Let's imagine that we are carrying out a performance analysis of the account service for 1,000 users. Follow these steps to learn how to create a performance test plan for a microservice:
Adding a thread group: Start by creating a thread group. Start JMeter, select the test plan, and add a thread group, as follows:
As you can see in the preceding screenshot, this is done by right-clicking on Test Plan and then selecting Add | Threads (Users) | Thread Group. Let's add this thread information to the thread group, as follows:
In the preceding screenshot, we have added 100 threads, which is the number of users who will connect to the targeted microservice. Those 100 users connect to the microservice 10 times each. We have also provided a 100 second ramp-up time period for the 100 users, which equates to one per user, per second.
Configuring JMeter elements: Let's configure JMeter's elements for this thread group. JMeter's elements are what you want to test.
First, we are going to configure HTTP Request Defaults. Right-click on Thread Group and select Add | Config Element | HTTP Request Defaults, as shown in the following screenshot:
Here, we can enter information about our microservice in the HTTP Request Defaults control panel. Let's suppose our microservice is hosted on www.dineshonjava.com. This is shown in the following screenshot:
You can also add other JMeter elements to this thread group, such as HTTP Request. Right-click on Thread Group and select Add | Sampler | HTTP Request. Then, add the element information to the control panel.
Adding a report element: Right-click on Test Plan and select Add | Listener | Graph Results, as shown in the following screenshot:
As you can see in the preceding screenshot, clicking on this option will show the test results in graph format.
Running the performance test: You can run the performance test by using the keyboard command Ctrl + R or by using the Run button on JMeter's toolbar. You will see the test result displayed in graph format in real time. This is shown in the following screenshot:
The preceding graph contains the following performance statistics about the targeted website and the microservice:
The number of samples sent to the website
The average of the all samples sent
The deviation for the samples
The throughput rate, which represents the number of requests per minute handled by the server
In this section, we have looked at how to carry out performance testing of a microservice with JMeter and how to configure different JMeter elements and report formats as per your requirements. We'll look at another tool for carrying out performance testing in the next section.