Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Fixed
-
4.1
-
None
-
None
Description
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)
long total = metrics.getReceivedBytesCount();
System.out.println("tot "+total);
metrics.reset();
}
} finally
}
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)
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.]