jira-importer opened a new issue, #1445:
URL: https://github.com/apache/httpcomponents-core/issues/1445

   
**[Sebb](https://issues.apache.org/jira/secure/[email protected])**
 opened 
**[HTTPCORE-254](https://issues.apache.org/jira/browse/HTTPCORE-254?redirect=false)**
 and commented
   
   The values obtained from getMetrics are erratic. For example, the following 
code:
   
   DefaultHttpClient httpclient = new DefaultHttpClient();
   try {
   HttpRequestBase req = new 
HttpGet("http://wiki.apache.org/jakarta-jmeter/JMeterCommitters";);
   for(int i = 0; i<3;i++) {
   HttpContext localContext = new BasicHttpContext();
   HttpResponse rsp = httpclient.execute(req, localContext);
   System.out.println(rsp.getStatusLine());
   HttpConnection conn = (HttpConnection) 
localContext.getAttribute(ExecutionContext.HTTP_CONNECTION);
   HttpConnectionMetrics metrics = conn.getMetrics();
   long hdr = metrics.getReceivedBytesCount();
   System.out.println("hdr "+hdr);
   
       HttpEntity entity = rsp.getEntity();
   
   //            Thread.sleep(1500);
   if (entity != null) {
   EntityUtils.consume(entity);
   }
   long total = metrics.getReceivedBytesCount();
   System.out.println("tot "+total);
   metrics.reset();
   }
   } finally {
   // When HttpClient instance is no longer needed,
   // shut down the connection manager to ensure
   // immediate deallocation of all system resources
   httpclient.getConnectionManager().shutdown();
   }
   }
   
   May produce:
   
   HTTP/1.1 200 OK
   hdr 284
   tot 566
   HTTP/1.1 200 OK
   hdr 283
   tot 313
   HTTP/1.1 200 OK
   hdr 283
   tot 313
   
   Enabling the sleep produces more consistent (but still inaccurate) results:
   
   HTTP/1.1 200 OK
   hdr 284
   tot 10946
   HTTP/1.1 200 OK
   hdr 283
   tot 10945
   HTTP/1.1 200 OK
   hdr 283
   tot 10945
   
   Rather unexpected behaviour, but as it happens, a very simple cause:
   
   // AbstractSessionInputBuffer lines 184-189
   // If the remaining capacity is big enough, read directly from the
   // underlying input stream bypassing the buffer.
   if (len > this.minChunkLimit) {
   return this.instream.read(b, off, len);
   } else {
   // otherwise read to the buffer first
   
   The code also bypasses the metrics collection...
   
   Fixing this results in the following (with or without the sleep):
   
   ```
   HTTP/1.1 200 OK
   hdr 284
   tot 16643
   HTTP/1.1 200 OK
   hdr 283
   tot 16642
   HTTP/1.1 200 OK
   hdr 283
   tot 16642
   ```
   
   [Note that the slight variation in size is due to a minor change in the 
headers.]
   
   
   ---
   
   **Affects:** 4.1
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to