Xem Nhiều 6/2023 #️ Jmeter Là Gì? Tìm Hiểu Về Jmeter # Top 13 Trend | Sansangdethanhcong.com

Xem Nhiều 6/2023 # Jmeter Là Gì? Tìm Hiểu Về Jmeter # Top 13 Trend

Cập nhật thông tin chi tiết về Jmeter Là Gì? Tìm Hiểu Về Jmeter mới nhất trên website Sansangdethanhcong.com. Hy vọng nội dung bài viết sẽ đáp ứng được nhu cầu của bạn, chúng tôi sẽ thường xuyên cập nhật mới nội dung để bạn nhận được thông tin nhanh chóng và chính xác nhất.

JMeter là gì? Tìm hiểu về JMeter

JMeter là gì? Tìm hiểu về JMeter

Phần I. Tìm hiểu về JMeter

1. JMeter là gì?

1.1 Định nghĩa

Có rất nhiều định nghĩa về JMeter nhưng nói đơn giản thì JMeter hay còn gọi là kiểm thử hiệu năng, là một phần mềm được dùng để test function, khả năng chịu tải và hiệu suất của một trang web, một hệ thống, thậm chí còn dùng để chạy Automation Test cho cả API.

Thử tưởng tượng nếu cùng 1 lúc có 100 người dùng truy cập vào một trang web thì liệu rằng trang web đó có đáp ứng và đảm bảo được tốc độ truy cập của 100 người dùng, thời gian phản hồi của 100 request đó sẽ vẫn nhanh hay không? Và rất không khả thi khi dùng 100 PC để mô phỏng cho 100 người dùng. Chính vì vậy JMeter ra đời.

Apache JMeter được phát triển từ ngôn ngữ lập trình Java.

Ngoài JMeter thì hiện nay cũng có rất nhiều tool kiểm thử hiệu năng như: LoadRunner, WebLoad, LoadView, Tricentis Flood, LoadComplete v.v…

1.2 Sự quan trọng của JMeter đối với website

Một website được nhiều người sử dụng thì phải đảm bảo các yếu tố sau:

tính năng phần mềm hoạt động chính xác

thời gian phản hồi (response time) của trang web nhanh

hệ thống chạy ổn định, đảm bảo cho sự trải nghiệm của người dùng liền mạch

Một trang web chạy chậm sẽ dẫn đến sự trải nghiệm người dùng không tốt và có tác động tiêu cực đến tài chính của Công ty đó. Vì vậy hiện nay các công ty phát triển phần mềm rất chú trọng trong việc thực hiện kiểm thử hiệu năng trước khi khởi chạy hoặc sau mỗi lần update.

Với sự trợ giúp của JMeter chúng ta có thể mô phỏng một lượng tải lớn trên server, network v.v… từ các máy khác nhau để thực hiện kịch bản tương tự thực tế.

2. Tác dụng của JMeter

Giúp tìm ra các điểm nghẽn của hệ thống.

Xác định được số lượng người dùng cùng lúc mà hệ thống, ứng dụng có thể đáp ứng được.

Giúp tìm ra được những tác động về hiệu năng sau mỗi bản update.

3. Tính năng của JMeter

Các tính năng chính của JMeter bao gồm:

Giấy phép (License)

Giao diện đồ hoạ người dùng (Graphical User Interface – GUI)

Hỗ trợ Giao thức/ Máy chủ (Server/Protocol Support)

Nền tảng (Platform)

Mô phỏng (Simulation)

Hỗ trợ Phân phối tải (Supports Distributed Testing)

Hiển thị kết quả (Test Result Visualation)

Báo cáo (Reporting)

Các loại kiểm thử (Testing Types)

Record and Playback

Framework

Cài đặt (Installation)

Kiến thức (Knowledge)

4. Cách thức hoạt động của JMeter

4.1 Sơ đồ cách thức hoạt động của JMeter 4.2 Trọng tâm của việc kiểm thử hiệu năng

Thời gian phản hồi: check xem ứng dụng phản hồi nhanh hay chậm

Khả năng mở rộng: xác định tải người dùng tối đa mà ứng dụng phần mềm có thể xử lý.

Tính ổn định: Xác định xem ứng dụng có ổn định dưới các tải khác nhau hay không.

5. Quy trình làm việc của JMeter

Phần II. Cách cài đặt JMeter

1. Điều kiện cài đặt

1.1 Yêu cầu phần mềm

Phải có Java mới dùng được JMeter

JMeter 5.0 chỉ hỗ trợ chạy được trên Java 8 và 9

1.2 Yêu cầu hệ điều hành

2. Các bước cài đặt

Step 1: Download JMeter tạo trang Apache JMeter

Step 3: Sau khi hoàn thành việc download và thực hiện giải nén chúng ta sẽ được folder như bên dưới.

Folder bin: chứa các files templates, .bat, .sh, .jar để start JMeter. Và cũng chứa các file User và JMeter properties.

Folder lib: chứa tất cả file jar bắt buộc.

.bat: muốn khởi chạy được giao diện người dùng của JMeter thì phải chạy file này trên Windows.

.sh: muốn khởi chạy được giao diện người dùng của JMeter thì phải chạy file này trên MacOS và Linux.

**Lưu ý: **

Chỉ việc download file nén, sau đó giải nén và có thể sử dụng nó luôn chứ không cần phải cài đặt

Trên trang chủ sẽ có 2 phần: Binaries và Source.

Người dùng bình thường sẽ download ở Binaries

Người muốn chỉnh sửa, phát triển thêm các tính năng trong JMeter sẽ download ở Source

Theo Le Thi Hoang Diep – viblo asia

Tìm Hiểu Tổng Quan Về Apache Jmeter

Ứng dụng Apache JMeter là phần mềm mã nguồn mở, một ứng dụng Java thuần túy 100% được thiết kế để kiểm tra hành vi chức năng và kiểm tra hiệu năng(đo lường hiệu suất). Ban đầu nó được thiết kế để kiểm tra ứng dụng web nhưng sau đó đã mở rộng sang các chức năng kiểm tra khác.

2. Apache Jmeter có các tính năng như nào ?

Apache JMeter có thể được sử dụng để kiểm tra hiệu suất trên cả tài nguyên tĩnh và động, các ứng dụng động Web. Nó có thể được sử dụng để mô phỏng hiệu năng trên một máy chủ, nhóm máy chủ, mạng hoặc đối tượng để kiểm tra sức mạnh của nó hoặc để phân tích hiệu suất tổng thể dưới các loại tải khác nhau.

Các tính năng của Apache JMeter bao gồm:

Có khả năng chịu tải và kiểm tra hiệu suất nhiều ứng dụng(application)/server/protocol types:

Web – HTTP, HTTPS (Java, NodeJS, PHP, chúng tôi …)

SOAP / REST Webservices

FTP

Database via JDBC

LDAP

Message-oriented middleware (MOM) via JMS

Mail – SMTP(S), POP3(S) and IMAP(S)

Native commands or shell scripts

TCP +Java Objects

Test IDE có đẩy đủ tính năng cho phép lên Test Plan nhanh hơn: recording (from Browsers or native applications), building and debugging.

CLI mode (Command-line mode (previously called Non GUI) / headless mode) có thể chịu tải(Load test) từ bất kỳ hệ điều hành Java khác nhau (Linux, Windows, Mac OSX, …)

Dynamic HTML report : JMeter hỗ trợ tạo báo cáo bảng điều khiển để lấy biểu đồ và thống kê từ Test Plan

Tương quan dễ dàng thông qua khả năng trích xuất dữ liệu từ hầu hết các response formats, HTML, JSON, XML or bất kỳ định dạng văn bản nào

100% Java thuần túy

Lưu vào bộ nhớ đệm và phân tích ngoại tuyến/phát lại kết quả test.

Highly Extensible core:

Bộ lấy mẫu có thể cài đặt cho phép kiểm tra không giới hạn

Scriptable Samplers (Các ngôn ngữ tương thích với JSR223 như Groovy và BeanShell)

Một số thống kê tải có thể được chọn với bộ hẹn giờ**(pluggable timers)**

Phân tích dữ liệu và visualization plugins cho phép khả năng mở rộng cũng như cá nhân hóa tuyện vời.

Các hàm có thể được sử dụng để cung cấp đầu vào động(dynamic) cho test hoặc cung cấp thao tác dữ liệu.

Tích hợp dễ dàng thông qua các thư viện mã nguông mở của bên thứ 3 như Maven, Gradle và Jenkin.

3. JMeter có phải là một trình duyệt không ?

Câu trả lời là KHÔNG. JMeter không phải là một trình duyệt, nó làm việc ở cấp độ giao thức(protocol). Về các dịch vụ web(web-services) và dịch vụ từ xa, JMeter trông giống như một trình duyệt (hay đúng hơn là nhiều trình duyệt). Tuy nhiên, JMeter không thực hiện tất cả các hành động được hỗ trợ bởi các trình duyệt. Đặc biệt, JMeter không thực thi Javascript được tìm thấy trong các trang HTML. Nó cũng không hiển thị các trang HTML như một trình duyệt ( có thể xem phản hồi dưới dạng HTML,v..v.., nhưng thời gian không được bao gồm trong bất kỳ mẫu nào và chỉ một mẫu trong một chuỗi được hiển thị tại một thời điểm).

4. Thiết lập và cài đặt Jmeter

Để bắt đầu với JMeter, điều đầu tiên chúng ta cần làm là thiết lập và cài đặt JMeter. Tôi sẽ giúp bạn làm thế nào để làm điều đó. Ứng dụng Apache JMeter là phần mềm mã nguồn mở, một ứng dụng Java thuần túy 100%. Vì vậy, bạn có thể chạy JMeter từ bất kỳ hệ điều hành tương thích với Java nào, miễn là Java đã được cài đặt trên hệ điều hành đó (Linux, Windows, MacOS,…)

4.1. Thiết lập

Kiểm tra Java đã được cài đặt trên máy tính chưa

Mở Terminal trên MacOS hoặc cmd trên windows, gõ lệnh: java -version

Ngược lại, bạn thấy điều này trên windows: ‘java’ is not recognized as an internal or external command, operable program or batch file

4.2. Download and Install JMeter

Bước 1: Truy cập trang này: http://jmeter.apache.org/download_jmeter.cgi Bước 2: Tải xuống chúng tôi trong phần Binaries. Bước 3: Giải nén tệp đã tải xuống của bạn. Bạn sẽ có thư mục như bên dưới

Windows:

Vào thư mục / bin

Tìm tệp chúng tôi (nếu bạn không thấy phần mở rộng .bat, bạn có thể quan sát cột Loại của tệp, nó phải là Tệp hàng loạt của Windows)

Nhấn đúp vào tệp này

Giao diện người dùng JMeter sẽ xuất hiện Xin chúc mừng! Bạn đã sẵn sàng. Bây giờ bạn có thể bắt đầu sử dụng JMeter, hãy thử tạo Kế hoạch kiểm tra web cơ bản với JMeter.

MacOS/Linux:

Trên MacOS, nó có một chút khác biệt so với Window. Bạn cần chạy JMeter qua dòng lệnh

Mở ứng dụng Terminal, sử dụng lệnh cd để chuyển đến thư mục / bin của JMeter: cd /Users/user/Desktop/apache-jmeter-5.3/bin

Sau đó, nhập: sh ./jmeter.sh

Giao diện người dùng JMeter sẽ xuất hiện Xin chúc mừng! Bạn đã sẵn sàng. Bây giờ bạn có thể bắt đầu sử dụng JMeter, hãy thử tạo Kế hoạch kiểm tra web cơ bản với JMeter.

How To Load Test Mongodb With Jmeter

As Big Data and real-time web apps keep getting bigger, NoSQL databases are more popular than ever for data storage. This is especially true for NoSQL’s most popular database – MongoDB.

Let’s take a step back for a moment…

When performance testing you usually need to check the entire application to measure the end-user experience. But it’s sometimes easier to test each database component separately if you want to check the response times for certain queries, the efficiency of horizontal scaling, replications, failovers and resilience, and to ensure the database is properly tuned you won’t hit a bottleneck or be denied service.

In today’s post, I’m going to guide you through MongoDB load testing with Apache JMeter, highlight frequently faced problems along with their workarounds, and explain and demonstrate some of MongoDB’s most common tasks.

JMeter first introduced support for MongoDB support in version 2.10, which was released in October 2013. Now we’re already on JMeter 2.13…here’s how MongoDB is being implemented:

MongoDB Source Config – a configuration element which creates a MongoDB connection using specified settings.

MongoDB Script – a sampler capable of sending requests to MongoDB. It assumes and requires the presence and correct configuration of MongoDB Source Config

Let’s take a look at how these test elements can be used for MongoDB testing. For today’s demo, I’ll be using the chúng tôi file – which can be found here: http://media.mongodb.org/zips.json. If you want to copy any of the examples below, just download the chúng tôi file to your computer and import it with this command:

mongoimport –db test –collection zips –file /path/to/zips.json

A quick explanation of each term…

mongoimport: a binary file located in the /bin folder of your MongoDB installation

“test”: MongoDB’s database, a container for “collections”

“zips”: MongoDB collection name

{ “_id” : “43747”, “city” : “JERUSALEM”, “loc” : [ -81.092088, 39.848831 ], “pop” : 2037, “state” : “OH” }

Want to visualize it more easily? Use tools like MongoVUE or Robomongo.

So let’s get started.

In order to execute MongoDB queries we need to:

You can leave other values as they are – the defaults are good to go. I’ll use the IP address of my MongoDB test server, and give “blazemeter” as the Mongo Source name.

Add the MongoDB Script, providing the:

Mongo Source name (in this case, “blazemeter”)

Database name (in this case, “test”)

Script. For this step, I’ll use the count of the elements in the “zips” collection, which is:

db.getCollection(“zips”).count()

View the Results Tree Listener to visualize the results

Let’s run the test and see how it goes:

As you can see, the MongoDB Script sampler response data is 29353.0. This is the actual count of all the documents in the “zips” collection of the “test” database.

IMPORTANT: There should not be any blank lines in the MongoDB Script Sampler. If you have a blank line after your MongoDB statement, the statement will still be chúng tôi you’ll only get the word “ok” in the response. If you’re getting “ok” double check that there aren’t any trailing blank lines in your script.

Make sure that line number “2” is NOT displayed.

Now let’s enter information on a city into the collection. You can re-use the same test plan but the “Script” area of the MongoDB Script sampler needs to be updated to something like this:

db.getCollection(‘zips’).insert({“city” : “BABYLON”, “loc” : [ 32.211100, 44.251500 ], “pop” : 300000, “state” : “IS” })

When you run the updated script in JMeter, you should be able to see the request details in the “Request” tab of the ‘View Results Tree Listener’

…and in the “Response Data” tab, you’ll be able to see the results.

If you change the MongoDB Script query back to db.getCollection(“zips”).count(), you should be able to get the updated documents count (incremented by 1). In my case, the count is: 29354.0

db.getCollection(‘zips’).findOne({“city”:”BABYLON”})

If you look into the Response Data tab of the View Results Tree Listener, you’ll be able to see the document that was inserted earlier.

It’s worth noting that I switched to the “JSON” tab for more user-friendly view.

Now, let’s measure the time it takes with a MongoDB Script sampler to get all the documents where the city is “NEW YORK”. This is how the MongoDB query should look:

db.getCollection(“zips”).find({“city” : “NEW YORK”})

When executed in Robomongo, this query returns 40 results within 0.103 seconds

Let’s try doing the same in JMeter. Enter the same request into the “Script” section of the MongoDB Script sampler:

Now let’s look at the “Response Data” tab:

It looks like that the sampler returns information on the health of the MongoDB server – rather than a list of documents which contain “city = NEW YORK” (as we wanted).

But Why?

When you look at the EvalResultsHandler class source, you can see that they can only be supported when cast to JSON. As the “NEW YORK” query returns more than one (actually 40!) documents, it needs to somehow be converted to JSON so the sampler can return it properly.

Fortunately there is a solution! You just need to append the “.toArray()” method to the end of the MongoDB query, like this:

db.getCollection(“zips”).find({“city” : “NEW YORK”}).toArray()

This will convert the response into something that can be cast to the JSON Array. This means the response will be displayed and used to extract the “interesting” bits – such as applying assertions, etc.

Now let’s see how to load test MongoDB with the help of JMeter. Surprisingly, it’s NOT RECOMMENDED to use the MongoDB Script Sampler for MongoDB load testing. The MongoDB Script uses the db.eval() method “under the hood” for executing queries and this is being phased out (as from the current version – MongoDB 3.0). Here are some reasons why:

Performance: the db.eval() method takes the global lock by default. This means that all read and write operations are blocked while your script is being evaluated

Compatibility: the db.eval() method won’t work on shared collections

Security: the db.eval() method requires too much privileges and your account might not have enough permissions to invoke it

Robustness: your scripts relying on the db.eval() method might stop working on next MongoDB release – when the method will be completely removed.

So here’s where it’s OK to use the MongoDB Script Sample:

For functional testing with one thread

If you need to change a huge amount of data and want to avoid overhead caused by passing gigabytes of data back and forth over the network.

However, if you need to create immense load, you should look at other options.

If you’re load testing MongoDB, it’s recommended to call the MongoDB Java Driver methods from the JSR223 Sampler, using “groovy” as a language.

Why JSR223 and groovy?

It’s the only scripting approach which provides performance comparable with native Java code. See Beanshell vs JSR223 vs Java JMeter Scripting: The Performance-Off You’ve Been Waiting For! for details on installing the groovy engine into JMeter – along with limitations and best practices.

If you’re not familiar with groovy – it’s worth knowing that it’s 100% compatible with Java, so a well-formed Java code will work like a charm!

So make sure you have:

a groovy-all-*.jar file in /lib folder of your JMeter installation

restarted JMeter to pick up the Groovy library

a MongoDB Source Config pointing to your MongoDB installation with the Source Name “blazemeter”

added the JSR223 Sampler

chosen “groovy” from “Language” drop down

And we’re good to go on to the next step.

First of all, we need to learn how to do the following:

Initialize the MongoDB connection based on the data source name

Get a count of documents in the collection

Insert a document

Assure that the count is incremented by 1

Find one document

Find multiple documents

Here’s how you access MongoDB from a groovy code:

import com.mongodb.DB; import org.apache.jmeter.protocol.mongodb.config.MongoDBHolder;

DB db = MongoDBHolder.getDBFromSource(“blazemeter”, “test”);

Where

If you need to provide credentials to access MongoDB, just add them as parameters:

DB db = MongoDBHolder.getDBFromSource(“blazemeter”, “test”, “username”, “password”);

So now you have an instance of the chúng tôi class, which is accessible as db. If you want to see all the available methods and fields, take a look at its JavaDOC. Let’s try to invoke MongoDB.getStats() – which is the equivalent of the dbstats MongoDB command. We’re interested in the string representation, so this is how the final line will look:

String result = db.getStats().toString();

Now we somehow need to return the resulting string. The JSR223 Sampler provides some predefined variables like ctx, vars, props, SampleResult,log, etc. These are all shorthands for relevant JMeter API classes instances, such as:

We’re particularly interested in the SampleResult as it gives control over the JSR223 Sampler and returns values like the Response Code, Response Message, and Response Body. To set the sampler response body, you’ll need to use the setResponseData()

So, here’s how it looks when we put everything together:

import com.mongodb.DB; import org.apache.jmeter.protocol.mongodb.config.MongoDBHolder;

DB db = MongoDBHolder.getDBFromSource(“blazemeter”, “test”); String result = db.getStats().toString() SampleResult.setResponseData(result.getBytes());

Here’s what you need to do:

This is what the full code will look like:

import com.mongodb.DB; import org.apache.jmeter.protocol.mongodb.config.MongoDBHolder; import com.mongodb.DBCollection;

DB db = MongoDBHolder.getDBFromSource(“blazemeter”, “test”); DBCollection collection = db.getCollection(“zips”);

Try to run the code yourself to see the count of documents in “zips” collection.

db.getCollection(‘zips’).insert({“city” : “BABYLON”, “loc” : [ 32.211100, 44.251500 ], “pop” : 300000, “state” : “IS” })

In the MongoDB Java API, you can do this via the DBCollection.insert() method – which takes the DBObject as a parameter and returns the WriteResult. Look at the code sample below to learn how to construct the DBObject instance.

We need to construct the following object:

For basic name/value pairs like “city” : “BABYLON”, you can use the BasicDBObject class

For arrays like “loc”, you can use BasicDBList class

This is how it looks when it’s all put together:

import com.mongodb.*

DB db = MongoDBHolder.getDBFromSource(“blazemeter”, “test”); DBCollection collection = db.getCollection(“zips”);

BasicDBObject object = new BasicDBObject();

WriteResult result = collection.insert(object, WriteConcern.ACKNOWLEDGED);

SampleResult.setResponseData(result.toString().getBytes());

This is how your response should look:

{ “serverUsed” : “/52.17.164.41:27017” , “n” : 0 , “connectionId” : 248 , “err” : null , “ok” : 1.0}

Now you can re-run the scenario ” How to Get the Count of the Documents in the Collection to make sure that the number of documents in the”zips” collection will be incremented by one.

Now let’s learn how to issue the “find()” command by using the JSR223 Sampler.

In order to find one document containing “city” : “BABYLON”, we need to invoke the DBCollection.findOne() method and pass the desired city name as a parameter. As we already know how to construct a DBObject to pass as a parameter, we just need to create one per query and add it to the DBCollection.findOne() method.

import com.mongodb.*

DB db = MongoDBHolder.getDBFromSource(“blazemeter”, “test”); DBCollection collection = db.getCollection(“zips”);

BasicDBObject query = new BasicDBObject(“city”, “BABYLON”);

SampleResult.setResponseData(result.toString().getBytes());

You should be able to see the document in the “Response Data” for the JSR223 Sampler in the View Results Tree Listener (just like in the MongoDB Script).

The query which returns multiple documents is pretty much the same as the query for one document. However, the DBCursor will be returned instead of the DBObject – so the results need to be handled a bit differently.

The DBCursor gives two methods which allow you to iterate through nested DBObjects:

hasNext() – checks whether another DBObject is available, it so – returns “true”, elsewise – “false”

next() – returns current DBObject and moves the cursor to the next one

Here’s how it looks when you put everything together:

import com.mongodb.*

DB db = MongoDBHolder.getDBFromSource(“blazemeter”, “test”); DBCollection collection = db.getCollection(“zips”);

BasicDBObject query = new BasicDBObject(“city”, “NEW YORK”); DBCursor cursor = collection.find(query);

while (cursor.hasNext()) {

}

SampleResult.setResponseData(resultBuilder.toString().getBytes());

By default, JMeter doesn’t print a lot into the chúng tôi file. However, if you have an issue that you’d like to get to the bottom of, you can increase the log level on a certain class or package. If you’d like to increase the details of the logging output of the MongoDB-related test elements, you can take one of two options:

Add the log_level.jmeter.protocol.mongodb=DEBUG line to the user.properties file (this can be found in the /bin folder of your JMeter installation). On the next JMeter instance, all classes under the jmeter.protocol.mongodb package will be set to the DEBUG level, which will provide additional information on what’s going on

Pass the desired log level as a command-line argument via the -L key as: jmeter -Ljmeter.protocol.mongodb=DEBUG

In any case, you’ll be able to see the extra debug output from the MongoDB test elements in the chúng tôi file

To get the best performance from the JSR223 Sampler, you just need to follow a few simple rules:

Keep the JSR223 scripts as files in the filesystem. This way they will get compiled into the bytecode and the overhead will be minimized

If, for some reason, point one isn’t possible or available, the groovy script can still be kept in the “Script” area. Just make sure that the “Compilation cache key” is set and unique for each JSR223 Sampler instance

Don’t refer to JMeter Variables as ${VariableName} in your groovy scripts as it will ruin all the benefits of the approach. Use vars.get(“VariableName”) instead.

Blazemeter systems are 100% JMeter compatible. They assume that you don’t need to do anything else except provide a groovy-all-*.jar along with your test script.

You can analyse your MongoDB load test sessions with Blazemeter’s reports. They are fully compatible with any sampler types – even when they are heavily customized.

Hướng Dẫn Sử Dụng Jmeter Test Hiệu Năng Website

Performance testing là một loại test quan trọng để xác định ứng dụng web đang được kiểm tra có đáp ứng các yêu cầu tải cao hay không. Loại test này được dùng để phân tích hiệu năng máy chủ một cách tổng thể khi chịu tải nặng.

Chuỗi bài viết này mình sẽ giới thiệu tới các bạn 1 công cụ test rất mạnh mẽ và phổ biến hiện nay: Apache Jmeter

Cụm bài viết của mình gồm các phần từ bắt đầu cho tới nâng cao: Phần 1: Giới thiệu và cài đặtPhần 2: Hướng dẫn xây dựng kịch bản testPhần 3: Sử dụng Regular Expressions làm việc với Session IDs và TokensPhần 4: Mở rộng – Tạo lập Scripts tự động bằng HTTP(S) Test Script Recorder.

Jmeter có thể làm gì?

Jmeter là công cụ giúp ta giả lập thao tác của người dùng trên web. Bằng việc giả lập các thao tác của một số lượng người dùng nhất định, Jmeter giúp ta đánh giá được các kết quả: – Web có thể chịu được bao nhiêu lượt truy cập/thao tác liên tục cùng lúc?– Để đáp ứng số lượng X người sử dụng, thì cần phân phối họ truy cập trong bao lâu? Như thế nào để Web vẫn hoạt động bình thường?– Thời gian response dữ liệu của server với từng mức tải người dùng?– Kết hợp với 1 số tool monitor server, ta có thể theo dõi thay đổi vật lý của server khi có tải lớn như: CPU, RAM, Network traffic… (Phần này mình sẽ có bài viết khác giới thiệu về các tool monitor – Link đang cập nhật)

Cài đặt và khởi chạy Jmeter

B1: Các bạn Download Apache Jmeter mới nhất tại Đây.B2: Để chạy được Jmeter, bạn cần cài thêm JDK của Java nữa, download tại ĐâyB3: Chạy JDKB4: Chạy Jmeter: Sau khi download Jmeter, các bạn giải nén và chạy file .jar trong thư mục /bin

Hình 1: Khởi chạy Jmeter

Giới thiệu các thành phần trong Jmeter

Các bạn vui lòng đọc kĩ phần này, trước khi bắt tay vào test hiệu năng 1 cách nghiêm túc. Chúng ta cần hiểu và nắm được ý nghĩa của các thành phần trong Jmeter. Tất nhiên nếu đơn giản bạn chỉ muốn test lượt truy cập vào website của bạn mà không mô phỏng thao tác nào của họ trên đó thì có thể bỏ qua phần này.Trong phần này chúng ta sẽ tìm hiểu các thành phần sau:

Thread Group

Controller (Sampler Controller & Logic Controller)

Configuration Element

Listener

Timer

 

Thread Group

Hình 2: Tạo thread group

Một Thread Group đại diện cho một nhóm người dùng, và nó chứa tất cả những yếu tố khác.Mỗi Thread Group sẽ mô phỏng những người dùng để thực hiện một trường hợp thử nghiệm cụ thể. Thread Group cho phép tester thực hiện những tùy chỉnh về:

Số lượng Thread: Mỗi Thread đại diện cho một người dùng ảo, JMeter cho phép thay đổi số lượng người dùng không hạn chế để thực hiện các thử nghiệm.

Ram-Up Period: Thời gian để bắt đầu tất cả những Thread.

Loop Count: Số lần lặp lại những yêu cầu của người dùng. Ngoài ra còn có những tùy chọn khác như việc chạy các Thread vào lịch biểu định sẵn, xác định hành động sẽ thực hiện khi xảy ra lỗi…

Hình 3: Các thành phần của Thread Group

Chú ý: 100 user + Loop count: 1 khác gì 50 user + Loop count 2.Về tổng số request thì bằng nhau, Jmeter sẽ thực hiện 100 lượt test.Tuy nhiên có sự khác nhau về thứ tự thực hiện của các user như sau:

Controller: HTTP Request Defaults

Trong Bảng HTTP Request, trường Path cho biết yêu cầu URL nào bạn muốn gửi tới server. Nếu bạn để trống trường này, request sẽ được gửi tới URL: chúng tôi (Đã được config trước đó ở http request default)Ở đây ta còn có thể định nghĩa phương thức truy cập tới URL trên gồm: GET/POST/HEAD/PUT/DELETE/….Phổ biến nhất hay dùng là GET/POST.Để truyền thêm param cho request, ấn nút Add.

Configuration Element

HTTP Cookie Manager: Hầu hết các trang web đều sử dụng cookie để lưu dữ liệu. Do đó, cần thêm element này để có thể lưu dữ liệu của user sau khi thực hiện controller login.

CSV Data Set Config: Dùng để quy định file dữ liệu đầu vào cho kịch bản test với nhiều người dùng khác nhau cùng sử dụng 1 chức năng.VD: Kịch bản test: 100 user login vào hệ thống sử dụng 100 tài khoản khác nhau. Danh sách username, password của 100 tài khoản đó sẽ được lưu trong file csv_account.txt. Jmeter sẽ đọc dữ liệu từ file này và lần lượt gửi dữ liệu vào mỗi request.

Mẫu file csv_account.txt Giải thích CSV data

Filename: đường dẫn tới file dữ liệuVarible names: Tên các biến mình định nghĩa, theo thứ tự dữ liệu từ trái qua phảiDelimiter: Kí tự dùng để phân cách giá trị các biến. Theo như file csv_account.txt bên trên thì mình định nghĩa format dữ liệu sẽ là: username, password.Để sử dụng các giá trị từ file dữ liệu đưa vào http request, cấu hình như sau:

Tại cột value, ta sử dụng các biến đã định nghĩa bên trên. Chú ý cú pháp sử dụng là: ${ten_bien}

Listener

Công cụ Listener mà JMeter cung cấp cho phép xem những kết quả thu được từ việc chạy thử nghiệm dưới các dạng khác nhau như: đồ thị, bảng biểu, cây.. Các listeners sẽ cung cấp một cách trực quan nhất những dữ liệu thu thập được từ việc thực thi các Test case. Tester cũng sẽ có thể tùy chỉnh những thông tin mà Listener trả về một cách dễ dàng bởi các tính năng trong giao diện cụ thể của từng Listener. Có rất nhiều dạng Listener được JMeter cung cấp, có thể kể đến một số Listener thường được sử dụng để cung cấp như:

Summary report: báo cáo tóm tắt kết quả thực hiện test.

 

View Results Tree: Báo cáo chi tiết kết quả thực hiện của từng request. Tại đây ta có thể xem lại dữ liệu request đó đã gửi đi, và dữ liệu nhận được từ phía server.

View Results in Table: Chi tiết kết quả thực hiện từng request ở dạng bảng. (Chi tiết của dạng summary report)

Graph Results: Biểu đồ thống kê thời gian phản hồi và các tham số sau mỗi request được gửi đi.

Summary Report

Label: Tên http requestSample: số lượng request đã thực hiệnAvarage: Thời gian phản hồi trung bình. Đơn vị ms.Min: Thời gian phản hồi ngắn nhất;Max: Thời gian phản hồi lâu nhấtStd. Dev: Độ lêch chuẩn thời gian phản hồiError %: Tỉ lệ % số request bị lỗi (Không nhận được phản hồi từ server).Throughput: Số request server có thể xử lý/ second/minute/hour.Received KB/sec: Thông lượng KB nhận được/giâySent KB/sec: Thông lượng KB gửi đi/giâyAvg. Bytes: Dữ liệu phản hồi trung bình

View Results Tree View Results In Table Graph Results

Ở dưới cùng của hình ảnh, có các số liệu thống kê sau đây, được biểu thị bằng màu sắc:• Đen: Tổng số mẫu hiện tại được gửi – 100.• Màu xanh dương : Mức trung bình hiện tại của tất cả các mẫu được gửi – 428ms.• Màu đỏ : Độ lệch chuẩn hiện tại – 325ms.• Màu xanh lá cây : Tỷ lệ thông lượng biểu thị số lượng yêu cầu mỗi phút mà máy chủ xử lý. – 59 964 request/phút1 vài chú ý:Throughput càng cao càng tốt. Chứng tỏ server xử lý được nhiều request/thời gian. Nó biểu hiện cho khả năng máy chủ xử lý tải nặng. Throughput càng cao thì hiệu suất máy chủ càng tốtDeviation: Tham số Deviation được hiện màu đỏ, nó chỉ ra sai lệch so với mức trung bình. Giá trị Deviation càng nhỏ thì càng tốt.

Timer

Timer là một phần rất quan trọng khi xây dựng một Test Plan, nó cho phép cài đặt khoảng thời gian giữa 2 yêu cầu kế tiếp nhau mà người dùng ảo gửi đến máy chủ. Điều này sẽ tạo ra một mô phỏng thực tế nhất so với hoạt động thực tế của người dùng trên website.JMeter cung cấp nhiều Timer với các dạng khác nhau để thiết lập thời gian nghỉ giữa việc thực hiện 2 yêu cầu , như :• Constant Timer: xác lập thời gian là một hằng số.• Uniform Random Timer: xác lập thời gian nghỉ ở một khoảng xác định.Để sử dụng Timer, ta tạo 1 Flow control action và đặt timer vào trong Follow đó.

Tham khảo

https://jmeter.apache.org/usermanual/component_reference.html

Kinhnghiemlaptrinh.com

5

/

5

(

1

bình chọn

)

Bạn đang xem bài viết Jmeter Là Gì? Tìm Hiểu Về Jmeter trên website Sansangdethanhcong.com. Hy vọng những thông tin mà chúng tôi đã chia sẻ là hữu ích với bạn. Nếu nội dung hay, ý nghĩa bạn hãy chia sẻ với bạn bè của mình và luôn theo dõi, ủng hộ chúng tôi để cập nhật những thông tin mới nhất. Chúc bạn một ngày tốt lành!