Skip to content

Commit

Permalink
Add simulator support for LIRS2's traces
Browse files Browse the repository at this point in the history
  • Loading branch information
ben-manes committed Jun 27, 2021
1 parent 7bca129 commit f279485
Show file tree
Hide file tree
Showing 17 changed files with 172 additions and 113 deletions.
1 change: 0 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ allprojects {

repositories {
mavenCentral()
maven { url 'https://jitpack.io' }
}

group = 'com.github.ben-manes.caffeine'
Expand Down
1 change: 1 addition & 0 deletions checksum.xml
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@
<trusted-key id='a41f13c999945293' group='commons-logging' />
<trusted-key id='379ce192d401ab61' group='info.picocli' />
<trusted-key id='0d9cb5ee96b7bc22' group='io.airlift' />
<trusted-key id='32bbf14af07ca77b' group='io.github.fastfilter' />
<trusted-key id='a6ea2e2bf22e0543' group='io.github.java-diff-utils' />
<trusted-key id='602ec18d20c4661c' group='io.github.x-stream' />
<trusted-key id='94b291aef984a085' group='io.reactivex.rxjava3' />
Expand Down
2 changes: 1 addition & 1 deletion gradle/codeQuality.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ tasks.withType(JavaExec) {
tasks.withType(JavaCompile).configureEach {
dependsOn downloadCaffeineLocal
options.compilerArgs << [
'-Xlint:all,-exports', '-auxiliaryclass',
'-Xlint:all,-processing,-exports', '-auxiliaryclass',
'-requires-automatic', '-requires-transitive-automatic',
].join(',')
options.encoding = 'UTF-8'
Expand Down
12 changes: 6 additions & 6 deletions gradle/dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ ext {
errorproneJavac: '9+181-r4173-1',
elasticSearch: '7.13.2',
expiringMap: '0.5.9',
fastfilter: '1.0',
fastfilter: '1.0.2',
fastutil: '8.5.4',
flipTables: '1.1.0',
googleJavaFormat: '1.10.0',
Expand Down Expand Up @@ -72,18 +72,18 @@ ext {
jcacheTck: '1.1.1',
jctools: '3.3.0',
junit: '4.13.2',
mockito: '3.11.1',
mockito: '3.11.2',
paxExam: '4.13.4',
testng: '7.4.0',
truth: '1.1.3',
felix: '7.0.0',
felix: '7.0.1',
felixScr: '2.1.26',
osgiUtilFunction: '1.1.0',
osgiUtilPromise: '1.1.1',
]
pluginVersions = [
bnd: '5.3.0',
checkstyle: '8.43',
checkstyle: '8.44',
coveralls: '2.12.0',
errorprone: '2.0.1',
findsecbugs: '1.11.0',
Expand All @@ -92,7 +92,7 @@ ext {
jmhReport: '0.9.0',
nexusPublish: '1.1.0',
nullaway: '1.1.0',
pmd: '6.35.0',
pmd: '6.36.0',
semanticVersioning: '1.1.0',
shadow: '7.0.0',
sonarqube: '3.3',
Expand Down Expand Up @@ -126,7 +126,7 @@ ext {
exclude group: 'org.apache.lucene'
},
expiringMap: "net.jodah:expiringmap:${versions.expiringMap}",
fastfilter: "com.github.FastFilter:fastfilter_java:${versions.fastfilter}",
fastfilter: "io.github.fastfilter:fastfilter:${versions.fastfilter}",
fastutil: "it.unimi.dsi:fastutil-core:${versions.fastutil}",
flipTables: "com.jakewharton.fliptables:fliptables:${versions.flipTables}",
googleJavaFormat: "com.google.googlejavaformat:google-java-format:${versions.googleJavaFormat}",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* Copyright 2021 Ben Manes. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.github.benmanes.caffeine.cache.simulator.parser;

import java.io.DataOutputStream;
import java.io.IOException;
import java.io.OutputStream;

/**
* A skeletal implementation that writes to the trace file as binary data.
*
* @author [email protected] (Ben Manes)
*/
public abstract class BinaryTraceWriter implements TraceWriter {
private final DataOutputStream writer;

protected BinaryTraceWriter(OutputStream output) {
this.writer = new DataOutputStream(output);
}

protected DataOutputStream writer() {
return writer;
}

@Override
public void close() throws IOException {
writer.close();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
import java.util.function.Function;

import com.github.benmanes.caffeine.cache.simulator.parser.adapt_size.AdaptSizeTraceWriter;
import com.github.benmanes.caffeine.cache.simulator.parser.climb.ClimbTraceWriter;
import com.github.benmanes.caffeine.cache.simulator.parser.cloud_physics.CloudPhysicsTraceWriter;
import com.github.benmanes.caffeine.cache.simulator.parser.lirs.LirsTraceWriter;

/**
* The trace output format.
Expand All @@ -30,7 +31,8 @@
@SuppressWarnings("ImmutableEnumChecker")
public enum OutputFormat {
ADAPT_SIZE(AdaptSizeTraceWriter::new),
CLIMB(ClimbTraceWriter::new);
CLOUD_PHYSICS(CloudPhysicsTraceWriter::new),
LIRS(LirsTraceWriter::new);

private final Function<OutputStream, TraceWriter> factory;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,11 @@

import java.io.BufferedOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.io.UncheckedIOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Stream;

import com.github.benmanes.caffeine.cache.simulator.policy.AccessEvent;
import com.google.common.base.Stopwatch;

import picocli.CommandLine;
Expand All @@ -38,7 +34,7 @@
* into Java.
* <p>
* <pre>{@code
* ./gradlew :simulator:rewrite \
* ./gradlew :simulator:rewrite -q \
* -PinputFormat=? \
* -PinputFiles=? \
* -PoutputFile=? \
Expand All @@ -47,11 +43,10 @@
*
* @author [email protected] (Ben Manes)
*/
@SuppressWarnings({"PMD.ImmutableField", "FieldCanBeFinal"})
public final class Rewriter implements Runnable {
@Option(names = "--inputFiles", required = true, description = "The trace input files. To use "
+ "a mix of formats, specify the entry as format:path, e.g. lirs:loop.trace.gz")
private List<String> inputFiles = new ArrayList<>();
@Option(names = "--inputFiles", required = true, split = ",", description = "The trace input "
+ "files. To use a mix of formats, specify the entry as format:path, e.g. lirs:loop.trace.gz")
private List<String> inputFiles;
@Option(names = "--inputFormat", required = true, description = "The default trace input format")
private TraceFormat inputFormat;

Expand All @@ -62,10 +57,10 @@ public final class Rewriter implements Runnable {

@Override
public void run() {
Stopwatch stopwatch = Stopwatch.createStarted();
try (OutputStream output = new BufferedOutputStream(Files.newOutputStream(outputFile));
Stream<AccessEvent> events = inputFormat.readFiles(inputFiles).events();
TraceWriter writer = outputFormat.writer(output)) {
var stopwatch = Stopwatch.createStarted();
try (var output = new BufferedOutputStream(Files.newOutputStream(outputFile));
var events = inputFormat.readFiles(inputFiles).events();
var writer = outputFormat.writer(output)) {
int[] tick = { 0 };
writer.writeHeader();
events.forEach(event -> {
Expand All @@ -77,7 +72,8 @@ public void run() {
}
});
writer.writeFooter();
System.out.printf("Rewrote %,d events in %s%n", tick[0], stopwatch);
System.out.printf("Rewrote %,d events from %,d inputs in %s%n",
tick[0], inputFiles.size(), stopwatch);
} catch (IOException e) {
throw new UncheckedIOException(e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
import com.github.benmanes.caffeine.cache.simulator.parser.arc.ArcTraceReader;
import com.github.benmanes.caffeine.cache.simulator.parser.cache2k.Cache2kTraceReader;
import com.github.benmanes.caffeine.cache.simulator.parser.camelab.CamelabTraceReader;
import com.github.benmanes.caffeine.cache.simulator.parser.climb.ClimbTraceReader;
import com.github.benmanes.caffeine.cache.simulator.parser.cloud_physics.CloudPhysicsTraceReader;
import com.github.benmanes.caffeine.cache.simulator.parser.corda.CordaTraceReader;
import com.github.benmanes.caffeine.cache.simulator.parser.gradle.GradleTraceReader;
import com.github.benmanes.caffeine.cache.simulator.parser.kaggle.OutbrainTraceReader;
Expand Down Expand Up @@ -65,7 +65,7 @@ public enum TraceFormat {
ARC(ArcTraceReader::new),
CACHE2K(Cache2kTraceReader::new),
CAMELAB(CamelabTraceReader::new),
CLIMB(ClimbTraceReader::new),
CLOUD_PHYSICS(CloudPhysicsTraceReader::new),
CORDA(CordaTraceReader::new),
GRADLE(GradleTraceReader::new),
LIRS(LirsTraceReader::new),
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* Copyright 2021 Ben Manes. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.github.benmanes.caffeine.cache.simulator.parser.cloud_physics;

import java.io.DataInputStream;
import java.io.IOException;
import java.util.Set;

import com.github.benmanes.caffeine.cache.simulator.parser.BinaryTraceReader;
import com.github.benmanes.caffeine.cache.simulator.policy.AccessEvent;
import com.github.benmanes.caffeine.cache.simulator.policy.Policy.Characteristic;
import com.google.common.collect.ImmutableSet;

/**
* A reader for the trace files provided by the author of LIRS2. See
* <a href="https://github.com/zhongch4g/LIRS2">traces</a>.
*
* @author [email protected] (Ben Manes)
*/
public final class CloudPhysicsTraceReader extends BinaryTraceReader {

public CloudPhysicsTraceReader(String filePath) {
super(filePath);
}

@Override
public Set<Characteristic> characteristics() {
return ImmutableSet.of();
}

@Override
protected AccessEvent readEvent(DataInputStream input) throws IOException {
return AccessEvent.forKey(Integer.toUnsignedLong(input.readInt()));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* Copyright 2021 Ben Manes. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.github.benmanes.caffeine.cache.simulator.parser.cloud_physics;

import java.io.IOException;
import java.io.OutputStream;

import com.github.benmanes.caffeine.cache.simulator.parser.BinaryTraceWriter;
import com.github.benmanes.caffeine.cache.simulator.policy.AccessEvent;
import com.google.common.hash.Hashing;

/**
* A writer for the trace format used by the authors of the LIRS2 algorithm.
*
* @author [email protected] (Ben Manes)
*/
public final class CloudPhysicsTraceWriter extends BinaryTraceWriter {

public CloudPhysicsTraceWriter(OutputStream output) {
super(output);
}

@Override
public void writeEvent(int tick, AccessEvent event) throws IOException {
int key = Hashing.murmur3_128().hashLong(event.key()).asInt();
writer().writeInt(key);
}
}
Loading

0 comments on commit f279485

Please sign in to comment.