Jmeter中的并发AJAX调用

时间:2016-09-06 11:58:34

标签: jmeter

我们如何在trigger ...

JMeter并发请求

我不是在谈论非-html元素(我们在jmeter中有一个同时下载它们的规定)。

我几乎没有同时下载的AJAX调用......

1 个答案:

答案 0 :(得分:0)

根据JMeter 3.0,没有合适的测试元素,您需要:

示例JSR223采样器代码:

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.util.EntityUtils;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors; // necessary imports


List<String> urls = new ArrayList<String>(); // initialize array of URLs
Collections.addAll(urls,args); // read URLs from "Parameters" input and add them to array
ExecutorService pool = Executors.newFixedThreadPool(urls.size()); // initialize pool of Future Tasks with number of threads equal to size of URLs provided
for (String url : urls) { // for each URL from list
   final String currentURL = url;
   pool.submit(new Runnable() { // Sumbit a new thread which will execute GET request

       @Override
       public void run() {
           try {
               HttpClient client = new DefaultHttpClient(); // Use Apache Commons HTTPClient to perform GET request
  HttpGet get = new HttpGet(currentURL);
     HttpResponse response = client.execute(get);
HttpEntity entity = response.getEntity();
EntityUtils.consume(entity);
           } catch (Exception ex) {
               ex.printStackTrace();
           }

       }
   });
}
pool.shutdown(); // shut down thread pool

更多详情:How to Load Test AJAX/XHR Enabled Sites With JMeter