Bug 59882 - Reduce memory allocations for better throughput
Summary: Reduce memory allocations for better throughput
Alias: None
Product: JMeter - Now in Github
Classification: Unclassified
Component: Main (show other bugs)
Version: 3.0
Hardware: All All
: P2 enhancement (vote)
Target Milestone: ---
Assignee: JMeter issues mailing list
Depends on:
Reported: 2016-07-18 21:01 UTC by benoit.wiart
Modified: 2016-07-31 14:42 UTC (History)
1 user (show)


Note You need to log in before you can comment on or make changes to this bug.
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)
Comment 3 The ASF infrastructure team 2022-09-24 20:38:04 UTC
This issue has been migrated to GitHub: https://github.com/apache/jmeter/issues/4026