Mercurial > hg > gc-bench
view src/main/java/org/openjdk/gcbench/fragger/LRUFragger.java @ 81:c1b1811b7730
Fragger updates
author | shade |
---|---|
date | Thu, 26 Oct 2017 12:09:35 +0200 |
parents | f69f4c3fa113 |
children | 583fef4276f5 |
line wrap: on
line source
package org.openjdk.gcbench.fragger; import org.openjdk.gcbench.tests.Sequence; import org.openjdk.jmh.annotations.*; import org.openjdk.jmh.infra.Blackhole; import org.openjdk.jmh.profile.SafepointsProfiler; import org.openjdk.jmh.results.Result; import org.openjdk.jmh.results.RunResult; import org.openjdk.jmh.runner.Runner; import org.openjdk.jmh.runner.RunnerException; import org.openjdk.jmh.runner.options.*; import java.io.PrintStream; import java.util.LinkedHashMap; import java.util.Map; import java.util.concurrent.ThreadLocalRandom; import java.util.concurrent.TimeUnit; @Warmup(iterations = 0) @Measurement(iterations = 1, time = 1) @Fork(1) @BenchmarkMode(Mode.SingleShotTime) @OutputTimeUnit(TimeUnit.SECONDS) @Threads(8) @State(Scope.Thread) public class LRUFragger { static final int PAYLOAD_SIZE = 4096; static final long TARGET_ALLOCS = 256L * 1024 * 1024 * 1024; @Param({"1000"}) int size; Map<Object, Object> cache; int keyCount; @Setup public void setup() { cache = new LinkedHashMap<Object, Object>(size*4/3, 0.75f, true) { @Override protected boolean removeEldestEntry(Map.Entry<Object, Object> eldest) { return size() > size; } }; keyCount = (int) (size * (1D / 0.8D)); // 80% hit rate for (int c = 0; c < size; c++) { cache.put("Key " + c, new byte[PAYLOAD_SIZE]); } } @Benchmark public void test(Blackhole bh) { long allocs = 0; while (allocs < TARGET_ALLOCS) { int idx = ThreadLocalRandom.current().nextInt(keyCount); Object k = "Key " + idx; Object o = cache.get(k); if (o == null) { o = new byte[PAYLOAD_SIZE]; allocs += PAYLOAD_SIZE; cache.put(k, o); } bh.consume(o); } } public static void main(String... args) throws RunnerException { Options parent = new OptionsBuilder() .detectJvmArgs() .jvmArgsAppend("-Xmx100g", "-Xms100g", "-XX:MaxGCPauseMillis=10", "-XX:+AlwaysPreTouch", "-XX:-UseBiasedLocking", "-XX:+UnlockDiagnosticVMOptions", "-XX:GuaranteedSafepointInterval=10000000") .include(LRUFragger.class.getCanonicalName()) .verbosity(VerboseMode.SILENT) .addProfiler(SafepointsProfiler.class) .timeout(TimeValue.hours(1)) // .warmupIterations(5) //.warmupTime(TimeValue.seconds(10)) // .warmupTime(TimeValue.seconds(5)) // .measurementIterations(5) //.measurementTime(TimeValue.seconds(10)) // .measurementTime(TimeValue.seconds(5)) // .threads(8) .build(); PrintStream pw = System.out; // Sequence sizeSeq = Sequence.steps(0, 24_000_000, 20); // for 100 GB Sequence sizeSeq = Sequence.steps(0, 3_000_000, 20); // for 100 GB, 8 threads // Sequence sizeSeq = Sequence.steps(0, 2_400_000, 10); // for 10 GB // Sequence sizeSeq = Sequence.predefined(1_000_000); // for (String gc : new String[]{"-XX:+UseParallelGC"}) { for (String gc : new String[]{"-XX:+UseShenandoahGC", "-XX:+UseParallelGC", "-XX:+UseG1GC", "-XX:+UseConcMarkSweepGC"}) { for (Object size : sizeSeq) { if (size.toString().equals("0")) continue; Options opt = new OptionsBuilder() .parent(parent) .jvmArgsPrepend(gc) .param("size", size.toString()) .build(); try { RunResult res = new Runner(opt).runSingle(); Result pr = res.getPrimaryResult(); Map<String, Result> sec = res.getSecondaryResults(); pw.printf("%10s, %30s, %10.3f, %10.3f, %5.0f, %10.3f, %10.3f, %10.3f, %10.3f, %10.3f, %10.3f, %10.3f, %10.3f, %10.3f, %10.3f, %10.3f%n", size.toString(), gc, pr.getScore(), pr.getScoreError(), sec.get("·safepoints.pause.count").getScore(), sec.get("·safepoints.pause").getScore(), sec.get("·safepoints.interval").getScore(), sec.get("·safepoints.pause.avg").getScore(), sec.get("·safepoints.pause.p0.00").getScore(), sec.get("·safepoints.pause.p0.50").getScore(), sec.get("·safepoints.pause.p0.90").getScore(), sec.get("·safepoints.pause.p0.95").getScore(), sec.get("·safepoints.pause.p0.99").getScore(), sec.get("·safepoints.pause.p0.999").getScore(), sec.get("·safepoints.pause.p0.9999").getScore(), sec.get("·safepoints.pause.p1.00").getScore() ); } catch (RunnerException e) { // okay } } } } }