java - Slow Apache httpclient 4.1 compared to JMeter -
I have a simple 1 thread loop, which uses Apache HTTP client 4.1. This connects my Apache httpd web server to the localhost.
I have averaging 2.5 ms per request / response. On the other hand, Jmater, Average 1 MS (Apache Benchmark, AB, does it in 0.4ms, but since it is the original code, there is probably no comparison).
The code is just: < Pre> My test otherwise shows, more than 10 examples of stackoverflow.com Receive Request for Repetitions: As you see through the image The average time (712 mms) when using jmeter with result code (or not) in a code And here is my code from Java: So I do not even care about the reaction body. But the results are very high here: Now when using the jmeter I have a screenshot no Mental worries'm not going to answer because there will be less readable, but this time the average time Now the Java code that cares about the reaction body (the new method): and I have modified the previous code, So it prints the feedback, imitates the jmeter behavior, posting the related part: The following results are: Report time went up from last HttpGet httpGet = new HTTPUtv (testUrl); While {true} {try {last long startNanoTime = System.nanoTime (); Last HttpResponse httpResponse = httpClient.execute (httpGet); Last inputstream inputstream = httpResponse.getEntity () GetContent (); Last byte [] buffer = new byte [8192]; Int size = inputstream.read (buffer); While (size> 0) {size = inputStream.read (buffer); } // Timeout expired Last time = System. Nano time () - startNanoTime; InputStream.close (); } Hold (Malformedlexception E) {// Never should throw new RuntimeException (E); } Hold (IOException e) {// count errors ++; Throw new runtime up (E); }}
result is Note that this listener does not print the requested statistics just to the body of the respondent.
Public static zero main (string [] args throws exceptions {long time = 0; (For int i = 0; i <10; i ++) {Long start time = System.currentTimeMillis (); Get HTTP Gate = New HTTP Gate ("http://stackoverflow.com"); HTTP Client Client = New DefaultHttpClient (); Client.execute (get); Long end time = system Time Received (); Long term = (and time-time); TotalTimeMS + = Duration; System.out.format ("duration% d ms \ n", duration); } System.out.format ("Average time is% d MS", (CholetimeMS / 10)); }
Duration 615 ms duration 263 ms duration 264 ms duration 262 ms duration 268 ms duration 266 ms duration 265 ms duration 266 ms 268 ms duration 263 ms average time 300 MS
see the result in a tree when you actually see the body of the reaction and the
can see the result of a table In because we still need time
812 ms is approximately 100ms more than before.
throws public static string converting streamtostring (Input Spread) IOException {if (is! = Faucet) {StringBuilder sb = new StringBuilder (); String line; Try {BufferedReader Reader = New BufferedReader (New InputStreamReader ("UTF-8"); while ((Line = Reader. Readline ())! = Null {sb.append (line) .append ("\ n") ;}} Is finally {is.close ();} return sb.toString ();} other {return "";}}
gets HttpGet = new HTTP gate ("http://stackoverflow.com"); HTTP Client Client = New DefaultHttpClient (); HTPRS Ponce Reaction = Client.except (get); Long end time = System. TimeTime (); Long term = (and time-time); TotalTimeMS + = Duration; Println (convertStreamToString (response.getEntity () getContent ()). ); System.out.format ("duration% d ms \ n", duration);
Duration 678 ms + ( Duration of 264 ms (including response body printing) duration 26 9 ms (including reaction of body reaction) 262 ms (reaction body print) Duration 263 ms + (reaction body printing including period) 265 ms + (reaction body printing) duration 262 ms + (including printing of reaction) 267 ms + (reaction body printing) duration 264 ms + (reaction) Period 264 ms + (including body printing) Average time is 305 ms
5 ms then I Do not know that jmeter is more than just plain Java code How fast it got Somehow jmeter is really great tool, one of the best arvel (free).
Comments
Post a Comment