From 057a78d3ba3f51e313ef7a1bada5ddca18504cd6 Mon Sep 17 00:00:00 2001 From: Ben Manes Date: Sun, 16 Aug 2020 15:02:21 -0700 Subject: [PATCH] Add K5 cloud traces to the simulator --- .../cache/simulator/parser/TraceFormat.java | 2 + .../snia/parallel/K5cloudTraceReader.java | 49 +++++++++++++++++++ .../parallel/TencentBlockTraceReader.java | 26 +++++----- .../simulator/policy/irr/DClockPolicy.java | 4 +- simulator/src/main/resources/reference.conf | 1 + 5 files changed, 66 insertions(+), 16 deletions(-) create mode 100644 simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/parser/snia/parallel/K5cloudTraceReader.java diff --git a/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/parser/TraceFormat.java b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/parser/TraceFormat.java index 30f079bdf4..79944daba2 100644 --- a/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/parser/TraceFormat.java +++ b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/parser/TraceFormat.java @@ -37,6 +37,7 @@ import com.github.benmanes.caffeine.cache.simulator.parser.lirs.LirsTraceReader; import com.github.benmanes.caffeine.cache.simulator.parser.scarab.ScarabTraceReader; import com.github.benmanes.caffeine.cache.simulator.parser.snia.cambridge.CambridgeTraceReader; +import com.github.benmanes.caffeine.cache.simulator.parser.snia.parallel.K5cloudTraceReader; import com.github.benmanes.caffeine.cache.simulator.parser.snia.parallel.TencentBlockTraceReader; import com.github.benmanes.caffeine.cache.simulator.parser.snia.parallel.TencentPhotoTraceReader; import com.github.benmanes.caffeine.cache.simulator.parser.umass.network.YoutubeTraceReader; @@ -68,6 +69,7 @@ public enum TraceFormat { OUTBRAIN(OutbrainTraceReader::new), SCARAB(ScarabTraceReader::new), SNIA_CAMBRIDGE(CambridgeTraceReader::new), + SNIA_K5CLOUD(K5cloudTraceReader::new), SNIA_TENCENT_BLOCK(TencentBlockTraceReader::new), SNIA_TENCENT_PHOTO(TencentPhotoTraceReader::new), UMASS_STORAGE(StorageTraceReader::new), diff --git a/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/parser/snia/parallel/K5cloudTraceReader.java b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/parser/snia/parallel/K5cloudTraceReader.java new file mode 100644 index 0000000000..8f7ed10934 --- /dev/null +++ b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/parser/snia/parallel/K5cloudTraceReader.java @@ -0,0 +1,49 @@ +/* + * Copyright 2020 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.snia.parallel; + +import java.io.IOException; +import java.util.stream.LongStream; + +import com.github.benmanes.caffeine.cache.simulator.parser.TextTraceReader; +import com.github.benmanes.caffeine.cache.simulator.parser.TraceReader.KeyOnlyTraceReader; + +/** + * A reader for the K5cloud trace files provided by + * SNIA. + * + * @author ben.manes@gmail.com (Ben Manes) + */ +public final class K5cloudTraceReader extends TextTraceReader implements KeyOnlyTraceReader { + static final int BLOCK_SIZE = 512; + + public K5cloudTraceReader(String filePath) { + super(filePath); + } + + @Override + public LongStream keys() throws IOException { + return lines() + .map(line -> line.split(",")) + .filter(array -> array[2].charAt(0) == 'R') + .flatMapToLong(array -> { + long offset = Long.parseLong(array[3]); + long startBlock = (offset / BLOCK_SIZE); + int sequence = Integer.parseInt(array[4]) / BLOCK_SIZE; + return LongStream.range(startBlock, startBlock + sequence); + }); + } +} diff --git a/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/parser/snia/parallel/TencentBlockTraceReader.java b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/parser/snia/parallel/TencentBlockTraceReader.java index 56cee9ddac..022f15332c 100644 --- a/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/parser/snia/parallel/TencentBlockTraceReader.java +++ b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/parser/snia/parallel/TencentBlockTraceReader.java @@ -16,12 +16,10 @@ package com.github.benmanes.caffeine.cache.simulator.parser.snia.parallel; import java.io.IOException; -import java.util.List; import java.util.stream.LongStream; import com.github.benmanes.caffeine.cache.simulator.parser.TextTraceReader; import com.github.benmanes.caffeine.cache.simulator.parser.TraceReader.KeyOnlyTraceReader; -import com.google.common.base.Splitter; /** * A reader for the Tencent Block Storage trace files provided by @@ -30,9 +28,8 @@ * @author ben.manes@gmail.com (Ben Manes) */ public final class TencentBlockTraceReader extends TextTraceReader implements KeyOnlyTraceReader { - static final Splitter splitter = Splitter.on(','); static final int BLOCK_SIZE = 512; - static final char WRITE = '1'; + static final char READ = '0'; public TencentBlockTraceReader(String filePath) { super(filePath); @@ -40,15 +37,16 @@ public TencentBlockTraceReader(String filePath) { @Override public LongStream keys() throws IOException { - return lines().flatMapToLong(line -> { - List list = splitter.splitToList(line); - if (list.get(3).charAt(0) == WRITE) { - return LongStream.empty(); - } - long offset = Long.parseLong(list.get(1)); - long startBlock = (offset / BLOCK_SIZE); - int sequence = Integer.parseInt(list.get(2)); - return LongStream.range(startBlock, startBlock + sequence); - }); + return lines() + .map(line -> line.split(",")) + .filter(array -> array[3].charAt(0) == READ) + .flatMapToLong(array -> { + long offset = Long.parseLong(array[1]); + long startBlock = (offset / BLOCK_SIZE); + int sequence = Integer.parseInt(array[2]); + int volumeId = Integer.parseInt(array[4]); + long key = (((long) volumeId) << 31) | Long.hashCode(startBlock); + return LongStream.range(key, key + sequence); + }); } } diff --git a/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/irr/DClockPolicy.java b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/irr/DClockPolicy.java index 2104e36828..d8d59c44fc 100644 --- a/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/irr/DClockPolicy.java +++ b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/irr/DClockPolicy.java @@ -91,7 +91,7 @@ public void record(long key) { if (node == null) { onMiss(key); } else if (node.status == Status.NON_RESIDENT) { - onNonResidentHir(node); + onNonResidentHit(node); } else if (node.status == Status.INACTIVE) { onInactiveHit(node); } else if (node.status == Status.ACTIVE) { @@ -149,7 +149,7 @@ private void onActiveHit(Node node) { policyStats.recordHit(); } - private void onNonResidentHir(Node node) { + private void onNonResidentHit(Node node) { // So when a refault distance of (R - E) is observed and there are at least (R - E) active // pages, the refaulting page is activated optimistically in the hope that (R - E) active pages // are actually used less frequently than the refaulting page - or even not used at all anymore. diff --git a/simulator/src/main/resources/reference.conf b/simulator/src/main/resources/reference.conf index dacf83615e..163304bcb7 100644 --- a/simulator/src/main/resources/reference.conf +++ b/simulator/src/main/resources/reference.conf @@ -453,6 +453,7 @@ caffeine.simulator { # outbrain: format from Outbrain trace provided on Kaggle # scarab: format of Scarab Research traces # snia-cambridge: format from the SNIA MSR Cambridge traces + # snia-k5cloud: format from the SNIA K5cloud traces # snia-tencent-block: format from the SNIA Tencent Block traces # snia-tencent-photo: format from the SNIA Tencent Photo traces # umass-storage: format from the University of Massachusetts storage traces