Bug 59882

Summary: Reduce memory allocations for better throughput
Product: JMeter Reporter: benoit.wiart
Component: MainAssignee: JMeter issues mailing list <issues>
Severity: enhancement CC: p.mouawad
Priority: P2    
Version: 3.0   
Target Milestone: ---   
Hardware: All   
OS: All   

Description benoit.wiart 2016-07-18 21:01:08 UTC
I've been profiling jmeter memory allocation under different conditions
the PR linked to this bug gives substantial improvements.

Gain really depends on the test but in the worst case (compressed content, no embedded resources) it's about 15% less allocations (in bytes)
When not compressed (no embedded resources) and if content-length is sent by the server my test gives 30% reduction in bytes allocated
As always YMMV but this PR is always a win in all my different tests.

Reduction in memory allocated comes from
Better usage of ByteArrayOutputStream  by
  - directly accessing the buffer instead of copying it
  - or by using the commons-lang implementation which avoid copying memory around when extending the buffer
  - or by creating the string directly from the buffer instead of a temporary copy

Avoid unneeded string concatenation due to missing log.isDebugEnabled()
if possible use httpclient CharArrayBuffer to avoid memory allocations
Do not create unneeded silent exceptions
Do not allocate 2 empty iterators on each call to executeSamplePackage
  - LinkedList.iterator() is a stinky monkey. Also see HTTPCORE-361
Set better default size to StringBuilder buffers
improve JOrphanUtils#replaceAllChars : provides a fast path which does not allocate memory

Remark : 
When using ssl, jsse is a major source of unneeded allocation !!!!  (sun.security.ssl.SSLContextImpl#getDefaultCipherSuiteList(boolean))
https://bugs.openjdk.java.net/browse/JDK-8133070 should improve the situation (I did not test it)
the title of the bug is misleading as it's also about an internal cache beeing cleared on each method call.
Comment 1 benoit.wiart 2016-07-18 21:02:11 UTC
PR : https://github.com/apache/jmeter/pull/217
Comment 2 Philippe Mouawad 2016-07-31 14:42:07 UTC
    jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/util/DirectAccessByteArrayOutputStream.java   (with props)