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

My test otherwise shows, more than 10 examples of stackoverflow.com Receive Request for Repetitions: Enter image details here

As you see through the image The average time (712 mms) when using jmeter with result code (or not) in a code result is Note that this listener does not print the requested statistics just to the body of the respondent.

And here is my code from Java:

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

So I do not even care about the reaction body. But the results are very high here:

  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   

Now when using the jmeter 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

I have a screenshot no Mental worries'm not going to answer because there will be less readable, but this time the average time 812 ms is approximately 100ms more than before.

Now the Java code that cares about the reaction body (the new method):

  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 "";}}   

and I have modified the previous code, So it prints the feedback, imitates the jmeter behavior, posting the related part:

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

The following results are:

  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   

Report time went up from 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

Popular posts from this blog

Python SQLAlchemy:AttributeError: Neither 'Column' object nor 'Comparator' object has an attribute 'schema' -

java - How not to audit a join table and related entities using Hibernate Envers? -

mongodb - CakePHP paginator ignoring order, but only for certain values -