我正在使用Servlet对我的Web服务进行负载测试,但我每秒只能执行1次请求。为什么以及如何提出更多请求?
这是我的测试方法:
public void testByMovieLens(String pathToData, int maxData) throws Exception {
if(api_key == null){
throw new Exception("No api key.");
}
BufferedReader br = new BufferedReader(new FileReader(pathToData));
String line;
String[] parts;
int counter = 0;
long timer = System.currentTimeMillis();
while((line = br.readLine()) != null){
parts = line.split("\t");
URL url = new URL("http://localhost:8111/preferences?api_key="+api_key+"&user_id="+parts[0]+"&item_id="+parts[1]+"&score="+parts[2]);
HttpURLConnection connection = (HttpURLConnection)url.openConnection();
connection.setRequestMethod("POST");
connection.setUseCaches(false);
connection.setDoOutput(true);
BufferedReader brr = new BufferedReader(new InputStreamReader(connection.getInputStream()));
String linee;
StringBuilder sb = new StringBuilder();
while((linee = brr.readLine()) != null){
sb.append(linee);
}
brr.close();
if(++counter % 100 == 0){
System.out.println("done "+counter);
}
if(counter == maxData){
break;
}
}
System.out.println("All done for "+((System.currentTimeMillis() - timer) * .001)+" seconds");
br.close();
}
P.S。在测试时,我的Web服务什么也没做。我提供了空模拟,但Restlet仍然每秒只处理1个请求