Skip to content

Commit

Permalink
add FASTER.benchmark cmdline options: --sd --sm --noaff --chkptms --d…
Browse files Browse the repository at this point in the history
…umpdist (#485)
  • Loading branch information
TedHartMS authored Jun 8, 2021
1 parent d0a84f6 commit 09445f3
Show file tree
Hide file tree
Showing 7 changed files with 140 additions and 87 deletions.
24 changes: 13 additions & 11 deletions cs/benchmark/ConcurrentDictionaryBenchmark.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ internal class KeyComparer : IEqualityComparer<Key>

internal unsafe class ConcurrentDictionary_YcsbBenchmark
{
readonly TestLoader testLoader;
readonly int numaStyle;
readonly string distribution;
readonly int readPercent;
Expand All @@ -44,6 +45,7 @@ internal unsafe class ConcurrentDictionary_YcsbBenchmark

internal ConcurrentDictionary_YcsbBenchmark(Key[] i_keys_, Key[] t_keys_, TestLoader testLoader)
{
this.testLoader = testLoader;
init_keys_ = i_keys_;
txn_keys_ = t_keys_;
numaStyle = testLoader.Options.NumaStyle;
Expand All @@ -67,7 +69,7 @@ internal ConcurrentDictionary_YcsbBenchmark(Key[] i_keys_, Key[] t_keys_, TestLo
for (int i = 0; i < 8; i++)
input_[i].value = i;

store = new ConcurrentDictionary<Key, Value>(testLoader.Options.ThreadCount, YcsbConstants.kMaxKey, new KeyComparer());
store = new ConcurrentDictionary<Key, Value>(testLoader.Options.ThreadCount, testLoader.MaxKey, new KeyComparer());
}

internal void Dispose()
Expand Down Expand Up @@ -101,9 +103,9 @@ private void RunYcsb(int thread_idx)
while (!done)
{
long chunk_idx = Interlocked.Add(ref idx_, YcsbConstants.kChunkSize) - YcsbConstants.kChunkSize;
while (chunk_idx >= YcsbConstants.kTxnCount)
while (chunk_idx >= testLoader.TxnCount)
{
if (chunk_idx == YcsbConstants.kTxnCount)
if (chunk_idx == testLoader.TxnCount)
idx_ = 0;
chunk_idx = Interlocked.Add(ref idx_, YcsbConstants.kChunkSize) - YcsbConstants.kChunkSize;
}
Expand Down Expand Up @@ -205,7 +207,7 @@ internal unsafe (double, double) Run(TestLoader testLoader)
}
sw.Stop();

double insertsPerSecond = ((double)YcsbConstants.kInitCount / sw.ElapsedMilliseconds) * 1000;
double insertsPerSecond = ((double)testLoader.InitCount / sw.ElapsedMilliseconds) * 1000;
Console.WriteLine(TestStats.GetLoadingTimeLine(insertsPerSecond, sw.ElapsedMilliseconds));

idx_ = 0;
Expand All @@ -227,7 +229,7 @@ internal unsafe (double, double) Run(TestLoader testLoader)
Stopwatch swatch = new Stopwatch();
swatch.Start();

if (YcsbConstants.kPeriodicCheckpointMilliseconds <= 0)
if (testLoader.Options.PeriodicCheckpointMilliseconds <= 0)
{
Thread.Sleep(TimeSpan.FromSeconds(testLoader.Options.RunSeconds));
}
Expand All @@ -236,8 +238,8 @@ internal unsafe (double, double) Run(TestLoader testLoader)
double runSeconds = 0;
while (runSeconds < testLoader.Options.RunSeconds)
{
Thread.Sleep(TimeSpan.FromMilliseconds(YcsbConstants.kPeriodicCheckpointMilliseconds));
runSeconds += YcsbConstants.kPeriodicCheckpointMilliseconds / 1000;
Thread.Sleep(TimeSpan.FromMilliseconds(testLoader.Options.PeriodicCheckpointMilliseconds));
runSeconds += testLoader.Options.PeriodicCheckpointMilliseconds / 1000;
}
}

Expand Down Expand Up @@ -282,7 +284,7 @@ private void SetupYcsb(int thread_idx)
Value value = default;

for (long chunk_idx = Interlocked.Add(ref idx_, YcsbConstants.kChunkSize) - YcsbConstants.kChunkSize;
chunk_idx < YcsbConstants.kInitCount;
chunk_idx < testLoader.InitCount;
chunk_idx = Interlocked.Add(ref idx_, YcsbConstants.kChunkSize) - YcsbConstants.kChunkSize)
{
for (long idx = chunk_idx; idx < chunk_idx + YcsbConstants.kChunkSize; ++idx)
Expand Down Expand Up @@ -381,10 +383,10 @@ void DoContinuousMeasurements()

#region Load Data

internal static void CreateKeyVectors(out Key[] i_keys, out Key[] t_keys)
internal static void CreateKeyVectors(TestLoader testLoader, out Key[] i_keys, out Key[] t_keys)
{
i_keys = new Key[YcsbConstants.kInitCount];
t_keys = new Key[YcsbConstants.kTxnCount];
i_keys = new Key[testLoader.InitCount];
t_keys = new Key[testLoader.TxnCount];
}
internal class KeySetter : IKeySetter<Key>
{
Expand Down
45 changes: 25 additions & 20 deletions cs/benchmark/FasterSpanByteYcsbBenchmark.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@ namespace FASTER.benchmark
internal class FasterSpanByteYcsbBenchmark
{
// Ensure sizes are aligned to chunk sizes
const long kInitCount = YcsbConstants.kChunkSize * (YcsbConstants.kInitCount / YcsbConstants.kChunkSize);
const long kTxnCount = YcsbConstants.kChunkSize * (YcsbConstants.kTxnCount / YcsbConstants.kChunkSize);
static long InitCount;
static long TxnCount;

readonly TestLoader testLoader;
readonly ManualResetEventSlim waiter = new ManualResetEventSlim();
readonly int numaStyle;
readonly int readPercent;
Expand Down Expand Up @@ -46,6 +47,7 @@ internal FasterSpanByteYcsbBenchmark(KeySpanByte[] i_keys_, KeySpanByte[] t_keys
(testLoader.Options.NumaStyle == 1 && testLoader.Options.ThreadCount <= numGrps * (numProcs - 1)))
Native32.AffinitizeThreadRoundRobin(numProcs - 1);

this.testLoader = testLoader;
init_keys_ = i_keys_;
txn_keys_ = t_keys_;
numaStyle = testLoader.Options.NumaStyle;
Expand Down Expand Up @@ -73,13 +75,13 @@ internal FasterSpanByteYcsbBenchmark(KeySpanByte[] i_keys_, KeySpanByte[] t_keys

device = Devices.CreateLogDevice(TestLoader.DevicePath, preallocateFile: true, deleteOnClose: true);

if (YcsbConstants.kSmallMemoryLog)
if (testLoader.Options.UseSmallMemoryLog)
store = new FasterKV<SpanByte, SpanByte>
(YcsbConstants.kMaxKey / 2, new LogSettings { LogDevice = device, PreallocateLog = true, PageSizeBits = 22, SegmentSizeBits = 26, MemorySizeBits = 26 },
(testLoader.MaxKey / 2, new LogSettings { LogDevice = device, PreallocateLog = true, PageSizeBits = 22, SegmentSizeBits = 26, MemorySizeBits = 26 },
new CheckpointSettings { CheckPointType = CheckpointType.Snapshot, CheckpointDir = testLoader.BackupPath });
else
store = new FasterKV<SpanByte, SpanByte>
(YcsbConstants.kMaxKey / 2, new LogSettings { LogDevice = device, PreallocateLog = true, MemorySizeBits = 35 },
(testLoader.MaxKey / 2, new LogSettings { LogDevice = device, PreallocateLog = true, MemorySizeBits = 35 },
new CheckpointSettings { CheckPointType = CheckpointType.Snapshot, CheckpointDir = testLoader.BackupPath });
}

Expand Down Expand Up @@ -121,14 +123,14 @@ private void RunYcsb(int thread_idx)
int count = 0;
#endif

var session = store.For(functions).NewSession<FunctionsSB>(null, YcsbConstants.kAffinitizedSession);
var session = store.For(functions).NewSession<FunctionsSB>(null, !testLoader.Options.NoThreadAffinity);

while (!done)
{
long chunk_idx = Interlocked.Add(ref idx_, YcsbConstants.kChunkSize) - YcsbConstants.kChunkSize;
while (chunk_idx >= kTxnCount)
while (chunk_idx >= TxnCount)
{
if (chunk_idx == kTxnCount)
if (chunk_idx == TxnCount)
idx_ = 0;
chunk_idx = Interlocked.Add(ref idx_, YcsbConstants.kChunkSize) - YcsbConstants.kChunkSize;
}
Expand All @@ -146,7 +148,7 @@ private void RunYcsb(int thread_idx)

if (idx % 512 == 0)
{
if (YcsbConstants.kAffinitizedSession)
if (!testLoader.Options.NoThreadAffinity)
session.Refresh();
session.CompletePending(false);
}
Expand Down Expand Up @@ -246,7 +248,7 @@ internal unsafe (double, double) Run(TestLoader testLoader)

elapsedMs = sw.ElapsedMilliseconds;
}
double insertsPerSecond = elapsedMs == 0 ? 0 : ((double)kInitCount / elapsedMs) * 1000;
double insertsPerSecond = elapsedMs == 0 ? 0 : ((double)InitCount / elapsedMs) * 1000;
Console.WriteLine(TestStats.GetLoadingTimeLine(insertsPerSecond, elapsedMs));
Console.WriteLine(TestStats.GetAddressesLine(AddressLineNum.Before, store.Log.BeginAddress, store.Log.HeadAddress, store.Log.ReadOnlyAddress, store.Log.TailAddress));

Expand All @@ -258,11 +260,11 @@ internal unsafe (double, double) Run(TestLoader testLoader)

idx_ = 0;

if (YcsbConstants.kDumpDistribution)
if (testLoader.Options.DumpDistribution)
Console.WriteLine(store.DumpDistribution());

// Ensure first fold-over checkpoint is fast
if (YcsbConstants.kPeriodicCheckpointMilliseconds > 0 && YcsbConstants.kPeriodicCheckpointType == CheckpointType.FoldOver)
if (testLoader.Options.PeriodicCheckpointMilliseconds > 0 && testLoader.Options.PeriodicCheckpointType == CheckpointType.FoldOver)
store.Log.ShiftReadOnlyAddress(store.Log.TailAddress, true);

Console.WriteLine("Executing experiment.");
Expand All @@ -283,7 +285,7 @@ internal unsafe (double, double) Run(TestLoader testLoader)
Stopwatch swatch = new Stopwatch();
swatch.Start();

if (YcsbConstants.kPeriodicCheckpointMilliseconds <= 0)
if (testLoader.Options.PeriodicCheckpointMilliseconds <= 0)
{
Thread.Sleep(TimeSpan.FromSeconds(testLoader.Options.RunSeconds));
}
Expand All @@ -292,10 +294,10 @@ internal unsafe (double, double) Run(TestLoader testLoader)
var checkpointTaken = 0;
while (swatch.ElapsedMilliseconds < 1000 * testLoader.Options.RunSeconds)
{
if (checkpointTaken < swatch.ElapsedMilliseconds / YcsbConstants.kPeriodicCheckpointMilliseconds)
if (checkpointTaken < swatch.ElapsedMilliseconds / testLoader.Options.PeriodicCheckpointMilliseconds)
{
long start = swatch.ElapsedTicks;
if (store.TakeHybridLogCheckpoint(out _, YcsbConstants.kPeriodicCheckpointType, YcsbConstants.kPeriodicCheckpointTryIncremental))
if (store.TakeHybridLogCheckpoint(out _, testLoader.Options.PeriodicCheckpointType, testLoader.Options.PeriodicCheckpointTryIncremental))
{
store.CompleteCheckpointAsync().GetAwaiter().GetResult();
var timeTaken = (swatch.ElapsedTicks - start) / TimeSpan.TicksPerMillisecond;
Expand Down Expand Up @@ -339,7 +341,7 @@ private void SetupYcsb(int thread_idx)

waiter.Wait();

var session = store.For(functions).NewSession<FunctionsSB>(null, YcsbConstants.kAffinitizedSession);
var session = store.For(functions).NewSession<FunctionsSB>(null, !testLoader.Options.NoThreadAffinity);

#if DASHBOARD
var tstart = Stopwatch.GetTimestamp();
Expand All @@ -352,7 +354,7 @@ private void SetupYcsb(int thread_idx)
ref SpanByte _value = ref SpanByte.Reinterpret(value);

for (long chunk_idx = Interlocked.Add(ref idx_, YcsbConstants.kChunkSize) - YcsbConstants.kChunkSize;
chunk_idx < kInitCount;
chunk_idx < InitCount;
chunk_idx = Interlocked.Add(ref idx_, YcsbConstants.kChunkSize) - YcsbConstants.kChunkSize)
{
for (long idx = chunk_idx; idx < chunk_idx + YcsbConstants.kChunkSize; ++idx)
Expand Down Expand Up @@ -455,10 +457,13 @@ void DoContinuousMeasurements()

#region Load Data

internal static void CreateKeyVectors(out KeySpanByte[] i_keys, out KeySpanByte[] t_keys)
internal static void CreateKeyVectors(TestLoader testLoader, out KeySpanByte[] i_keys, out KeySpanByte[] t_keys)
{
i_keys = new KeySpanByte[kInitCount];
t_keys = new KeySpanByte[kTxnCount];
InitCount = YcsbConstants.kChunkSize * (testLoader.InitCount / YcsbConstants.kChunkSize);
TxnCount = YcsbConstants.kChunkSize * (testLoader.TxnCount / YcsbConstants.kChunkSize);

i_keys = new KeySpanByte[InitCount];
t_keys = new KeySpanByte[TxnCount];
}

internal class KeySetter : IKeySetter<KeySpanByte>
Expand Down
Loading

0 comments on commit 09445f3

Please sign in to comment.