Search code examples
javajenkinsgarbage-collectiong1gcsoft-references

Soft Reference in the role of GC in java


Recently I come across this article which does the GC tuning the Jenkins which talks about this paramter : -XX:SoftRefLRUPolicyMSPerMB

https://jenkins.io/blog/2016/11/21/gc-tuning/

I understand it prevents OOM error, Because it clears the Soft reference object when it reaches to the threshold.

1) What is this threshold (default = 1000ms in -XX:SoftRefLRUPolicyMSPerMB) means? What does this value denotes?

2) My jenkins seems to have 80% of the softreference (observed using HProf)

3) As suggested in the above article, If I reduce this -XX:SoftRefLRUPolicyMSPerMB flag to 10ms What will be consequence?

NOTE : We use G1GC

Thanks,
Harry


Solution

  • 1) From Oracle:

    Starting with 1.3.1, softly reachable objects will remain alive for some amount of time after the last time they were referenced. The default value is one second of lifetime per free megabyte in the heap. This value can be adjusted using the -XX:SoftRefLRUPolicyMSPerMB flag, which accepts integer values representing milliseconds. For example, to change the value from one second to 2.5 seconds, use this flag:

    -XX:SoftRefLRUPolicyMSPerMB=2500

    3) I mean, it specifically says in the article you linked to. You'll possibly free up heap space by potentially sacrificing some performance. What more can we tell you?

    If Jenkins consumes excessive old generation memory, it may help to make soft references easier to flush by reducing -XX:SoftRefLRUPolicyMSPerMB from its default (1000) to something smaller (say 10-200). The catch is that SoftReferences are often used for objects that are relatively expensive to load, such lazy-loaded build records and pipeline FlowNode data