background

Ali’s PTS performance test is out of 5 yuan, so I have to use JMeter to perform the public network pressure test. I will spend the weekend to learn about the HTTP request of JMeter sampler, which is the most used sampler.

However, when testing the snowflake algorithm IdWorker sender, it is very unscientific to use HTTP request. First, IdWorker sender is based on snowflake algorithm, which is pure memory calculation, and TPS is very high. If HTTP request is used,TPS will be greatly reduced due to bottlenecks such as network requests, and the measured indicators are also inaccurate.

JMeter has a sampler called Java Request, which can directly test the Java method. The following describes how I use the Java request sampler to test the IdWorker sender.

coding

According to the resources, to write Java JMeter recognition request must inherit AbstractJavaSamplerClient JavaSamplerClient or implementation, so the test code must rely on ApacheJMeter_java and ApacheJMeter_cor E, let me give you the GAV coordinates

< the dependency > < groupId > org, apache jmeter < / groupId > < artifactId > ApacheJMeter_java < / artifactId > < version > 5.4.1 < / version > </dependency>Copy the code

In my case, it’s inheritedAbstractJavaSamplerClientSampleStart () and sampleEnd() generate a timestamp, the difference is the single test time, the main test logic in the try part, generate a UUID.

The next step is to package. You don’t need ApacheJMeter_java and ApacheJMeter_core(JMeter itself certainly includes them), you just need to package your test code and other dependencies. In this case, there are no dependencies.

Finally, copy the JAR package into the JMeter lib/ext

Pressure test

Open JMeter again and see the test class you added under the Java request. Go ahead and test it

My test machine was local Windows,CPU I5 9400F, 16G memory (actually not much memory, it only puts pressure on the CPU), 800 concurrent threads, 150W TPS, enough for most scenarios, and performance bottlenecks were never found on the IdWorker transmitter.