Jmeter - How to load test ajax web applications by

2019-06-14 12:44发布

I have been using Jmeter for performance testing my web application. I have recorded the jmeter script by excluding js,css and other static content files. While running the script, Jmeter doesnt execute javascript files so ajax XHR request are not sent. To overcome this i have recorded the script with js, css and other static content and it recorded all the Ajax xhr request too. But the performance results seems to be different from the browser loading time. Also i need to use cache during my performance testing.

Below is how my test plan will look like,

  1. Included Retrieve all embedded resources in HTTP Request manager.
  2. Concurrent pool size is 6
  3. I have added HTTP cookie manager and Cache manager.
  4. I have added a loop controller (This is for caching, jmeter will cache the files on first iteration and it will use the cached files after that)

The problem i am facing is that the time taken for rest call are double the time shown in the browser console for single user. I have tried all other combinations but always i am getting higher time than the browser console.

I have tried to use the Selenium webdriver plugin to simulate the browser behavior but it doesnt seems to be using the cache. (https://www.blazemeter.com/blog/how-load-test-ajaxxhr-enabled-sites-jmeter)

Is there any other way to solve this problem? I want to take the metrics with cache so kindly suggest me any solution that must include cache. Or is there any other tool similar to jmeter that could solve this issue. My goal is to take web page load time with cache for 'n' number of users.

PS : I am even interested to write any scripts in jmeter but the scripts should not overload the performance of jmeter.

Thanks in advance.

2条回答
够拽才男人
2楼-- · 2019-06-14 12:54

Jmeter and caching are unrelated - everything that happens after data went over the wire is out of scope by design. You should only ever simulate requests that you expect NOT to be cached. So this is the feasible part: drop all requests that you expect the browser to cache from the Jmeter script (or move them outside the loop). On the load time of XHR: the browser will most certainly use HTTP keepAlive. Result is that all requests except the very first skip the setup and teardown phase of TCP sockets and are much faster - esp. when the request itself is small and quick. You can simulate this in JMeter also by checking the KeepAlive option AND selecting http commons as implementation. You can read up on this in the docs here: http://jmeter.apache.org/usermanual/component_reference.html#HTTP_Request

查看更多
干净又极端
3楼-- · 2019-06-14 13:11
  1. You should not be recording calls to embedded resources (images, scripts, styles, fonts, etc.) as if you record them - they will be executed sequentially while real browsers do this in parallel. So remove recorded requests for the embedded resources and "tell" JMeter to download them (and do it in parallel) using HTTP Request Defaults
  2. You should be recording AJAX requests, however real browsers execute them in parallel while JMeter runs them sequentially. In order to make JMeter's behavior closer to real browser you need to put these AJAX calls under the Parallel Controller

You can install the Parallel Controller extension using JMeter Plugins Manager

JMeter plugins manager - parallel controller

查看更多
登录 后发表回答