我必须构建一个相当自定义的负载测试工具,因此我不想使用 JMeter(让我们暂时假设无法使用 jmeter 完成自定义级别)。
这个负载测试工具的一个重要部分是将 XML 发送到 API 端点。
如何改进以下代码以使其快速/高效?
private boolean PostErrorToApi() throws IOException {
       File xmlSample = new File("/path/to/file/sample.xml");
       CloseableHttpClient httpClient = HttpClients.createDefault();
       HttpPost httpPost = new HttpPost("http://localhost:8090/some/api/method/get/");
       httpPost.setEntity(new FileEntity(xmlSample, "text/xml, application/xml"));
       CloseableHttpResponse response = httpClient.execute(httpPost);
       String line = "";
       try {
           BufferedReader reader = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
           while ((line = reader.readLine()) != null) {
               System.out.println(line);
           }
       } finally {
           response.close();
       }
       if (line.equals("200 OK"))
           return true;
       else
           return false;
   }
我的目标是每秒处理几千个请求(http 延迟应该不是什么大问题,因为这将在专用网络中)。
我不是想在这里获得真实世界的场景,目标是查看服务是否可以保持 48 小时并监控可能出现的任何问题等。