有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java Restlet:每秒仅1个请求

我正在用Servlet对我的web服务进行负载测试,但每秒只能执行一个请求。为什么以及如何处理更多请求

以下是我的测试方法:

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();
}

另外,在测试时,我的web服务什么也没做。我得到了空的mock,但Restlet仍然每秒只处理1个请求


共 (0) 个答案