jmeter dubbo interface test

Foreword

Recently, I am doing the monitoring integration of Dubbo service and Prometheus. In order to test the performance impact of the monitoring component on Dubbo RPC calls, we need to do performance tests before and after the addition. Although a unified Dubbo service test platform was built for the group before, it cannot be used for performance testing.

Speaking of performance testing, you may have many options, wrk, JMeter and so on. But I believe everyone is generally used to test the HTTP interface. For this private protocol of the Dubbo framework dubbo://, these tools do not provide native support. The first idea is to write a client by Dubbo's generalization call, and then count the test results, but this one is not elegant, and the other is that it is possible to repeat the wheel and waste time. After some google, I really got the answer I wanted.

Today I am going to introduce a JMeter plugin jmeter-plugins-for-apache-dubbo from the Dubbo community . Using this plugin, you can let JMeter test the Dubbo service.

This article assumes that readers have used jmeter for simple performance tests and have installed jmeter

text

Step 1: Install Dubbo plugin

  1. Clone the project:git clone https://github.com/thubbo/jmeter-plugins-for-apache-dubbo.git

  2. Package the project and build the JMeter plug-in:mvn clean install

    Or you can skip the two steps above and download  jmeter-plugins-dubbo-2.7.3-jar-with-dependencies.jar

  3. Add the plugin to  ${JMETER_HOME}\lib\ext(restart jmeter after installation)

image.png

image.png

 

Step 2: Write JMeter script

1. Create Dubbo Sample

Right-click [Thread Group] in the [Test Plan] area and select [Add]> [Sampler]> Dubbo Sample

image.png

image.png

 

Configure the registry address, service interface name (Java interface class name), method name, parameter type, and parameter value in the Dubbo Sample dialog box.

The configuration steps are as follows:

  • Configure the registration center, usually use ZooKeeper. (After the configuration is complete, click the Get Provider List button above to obtain the list of registered services)

    • If Protocol is selected  zookeeper, fill in ZooKeeper Address.
    • If the production environment usually contains multiple ZooKeeper nodes, you can fill in multiple ZooKeeper addresses and separate them with a comma (,).
    • For testing on a single server, select Protocol  noneand fill in the Dubbo service address with Address.
  • Adjust the service call configuration as needed, such as group, version, call timeout timeout (default is 1 second), etc.

  • Configure the full Java interface class name and method name of the Dubbo service.

  • Configure the parameter type and parameter value of each parameter.

    • Parameter type: basic types (such as boolean, int, etc.) write type names directly, and other types write complete Java class names (note that it is a complete class name).
    • Parameter value: The basic type and the string directly write the parameter value, and the complex type is filled in with JSON.

image.png

image.png

 

To facilitate the local debugging of test scripts, you can add a structure listener, right-click [Thread Group], select [Add]> [Listener]> [View Result Tree], and add a View Result Tree listener.

Step 3: Test execution

Right-click on [Thread Group] and click [Verify] to execute a single request to test the connectivity between the tool and the service.

In the [View Results Tree] tab, you can see the [Response Data] returned as expected, indicating that the Dubbo call can be executed normally.

image.png

image.png

 

Step 4: Add assertion

Sometimes you will see the execution result shows success, but in fact the Dubbo service call failed, or the business process failed, and the returned result contains an error code. For example, the following two pictures.

RPC call failed.

image.png

image.png

 

Business processing failed.

image.png

image.png

 

Solution:

For such problems, you can add assertions to check whether the service is successful. The result of the generalization call is returned in the form of JSON, and an assertion can be added to check the returned JSON data to more accurately verify whether the service execution is successful.

The specific steps are to right-click Dubbo Sample in the [Test Plan] area of ​​jmeter and select [Add]> [Assert]> [JSR233 Assertion].

image.png

image.png

 

Here I give my groovy test script code:

  1. String respStr = null;
  2. Map<String, Object> resp = null;
  3. try {
  4. respStr = SampleResult.getResponseDataAsString();
  5. resp = (Map<String, Object>) com.alibaba.fastjson.JSON.parse(respStr);
  6. } catch (Throwable ex) {
  7. // pass
  8. log.error("error", ex);
  9. }
  10. if (resp == null) {
  11. AssertionResult.setFailure(true);
  12. AssertionResult.setFailureMessage("RESPONSE IS NOT JSON: " + respStr);
  13. } else {
  14. // Simple check: when dubbo's generalization call fails, the returned JSON contains code and detailMessage fields.
  15. if (resp.get("code") != null && resp.get("detailMessage")) {
  16. AssertionResult.setFailure(true);
  17. AssertionResult.setFailureMessage("rpc exception, code=" + resp.get("code") + " detailMessage=" + resp.get("detailMessage"));
  18. } else if(!"SUCCESS".equals((String)resp.get("code"))) {
  19. // TODO verifies the success of the request based on your own actual business.
  20. AssertionResult.setFailure(true);
  21. AssertionResult.setFailureMessage ( "Request failed, code =" + resp.get ( "code"));
  22. } else {
  23. AssertionResult.setFailure(false);
  24. }
  25. }

image.png

image.png

 

Let's see, after adding the assertion, verify the result.

image.png

image.png

 

As you can see, the assertion played a role in business verification and prompted an error message.

As for how to write other parts of the script, it is necessary to consider the scene you want to simulate to set up, which belongs to the part of how to use JMeter, so I will not elaborate here.

More frequently asked questions

For more frequently asked questions about the plugin, please refer to the FAQ in the plugin's github wiki .

reference

Guess you like

Origin www.cnblogs.com/SunshineKimi/p/12717015.html