Skip to content

Commit

Permalink
Merge pull request jenkinsci#77 from briceruzand/master
Browse files Browse the repository at this point in the history
Improve CPU and memory usage on heavy performance test.
  • Loading branch information
undera authored Dec 15, 2016
2 parents 8e7b9c0 + 1873c93 commit ef0794a
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public abstract class AbstractParser extends PerformanceReportParser {
/**
* A cache that contains serialized PerformanceReport instances. This cache intends to limit disc IO.
*/
private static final Cache<String, PerformanceReport> CACHE = CacheBuilder.newBuilder().maximumSize(1000).build();
private static final Cache<String, PerformanceReport> CACHE = CacheBuilder.newBuilder().maximumSize(1000).softValues().build();

public AbstractParser(String glob) {
super(glob);
Expand Down
46 changes: 26 additions & 20 deletions src/main/java/hudson/plugins/performance/AbstractReport.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,57 +11,63 @@
*/
public abstract class AbstractReport {

protected final DecimalFormat percentFormat;
protected final DecimalFormat dataFormat; // three decimals
protected final ThreadLocal<DecimalFormat> percentFormat;
protected final ThreadLocal<DecimalFormat> dataFormat; // three decimals

abstract public int countErrors();

abstract public double errorPercent();

public AbstractReport() {
final Locale useThisLocale = (Stapler.getCurrentRequest() != null) ? Stapler.getCurrentRequest().getLocale() : Locale.getDefault();
final Locale useThisLocale = ( Stapler.getCurrentRequest() != null ) ? Stapler.getCurrentRequest().getLocale() : Locale.getDefault();

percentFormat = new ThreadLocal<DecimalFormat>() {

@Override
protected DecimalFormat initialValue()
{
return new DecimalFormat("0.0", DecimalFormatSymbols.getInstance(useThisLocale));
}
};

dataFormat = new ThreadLocal<DecimalFormat>() {

@Override
protected DecimalFormat initialValue()
{
return new DecimalFormat("#,###", DecimalFormatSymbols.getInstance( useThisLocale ));
}
};

percentFormat = new DecimalFormat("0.0", DecimalFormatSymbols.getInstance(useThisLocale));
dataFormat = new DecimalFormat("#,###", DecimalFormatSymbols.getInstance(useThisLocale));
}

public String errorPercentFormated() {
Stapler.getCurrentRequest().getLocale();
synchronized (percentFormat) {
return percentFormat.format(errorPercent());
}
return percentFormat.get().format(errorPercent());
}

abstract public long getAverage();

public String getAverageFormated() {
synchronized (dataFormat) {
return dataFormat.format(getAverage());
}
return dataFormat.get().format(getAverage());
}

abstract public long getMedian();

public String getMeanFormated() {
synchronized (dataFormat) {
return dataFormat.format(getMedian());
}
return dataFormat.get().format(getMedian());
}

abstract public long get90Line();

public String get90LineFormated() {
synchronized (dataFormat) {
return dataFormat.format(get90Line());
}
return dataFormat.get().format(get90Line());
}

abstract public long getMax();

public String getMaxFormated() {
synchronized (dataFormat) {
return dataFormat.format(getMax());
}
return dataFormat.get().format(getMax());
}

abstract public long getMin();
Expand Down

0 comments on commit ef0794a

Please sign in to comment.