Skip to content

Commit

Permalink
SHC - moved to XXH3
Browse files Browse the repository at this point in the history
  • Loading branch information
NadavKeren committed Nov 1, 2024
1 parent 2f65e91 commit 98c154b
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 2 deletions.
2 changes: 2 additions & 0 deletions gradle/dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ ext {
univocityParsers: '2.9.1',
ycsb: '0.17.0',
xz: '1.9',
hash4j: '0.18.0',
zstd: '1.5.2-3',
]
testVersions = [
Expand Down Expand Up @@ -167,6 +168,7 @@ ext {
transitive = false
},
xz: "org.tukaani:xz:${versions.xz}",
hash4j: "com.dynatrace.hash4j:hash4j:${versions.hash4j}",
zstd: "com.github.luben:zstd-jni:${versions.zstd}",
]
testLibraries = [
Expand Down
1 change: 1 addition & 0 deletions simulator/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ dependencies {
implementation libraries.commonsMath3
implementation libraries.commonsCompress
implementation libraries.univocityParsers
implementation libraries.hash4j

testImplementation testLibraries.testng

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ public SampledHillClimber(Config config) {
stats = new PolicyStats("Sampled " + sampleOrder + " " + mainPipeline.generatePipelineName());
adaptionTimeframe = settings.adaptionMultiplier() * mainPipeline.cacheCapacity();

sampler = new FarmHashSampler(sampleOrder);
// sampler = new FarmHashSampler(sampleOrder); Testing xxHash3 to see if there is performance improvement, need to check if FarmHash allows for different seeds.
sampler = new XXH3Sampler(sampleOrder, settings.randomSeed());
sampledMainCache = new PipelinePolicy(config, sampleOrder);
final int numOfCaches = blockCount * (blockCount - 1);
ghostCaches = new ArrayList<>(numOfCaches);
Expand All @@ -64,7 +65,6 @@ private void createGhostCaches() {
}

ghostCaches.clear();

int idx = 0;
for (int inc = 0; inc < blockCount; ++inc) {
for (int dec = 0; dec < blockCount; ++dec) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.github.benmanes.caffeine.cache.simulator.policy.latency_aware.pipeline;
import com.dynatrace.hash4j.hashing.Hasher64;
import com.dynatrace.hash4j.hashing.XXH3_64;
import com.dynatrace.hash4j.hashing.HashFunnel;

public class XXH3Sampler implements LongSampler{
private HashFunnel<Long> funnel = (o, sink) -> sink.putLong(o);
private long mask;

private Hasher64 hash;
public XXH3Sampler(int order, long seed) {
mask = createMask(order);
hash = XXH3_64.create(seed);
}

@Override
public boolean shouldSample(long key) {
return (hash.hashToLong(key, funnel) & mask) == 0;
}

private static long createMask(int exp) {
long mask = 0;
for (int i = 0; i < exp; ++i) {
mask = mask << 1 | 1;
}

return mask;
}
}

0 comments on commit 98c154b

Please sign in to comment.