我有一个REST服务方法,需要对它进行负载测试。不幸的是,我没有我的笔记本电脑的管理员权限,也无法安装/下载任何工具。
需要知道REST服务(tomcat中的web项目)的容量,比如它可以处理多少并发请求。我不需要任何其他信息或细节。
以下是有关REST api的一些详细信息:
Method: POST
Technology: Spring MVC
Response object is very complex and huge form, requiring 100's of objects.有没有办法使用核心java应用程序(post到REST URL,获取响应,并找到API支持的最大并发请求数)
在core java中,我可以使用apache http、spring或core java 7/8。
发布于 2017-07-19 06:10:42
我可以使用Java7执行器和URLConnection使用以下代码进行负载测试:
public class POSTProcessor {
class ManagedProcessor implements Callable {
public void postMessage() {
//Test execute single call for REST web service with URLConnection
}
@Override
public Object call() throws Exception {
postMessage();
return null;
}
}
public static void main(String[] args) {
long time1 = System.currentTimeMillis();
int size = 200;
ExecutorService loadExecutor = Executors.newFixedThreadPool(size);
POSTProcessor threadRunner = new POSTProcessor();
List jobs = new ArrayList();
for(int i=0;i<size;i++){
ManagedProcessor exec = threadRunner.new ManagedProcessor() ;
jobs.add(exec);
}
try {
loadExecutor.invokeAll(jobs);
} catch (InterruptedException e) {
e.printStackTrace();
}
long time2 = System.currentTimeMillis();
System.out.println("Time delay: " + ( (time2 - time1)/size));
loadExecutor.shutdown();
}
}https://stackoverflow.com/questions/45174438
复制相似问题