Although I have been using JMeter for stress- and load-testing of web applications a good few times it took us a while to figure out how to test asynchronous HTTP/REST based services with the tool. With us I mean a fellow programmer – Holger Staudacher, I have the honor to work with currently on a project – and my humble self.
While Holger developed restfuse based on the experience of doing functional and integration tests for the project mentioned above, we decided to use
JMeter for stress- and load-testing. The main service of the software under test processes a data structure that is uploaded to a certain URL. If the upload process was successful an URL pointing to a resource containing the processing result is returned. The resulting resource is not available immediately – processing takes a while. So polling is used to retrieve the resource once it is available1.
Our goal was to measure the time it takes to upload the data structure, process it and download the result resource in one test run. Running such a test with multiple users concurrently should give us a fair impression of the throughput capabilities of the system. Does not sound too complicated, but…
…our first approach writing a test plan for the scenario described in the previous paragraph using the on-board capabilities of
JMeter did not work out very well. Neither was the plan comprehendible nor – and that was worse – made the measurement results any sense. In particular clamping the upload request and the polling loops together with a transaction controller seemed to have some unexpected side effects with timers. So after a while of additional Google research I stumbled across the JavaSamplerClient API, which I did not know before.
There is an entry at stackoverflow.com that describes how to extend the AbstractJavaSamplerClient – an implementation of
JavaSamplerClient – and use it within
JMeter. So this was the way to solve our problem. We created an extension of
runTest(JavaSamplerContext). Within that method we use HttpClient to perform the upload and poll requests. Once the processing result is successfully retrieved by a poll request all the header and content information is stored in an instance of
SampleResult. The latter is returned by the overridden test sampler method for further processing by
JMeter – quite straight forward2.
Once you have created a jar that contains a custom
JavaSampleClient and put this into the
lib/ext/ folder below your
JMeter installation directory you can add a
Java Request to your
Thread Group. This allows you to select and configure a custom sampler as shown in the picture below:
Using the the
JavaSamplerClient made our test plan very simple and allowed us to use the common
JMeter result measurement functionality as shown below examplary with the
Graph Results view:
And of course the measurement results are now reasonable…
Since we had to fumble quite a while to get this done I thought our solution might be of interest for other people, too – which was the reason to write this post. But it would be also interesting to hear from you if there are easier solutions we did not notice. So feel welcome to provide feedback
- We started using WebHooks but our customer had problems to convince the IT admins to open up the firewall… ↩
- For the sake of a reasonble length of this post I skip any description of how to deal with unsuccessful requests – but most of our implementation work had to be done in that area… ↩
Reference: Stress/Load-Testing of Asynchronous HTTP/REST Services with JMeter from our JCG partner Frank Appel at the Code Affine blog.