-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Sieve and S3-FIFO to the simulator (#1417)
- Loading branch information
Showing
14 changed files
with
716 additions
and
299 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,13 +23,20 @@ | |
|
||
import java.util.List; | ||
import java.util.Set; | ||
import java.util.function.Function; | ||
import java.util.regex.Pattern; | ||
|
||
import org.checkerframework.checker.nullness.qual.Nullable; | ||
|
||
import com.github.benmanes.caffeine.cache.simulator.admission.Admission; | ||
import com.github.benmanes.caffeine.cache.simulator.membership.FilterType; | ||
import com.github.benmanes.caffeine.cache.simulator.parser.TraceFormat; | ||
import com.github.benmanes.caffeine.cache.simulator.report.ReportFormat; | ||
import com.google.common.base.CaseFormat; | ||
import com.google.common.primitives.Ints; | ||
import com.google.common.primitives.Longs; | ||
import com.typesafe.config.Config; | ||
import com.typesafe.config.ConfigException; | ||
|
||
/** | ||
* The simulator's configuration. A policy can extend this class as a convenient way to extract | ||
|
@@ -38,6 +45,8 @@ | |
* @author [email protected] (Ben Manes) | ||
*/ | ||
public class BasicSettings { | ||
private static final Pattern NUMERIC_SEPARATOR = Pattern.compile("[_,]"); | ||
|
||
private final Config config; | ||
|
||
public BasicSettings(Config config) { | ||
|
@@ -53,7 +62,7 @@ public ReportSettings report() { | |
} | ||
|
||
public int randomSeed() { | ||
return config().getInt("random-seed"); | ||
return getFormattedInt("random-seed"); | ||
} | ||
|
||
public Set<String> policies() { | ||
|
@@ -78,7 +87,7 @@ public TinyLfuSettings tinyLfu() { | |
} | ||
|
||
public long maximumSize() { | ||
return config().getLong("maximum-size"); | ||
return getFormattedLong("maximum-size"); | ||
} | ||
|
||
public TraceSettings trace() { | ||
|
@@ -90,6 +99,30 @@ public Config config() { | |
return config; | ||
} | ||
|
||
/** Gets the quoted integer at the given path, ignoring comma and underscore separators */ | ||
protected int getFormattedInt(String path) { | ||
return parseFormattedNumber(path, config()::getInt, Ints::tryParse); | ||
} | ||
|
||
/** Gets the quoted long at the given path, ignoring comma and underscore separators */ | ||
protected long getFormattedLong(String path) { | ||
return parseFormattedNumber(path, config()::getLong, Longs::tryParse); | ||
} | ||
|
||
private <T extends Number> T parseFormattedNumber(String path, | ||
Function<String, T> getter, Function<String, @Nullable T> tryParse) { | ||
try { | ||
return getter.apply(path); | ||
} catch (ConfigException.Parse | ConfigException.WrongType e) { | ||
var matcher = NUMERIC_SEPARATOR.matcher(config().getString(path)); | ||
var value = tryParse.apply(matcher.replaceAll("")); | ||
if (value == null) { | ||
throw e; | ||
} | ||
return value; | ||
} | ||
} | ||
|
||
public final class ActorSettings { | ||
public int mailboxSize() { | ||
return config().getInt("actor.mailbox-size"); | ||
|
@@ -183,10 +216,10 @@ public boolean enabled() { | |
|
||
public final class TraceSettings { | ||
public long skip() { | ||
return config().getLong("trace.skip"); | ||
return getFormattedLong("trace.skip"); | ||
} | ||
public long limit() { | ||
return config().getIsNull("trace.limit") ? Long.MAX_VALUE : config().getLong("trace.limit"); | ||
return config().getIsNull("trace.limit") ? Long.MAX_VALUE : getFormattedLong("trace.limit"); | ||
} | ||
public boolean isFiles() { | ||
return config().getString("trace.source").equals("files"); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
...b/benmanes/caffeine/cache/simulator/parser/libcachesim/csv/LibCacheSimCsvTraceReader.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/* | ||
* Copyright 2023 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.libcachesim.csv; | ||
|
||
import static com.github.benmanes.caffeine.cache.simulator.policy.Policy.Characteristic.WEIGHTED; | ||
|
||
import java.util.Set; | ||
import java.util.stream.Stream; | ||
|
||
import com.github.benmanes.caffeine.cache.simulator.parser.TextTraceReader; | ||
import com.github.benmanes.caffeine.cache.simulator.policy.AccessEvent; | ||
import com.github.benmanes.caffeine.cache.simulator.policy.Policy.Characteristic; | ||
|
||
/** | ||
* A reader for the <b>data/trace.csv</b> file provided by the authors of | ||
* <a href="https://github.com/1a1a11a/libCacheSim">libCacheSim</a>. | ||
* | ||
* @author [email protected] (Ben Manes) | ||
*/ | ||
public final class LibCacheSimCsvTraceReader extends TextTraceReader { | ||
|
||
public LibCacheSimCsvTraceReader(String filePath) { | ||
super(filePath); | ||
} | ||
|
||
@Override | ||
public Set<Characteristic> characteristics() { | ||
return Set.of(WEIGHTED); | ||
} | ||
|
||
@Override | ||
public Stream<AccessEvent> events() { | ||
return lines() | ||
.skip(1) | ||
.map(line -> line.split(",")) | ||
.map(array -> { | ||
long key = Long.parseLong(array[4]); | ||
int weight = Integer.parseInt(array[3]); | ||
return AccessEvent.forKeyAndWeight(key, weight); | ||
}); | ||
} | ||
} |
4 changes: 4 additions & 0 deletions
4
...ava/com/github/benmanes/caffeine/cache/simulator/parser/libcachesim/csv/package-info.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
@CheckReturnValue | ||
package com.github.benmanes.caffeine.cache.simulator.parser.libcachesim.csv; | ||
|
||
import com.google.errorprone.annotations.CheckReturnValue; |
58 changes: 58 additions & 0 deletions
58
...es/caffeine/cache/simulator/parser/libcachesim/twitter/LibCacheSimTwitterTraceReader.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/* | ||
* Copyright 2023 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.libcachesim.twitter; | ||
|
||
import static com.github.benmanes.caffeine.cache.simulator.policy.Policy.Characteristic.WEIGHTED; | ||
|
||
import java.util.Set; | ||
import java.util.stream.Stream; | ||
|
||
import com.github.benmanes.caffeine.cache.simulator.parser.TextTraceReader; | ||
import com.github.benmanes.caffeine.cache.simulator.policy.AccessEvent; | ||
import com.github.benmanes.caffeine.cache.simulator.policy.Policy.Characteristic; | ||
|
||
import net.openhft.hashing.LongHashFunction; | ||
|
||
/** | ||
* A reader for the <b>data/twitter_cluster52.csv</b> file provided by the authors of | ||
* <a href="https://github.com/1a1a11a/libCacheSim">libCacheSim</a>. | ||
* | ||
* @author [email protected] (Ben Manes) | ||
*/ | ||
public final class LibCacheSimTwitterTraceReader extends TextTraceReader { | ||
|
||
public LibCacheSimTwitterTraceReader(String filePath) { | ||
super(filePath); | ||
} | ||
|
||
@Override | ||
public Set<Characteristic> characteristics() { | ||
return Set.of(WEIGHTED); | ||
} | ||
|
||
@Override | ||
public Stream<AccessEvent> events() { | ||
var hasher = LongHashFunction.xx3(); | ||
return lines() | ||
.skip(1) | ||
.map(line -> line.split(", ")) | ||
.map(array -> { | ||
long key = hasher.hashChars(array[1]); | ||
int weight = Integer.parseInt(array[2]); | ||
return AccessEvent.forKeyAndWeight(key, weight); | ||
}); | ||
} | ||
} |
4 changes: 4 additions & 0 deletions
4
...com/github/benmanes/caffeine/cache/simulator/parser/libcachesim/twitter/package-info.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
@CheckReturnValue | ||
package com.github.benmanes.caffeine.cache.simulator.parser.libcachesim.twitter; | ||
|
||
import com.google.errorprone.annotations.CheckReturnValue; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.