green-code-initiative / ecoCode-challenge

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

[WEB][42108] Spring Retry: Inconsistent configuration #78

Open JulienBertrand opened 1 year ago

JulienBertrand commented 1 year ago

\newpage

Spring Retry: Inconsistent configuration

Platform

OS OS version Langage
- - Java

Main caracteristics

ID Title Category Sub-category
CRJVM002 Spring Retry: Inconsistent configuration - -

Severity / Remediation Cost

Severity Remediation Cost
Minor Minor

Rule short description

An inconsistent configuration of Spring Retry can lead to blocking thread and therefore increase energy usage.

Rule complete description

Text

With Spring Retry, we can make operation retryable but configuration can be inconsistent with too many retries, or too long retry period which can lead to increase energy usage.

This rule only focuses on the use of Retry with annotation @Retryable This rule needs a threshold max.timeout the maximum time out acceptable for blocking ressource (ms).

Example:

 @Retryable(maxAttempts = 5, backoff = @Backoff(delay = 10)) 
 void retryService(String sql);
 // here max is 50 ms 

HTML

<p>Using <code>@Retryable</code> can lead to increase energy usage.</p>
<p>Limit the configuration of the retry to prevent too large time blocking thread `max.timeout=50000`.</p>
<h2>Noncompliant Code Example, timeout = 10_000_000</h2>
<pre>
 @Retryable(maxAttempts = 4, backoff = @Backoff(delay = 10, multiplier = 100)) 
 void retryService(String sql);
</pre>

Implementation principle

jhertout commented 2 months ago

Interesting rule for its subject. Missing to find a good "max.timeout" and to justify the rule. May be a good example for measure validation in the next hackaton.