green-code-initiative / ecoCode-challenge

Emboard in the hackhatons serie for improving ecoCode
3 stars 4 forks source link

[WEB][42108] Optimized JVM: Tune your Garbage collector #82

Open JulienBertrand opened 1 year ago

JulienBertrand commented 1 year ago

\newpage

Optimized JVM: Tune your Garbage collector

Platform

OS OS version Langage
- - Java

Main caracteristics

ID Title Category Sub-category
CRJVM006-42108 Optimized JVM: Tune your Garbage collector Environment Optimized JVM

Severity / Remediation Cost

Severity Remediation Cost
Minor Minor

Rule short description

Using -XX:+UseG1GC and -XX:+UseStringDeduplication flags to tune your JVM to be more energy efficient.

Rule complete description

Text

Using -XX:+UseG1GC and -XX:+UseStringDeduplication flags to tune your JVM to be more energy efficient.

The -XX:+UseG1GC argument will change the garbage collector behaviorto be more energy efficient. Note that the G1GC is available since Java 8 and is the default value since Java 11.

The -XX:+UseStringDeduplication argument will attempts to eliminate duplicate strings as a part of the collection process

Code samples:

<!-- JIB Configuration -->
<jvmFlag>-XX:+UseG1GC</jvmFlag>
<jvmFlag>-XX:+UseStringDeduplication</jvmFlag>
#Docker file 
ENTRYPOINT exec java -XX:+UseG1GC -XX:+UseStringDeduplication -jar ./ecoCode.jar

Documentation:

HTML

<p>Using <code>-XX:+UseG1GC</code> and <code>-XX:+UseStringDeduplication</code> flags to tune your JVM to be more energy efficient.</p>

<p>The <code>-XX:+UseG1GC</code> argument will change the garbage collector behavior to be more energy efficient.
</p>

<p>The <code>-XX:+UseStringDeduplication</code> argument will attempts to eliminate duplicate strings as a part of the collection process.
</p>

<h2>Compliant Solutions: </h2>
<pre>
    <!-- JIB Configuration -->
    <jvmFlag>-XX:+UseG1GC</jvmFlag>
    <jvmFlag>-XX:+UseStringDeduplication</jvmFlag>
</pre>
<pre>
    #Docker file 
    ENTRYPOINT exec java -XX:+UseG1GC -XX:+UseStringDeduplication -jar ./ecoCode.jar
</pre>

Implementation principle

jhertout commented 6 months ago

Hello,

For the use of G1GC:

I think the usage of the GC is a good thing to look at but at this point we cannot affirm which one is the best. And without looking at the options it is worse. For me, we cannot implement a rule at this point.

For use of UseStringDeduplication

To understand what the option does: https://dzone.com/articles/usestringdeduplication It seems to be a good idea to look at the option, even if its use is not quite simple and the improvement not always easy to see. However it is a "good practice" and we do not detect that in ecoCode and I am not sure we can throw a bad practice systematically if we do not found this option in the GC options wherever they are.

For the last reason, I think we cannot implement this rule in ecoCode.