Application of JMeter in performance test of Web services

Source: Internet
Author: User
Tags soap ldap wsdl

Performance testing is an important part of any distributed or Web application test plan. Performance evaluations in the planning and development cycle ensure that applications delivered to customers meet customer requirements for high load, availability, and scalability. Determining the load limit of the software in advance can help with proper system configuration to avoid unexpected failures. A few of the problems to be addressed in the system performance analysis are whether the systems or servers can handle simultaneous requests from hundreds of or thousands of clients, and how often the system is able to process requests. This type of testing not only provides an absolute measure of the system response time, but also checks the server for regression testing and application code to see if the response to the servers matches the expected results and helps to evaluate and compare the middleware solutions of different vendors.

Apache Jmeter--apache's performance testing framework has been widely used as a performance testing tool for Web applications. It can be used to analyze the performance of the entire server under the condition of simulating heavy loads. The software provides FTP and HTTP request functionality and extensible custom scripting capabilities. This article explains why JMeter can be used to load test Web services. We describe this in particular by configuring a simple Web services in Bea WebLogic Server 9.0. The sample test plan illustrates the creation of test plans, thread groups, loops, and Web services requests. We also discussed how to measure the data and illustrate the results shown in the graphical tools with the accompanying JMeter chart.

Jmeter

Apache JMeter is a tool that can be used to test applications that utilize HTTP or FTP servers. It is Java-based, and it is also highly extensible through the API provided. Typical jmeter tests include creating loops and thread groups. The loop uses a preset delay to simulate successive requests to the server. Thread groups are designed to emulate concurrent workloads. JMeter provides a user interface. It also exposes APIs that allow users to run JMeter-based tests from Java applications. In order to create a load test in jmeter, you need to build a test plan. In practice, JMeter needs to perform a series of operations. The simplest test plan typically includes the following components:

* Thread groups-these components are used to specify the number of threads to run and the wait period. Each thread impersonates one user, while the wait period is used to specify when all threads are created. For example, the number of threads is 5, the wait time is 10 seconds, and the interval between each thread is created is 2 seconds. The number of loops defines the run time of the thread. With the scheduler, you can also set the start time of the run.
* Sampler-These components are configurable requests for server HTTP, FTP, or LDAP requests. This tutorial focuses only on Web services requests.
* Listeners-these components are used to request post-processing of data. For example, you can save data to a file or use a chart to illustrate the results. The JMeter chart does not offer many configuration options at this time, but it is extensible and can always add additional visualizations or data processing modules.

A detailed description of the available components is given on the Apache JMeter website. In some cases, if the available components are not suitable for a particular test, the developer can write his or her own script or Java class and embed it in the test plan by placing the jar file in the Libext directory where the JMeter is installed.

The version we used in this article is JMeter 2.1. Download the executable binaries from the Web site, unzip them, and then use the application on a Windows or UNIX platform. If you are working in the Windows operating system, go to the Bin folder to start the application with Jmeter.bat or Jmeterw.bat. As shown in the initial user interface 1.

Figure 1: Starting Apache JMeter

Create a Load test

Using the load test feature of JMeter, you can generate high loads on the server and determine their capacity and limits. Note: To use a Web services sample, you need available Mail.jar and Activation.jar, which can be obtained from Sun Microsystems (see the link below). Because of authorization restrictions, Apache did not distribute these libraries. After downloading these two jar files, place them in the Java classpath or install the JMeter lib directory.

Figure 2: Creating a thread group and a basic Web Services test plan

Now right-click on test plan and add the thread group and loop Controller. We use these two components to set the number of concurrent users to simulate and the duration of the test. Under the tree-like loop controller, add "WebService (SOAP) Request" and graph,2 as shown. If the webservice request cannot be added to the test plan, there may be no mail.jar or Activation.jar in the path.

Type the number of threads, the wait period, and the number of loops. In this tutorial we use 5, 10, and 100, respectively. Set the loop controller count to 1. If the WebLogic server that is configured with Web services is still not running, either start it manually or start from the WebLogic workshop.

Configuring Load Tests

As shown in 3, we need to set the SOAP request parameters that are sent to the server. If a link (URL) to the WSDL file is available, paste the link into the WSDL URL field and click Load WSDL. The available methods are displayed in the Web methods combo box. Next, you need to click Configure to populate server name or IP, Port number, path, and SOAPAction.

Figure 3:webservice (SOAP) Request dialog box

If there are no WSDL links available, you can also manually type the values for the server name, port number, path, and soap operation. The final step is to fill in the SOAP request in the SOAP/XML-RPC data area. The user can also load from a file using the SOAP XML data option.

After you enter all the fields in the Web Services Request dialog box, click Ctrl+s to save the JMeter project. To visualize the data, we added the chart elements "graph results" and "Spline Visualizer". In addition, we can also send a response to a file by adding a "Save responses to a file" component, which is useful when checking for SOAP response errors. To simulate a more realistic order of client requests, we inserted a timer element in the tree-"Gaussian Random timer". After doing this, the client's request is distributed more chaotic, and the server is clicked randomly instead of at equal intervals. We set the Gaussian random time to deviate from 100ms and the constant delay offset to 300ms.

Run a Load test

Users can run a load test by clicking Ctrl+r or by selecting Run from the menu and clicking Start to run the load test. Click on the graphic symbol and you will see that the chart is populated with data representing requests to the server, as shown in 4 to 6.

Figure 4: A chart that illustrates the test results. Number of threads = 5, wait time = 10, number of loops = 100. Loop controller set to 1

We chose to show three parameters in the chart--throughput (green Line), median (Purple Line), and average (blue line). We modify the parameters of the test. To simulate a higher load on the server, we increased the number of threads to 10 and 50 and compared the server's response time. Click Start again and look at the results shown in the chart, see Figure 5 and Figure 6.

Figure 5: A chart that illustrates the test results. Number of threads = 10, wait time = 5, number of cycles = 100, loop controller set to 1

The parameters at the bottom of the chart have the following meanings:

* Throughput is the number of requests that the server processes per minute.
* Average is the total elapsed time divided by the number of requests sent to the server.
* Median is the number representing the time, half of the server response time is below that value and the other half is above that value.
* Deviation indicates the server response time change, the size of the discrete measure value, or, in other words, the distribution of the data.
* The final sample is the last completed request.
  
By observing these three runs and their corresponding graphs, we can get the following valuable results:

The response time is obviously increased as the thread increases. To proceed with the test, we can make more thread count, wait period, and number of loops. Note: We did not change or adjust the configuration of the server. WebLogic Server 9.0 has a thread pool that can be configured automatically, with limited configuration scope (see Naresh Revanuru compose Workload Management in WebLogic Server 9.0, Dev2dev), The table above shows that the increase in the number of clients has a non-linear effect on the server response time. In fact, increasing this number by twice or 10 times times will not have a noticeable impact! However, you should be aware of running the same experiment using the number of threads that are close to or exceeding the default server limit. To verify that the response received from the server is a real SOAP response rather than an HTTP error, we observe the contents of the following output file. This is the SOAP response that meets the above requirements:

To make the test results more visible, add spline Visualizer to the plan, which is close to the graph Results. Spline Visualizer provides a view of all sample times. It draws a continuous line with the segmented insertion function, spanning 10 points at the time of drawing, and each point represents a sample of 10﹪. A smooth distribution view based on a polynomial approximation algorithm is provided by replacing the connection point with a straight line in a spline chart. As shown in result 7

Figure 7: Chart with the same test results as shown in Figure 6 using spline visualizer

Multiple jmeters

The JMeter also has a very useful remote start feature that allows users to start jmeter tests from multiple machines. The client host address can be entered in the "jmeter.properties" file located under the Bin folder. Locate the Remote_hosts property and add the remote host name there, separating it with a comma. Restart JMeter, click Remote Start or remote start all in the Run menu. Some Web and application servers can continuously process multiple requests for the same IP address and process requests for different IP addresses in parallel, so you can use this option to perform operations that are critical to requesting a different machine or distributing the test load to several clients.

Other features

As mentioned earlier, JMeter contains HTTP, FTP, and LDAP samplers. Creating these requests is a simple task that is described in detail in the JMeter user manual, which typically involves creating the thread Group, adding samplers, timers, and listeners. Below we describe some of the features outside these standard samplers that may require some non-standard configuration steps.

Script

Custom tests and scripts that specifically support Java requests and BeanShell scripts are another feature of jmeter, providing greater flexibility for load test developers. We can create scripted tests and compile them as a Java class, and then pass them to JMeter to run. In order to use the BeanShell scripting feature, you need to download the BeanShell jar and place it under the/lib directory so that JMeter can pick it up at run time. The user can use the BeanShell API in the Java sampler, or create a BeanShell sampler that reads the script in the file or handles the commands typed in the text box. The following code sample illustrates the BeanShell assertion added to the HTTP sampler. The user can analyze and control the test execution process for HTTP request-based responses. A good scenario should be to create a test plan with a thread group and start the load test in a scheduled time cycle. The request will click on the Web server and get its response.

The response can be logged with the BeanShell assertion added to the test plan, which is next to the HTTP sampler, and if the Web server response matches a condition, that is, if a successful or included string is expected, the script will stop the test or thread, otherwise it will continue execution.

JMS Application

In order to load test the JMS application using JMeter, download the activemq jar and copy it to the/lib directory. Based on the previous tests, we first created the thread group and added the JMS point-to-point sample. The JMS Point-to-Point dialog box needs to fill in the following parameters: Queueconnection Factory, Jndi name request queue, and Jndi name receive queue. For example, we can use the parameters in the JMS module installed on the WebLogic sample server, in which case they are weblogic.examples.jms.QueueConnectionFactory and Weblogic.examples.jms.exampleQueue. We can also create custom JMS connection factories and queues. For WebLogic servers, we also need to add weblogic.jndi.WLInitialContextFactory as the initial context factory value and provider URL, typically in the form of: t3:// HOSTNAME:7001, for example: t3://localhost:7001.

Custom Samplers

Sooner or later, many testers will face the following problem: If a test plan must be created, and JMeter does not provide the required sampler or listener. For example, a user needs to test an Enterprise JavaBeans application. The user can still use JMeter's Java Request, which is essentially a Java class that can add whatever logic is needed to it. We create a sample Java sampler that sends a request to the application server and invokes the session bean. First, we create a package mytest and a Java class called Jbtest.javajava:

To use this code, compile it to create the jar file Myejbtest.jar, copy the jar to the JMeter classpath (such as the Lib directory), or add the classpath location to the jmeter.properties file-- The form is:

Restart JMeter, add the Java request component to the test plan, and select MyTest from the drop-down menu. Ejbtest. By default, JMeter provides "sleeptest" and "Javatest". We can now add thread groups, loops, and listeners to the test plan and run the test plan.

Test database

Another feature supported by JMeter is the evaluation of the performance of the database server. Users can use the JDBC request component provided by the software, or they can use a script or Java class to create their own tests. For example, you can test a call to a stored procedure using some examples similar to the previous example. Many database optimization techniques can be used, including using specific vendor optimizations (such as parallel processing of queries), using junctions or indexes. In addition, data organization knowledge is useful when creating queries with multiple Boolean evaluations. Database and query optimization in applications is particularly critical when dealing with large amounts of data, and JMeter is a tool that can provide some evaluation in such evaluations. For example, you can perform performance or load tests before and after data or query optimization and compare the results.

We demonstrate how the sample database performance measurement plan works by creating a test plan for the MySQL instance. First, download the JDBC driver from the MySQL Web site and copy it to the/lib directory so that the JMeter can access the database. Now start JMeter, create the thread group, and set the number of loops and the corresponding number of threads. Add the JDBC Connection Configuration, JDBC Query defaults, and the JDBC request component. In these dialogs, we need to configure database connections and queries. Enter the database URL values in the form similar to: Jdbc:mysql://hostname/databasename, and then enter Com.mysql.jdbc.Driver for the JDBC Driver class. For this experiment, we created the database customers with a customer table with the following three fields: Name, address, and account. In the Query box, type queries, for example, select a name from the customer.

To visualize the results, you can add a chart with response time, or you can add a response assertion if you want to verify that the response matches a specific pattern. For example, add the text pattern "Smith" in response assertion. The assertion result window will display errors such as "Test failed, text expected to contain/smith/", or "Response was null" if there is no connection due to a set error. If the test succeeds, no content is returned. In addition to charting and assertion listeners, we can also use the aggregate report, which displays a summary of the number of samples, averages, intermediate values, and throughput in tabular form.

Conclusion

JMeter is a very flexible tool that is able to test not only HTTP servers, but also Web services for load testing. Experienced developers can write their own scripts to impersonate or customize client requests, or add custom visualizations to test results. Web services and SOAP samplers are new features of JMeter, and they are expected to evolve with Web services, gaining broader recognition among industry and developers.

Using JMeter's existing features and the user interface it provides, you can simulate 5 concurrent threads, with 10 and 5 ms latency clicking on the server. This tutorial explains how the tool can be used to measure the response time of Web services. For example, with the JMeter script, you can find the identity authentication and authorization of the client. Both the application server and the JMeter client are installed locally on the same workstation, but the same settings can be used to test the remote server.

The resulting results and graphs do not provide valuable performance reports; they can only describe the simple distribution of WebLogic server response time to Web services requests. To understand whether optimizations are being implemented, you should run the same load test for two different servers before and after optimization, or for a different load on the number of client thread variables. In other words, only the results of comparisons have practical value, which can help understand server performance and then make judgments based on these evaluations.

Resources

View Jakarta Apache jmeter--binary release downloads and guides.
The product center in Dev2dev accesses the WebLogic Server (Chinese version).
For more information about creating Web services, read the programming Web Services for WebLogic Server Guide (product documentation).
Matt Maccaux's approaches to performance testing (Chinese version, dev2dev,2005 year December) is a comprehensive introduction to the test.

Application of JMeter in performance test of Web services

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.