Mercurial > hg > gc-bench
view src/main/java/org/openjdk/gcbench/fragger/LRUFragger.java @ 90:14c1bb4faa6e
Optimize imports
author | shade |
---|---|
date | Thu, 23 Nov 2017 15:12:49 +0100 |
parents | 583fef4276f5 |
children |
line wrap: on
line source
/* * Copyright (c) 2017, Red Hat Inc. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ 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.Options; import org.openjdk.jmh.runner.options.OptionsBuilder; import org.openjdk.jmh.runner.options.TimeValue; import org.openjdk.jmh.runner.options.VerboseMode; 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 } } } } }