Skip to content

Commit

Permalink
add Delete to YCSB Benchmark; change "-r read%" to "-rumd read% upser…
Browse files Browse the repository at this point in the history
…t% rmw% delete%" (#839)
  • Loading branch information
TedHartMS authored May 31, 2023
1 parent 7d5d5ff commit 73fe128
Show file tree
Hide file tree
Showing 6 changed files with 145 additions and 195 deletions.
63 changes: 25 additions & 38 deletions cs/benchmark/ConcurrentDictionaryBenchmark.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.

#pragma warning disable CS0162 // Unreachable code detected -- when switching on YcsbConstants

//#define DASHBOARD

using FASTER.core;
Expand Down Expand Up @@ -30,7 +28,7 @@ internal unsafe class ConcurrentDictionary_YcsbBenchmark
readonly TestLoader testLoader;
readonly int numaStyle;
readonly string distribution;
readonly int readPercent;
readonly int readPercent, upsertPercent, rmwPercent;
readonly Input[] input_;

readonly Key[] init_keys_;
Expand All @@ -50,7 +48,9 @@ internal ConcurrentDictionary_YcsbBenchmark(Key[] i_keys_, Key[] t_keys_, TestLo
txn_keys_ = t_keys_;
numaStyle = testLoader.Options.NumaStyle;
distribution = testLoader.Distribution;
readPercent = testLoader.Options.ReadPercent;
readPercent = testLoader.ReadPercent;
upsertPercent = testLoader.UpsertPercent;
rmwPercent = testLoader.RmwPercent;

#if DASHBOARD
statsWritten = new AutoResetEvent[threadCount];
Expand Down Expand Up @@ -93,6 +93,7 @@ private void RunYcsb(int thread_idx)
Value value = default;
long reads_done = 0;
long writes_done = 0;
long deletes_done = 0;

#if DASHBOARD
var tstart = Stopwatch.GetTimestamp();
Expand All @@ -113,40 +114,27 @@ private void RunYcsb(int thread_idx)

for (long idx = chunk_idx; idx < chunk_idx + YcsbConstants.kChunkSize && !done; ++idx)
{
Op op;
int r = (int)rng.Generate(100);
int r = (int)rng.Generate(100); // rng.Next() is not inclusive of the upper bound so this will be <= 99
if (r < readPercent)
op = Op.Read;
else if (readPercent >= 0)
op = Op.Upsert;
else
op = Op.ReadModifyWrite;

switch (op)
{
case Op.Upsert:
{
store[txn_keys_[idx]] = value;
++writes_done;
break;
}
case Op.Read:
{
if (store.TryGetValue(txn_keys_[idx], out value))
{
++reads_done;
}
break;
}
case Op.ReadModifyWrite:
{
store.AddOrUpdate(txn_keys_[idx], *(Value*)(input_ptr + (idx & 0x7)), (k, v) => new Value { value = v.value + (input_ptr + (idx & 0x7))->value });
++writes_done;
break;
}
default:
throw new InvalidOperationException("Unexpected op: " + op);
if (store.TryGetValue(txn_keys_[idx], out value))
++reads_done;
continue;
}
if (r < upsertPercent)
{
store[txn_keys_[idx]] = value;
++writes_done;
continue;
}
if (r < rmwPercent)
{
store.AddOrUpdate(txn_keys_[idx], *(Value*)(input_ptr + (idx & 0x7)), (k, v) => new Value { value = v.value + (input_ptr + (idx & 0x7))->value });
++writes_done;
continue;
}
store.Remove(txn_keys_[idx], out _);
++deletes_done;
}

#if DASHBOARD
Expand All @@ -168,9 +156,8 @@ private void RunYcsb(int thread_idx)

sw.Stop();

Console.WriteLine("Thread " + thread_idx + " done; " + reads_done + " reads, " +
writes_done + " writes, in " + sw.ElapsedMilliseconds + " ms.");
Interlocked.Add(ref total_ops_done, reads_done + writes_done);
Console.WriteLine($"Thread {thread_idx} done; {reads_done} reads, {writes_done} writes, {deletes_done} deletes in {sw.ElapsedMilliseconds} ms.");
Interlocked.Add(ref total_ops_done, reads_done + writes_done + deletes_done);
}

internal unsafe (double, double) Run(TestLoader testLoader)
Expand Down
116 changes: 48 additions & 68 deletions cs/benchmark/FasterSpanByteYcsbBenchmark.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ internal class FasterSpanByteYcsbBenchmark
readonly TestLoader testLoader;
readonly ManualResetEventSlim waiter = new();
readonly int numaStyle;
readonly int readPercent;
readonly int readPercent, upsertPercent, rmwPercent;
readonly FunctionsSB functions;
readonly Input[] input_;

Expand Down Expand Up @@ -52,7 +52,9 @@ internal FasterSpanByteYcsbBenchmark(KeySpanByte[] i_keys_, KeySpanByte[] t_keys
init_keys_ = i_keys_;
txn_keys_ = t_keys_;
numaStyle = testLoader.Options.NumaStyle;
readPercent = testLoader.Options.ReadPercent;
readPercent = testLoader.ReadPercent;
upsertPercent = testLoader.UpsertPercent;
rmwPercent = testLoader.RmwPercent;
functions = new FunctionsSB();

#if DASHBOARD
Expand Down Expand Up @@ -116,6 +118,7 @@ private void RunYcsbUnsafeContext(int thread_idx)

long reads_done = 0;
long writes_done = 0;
long deletes_done = 0;

#if DASHBOARD
var tstart = Stopwatch.GetTimestamp();
Expand All @@ -142,44 +145,33 @@ private void RunYcsbUnsafeContext(int thread_idx)

for (long idx = chunk_idx; idx < chunk_idx + YcsbConstants.kChunkSize && !done; ++idx)
{
Op op;
int r = (int)rng.Generate(100);
if (r < readPercent)
op = Op.Read;
else if (readPercent >= 0)
op = Op.Upsert;
else
op = Op.ReadModifyWrite;

if (idx % 512 == 0)
{
uContext.Refresh();
uContext.CompletePending(false);
}

switch (op)
int r = (int)rng.Generate(100); // rng.Next() is not inclusive of the upper bound so this will be <= 99
if (r < readPercent)
{
case Op.Upsert:
{
uContext.Upsert(ref SpanByte.Reinterpret(ref txn_keys_[idx]), ref _value, Empty.Default, 1);
++writes_done;
break;
}
case Op.Read:
{
uContext.Read(ref SpanByte.Reinterpret(ref txn_keys_[idx]), ref _input, ref _output, Empty.Default, 1);
++reads_done;
break;
}
case Op.ReadModifyWrite:
{
uContext.RMW(ref SpanByte.Reinterpret(ref txn_keys_[idx]), ref _input, Empty.Default, 1);
++writes_done;
break;
}
default:
throw new InvalidOperationException("Unexpected op: " + op);
uContext.Read(ref SpanByte.Reinterpret(ref txn_keys_[idx]), ref _input, ref _output, Empty.Default, 1);
++reads_done;
continue;
}
if (r < upsertPercent)
{
uContext.Upsert(ref SpanByte.Reinterpret(ref txn_keys_[idx]), ref _value, Empty.Default, 1);
++writes_done;
continue;
}
if (r < rmwPercent)
{
uContext.RMW(ref SpanByte.Reinterpret(ref txn_keys_[idx]), ref _input, Empty.Default, 1);
++writes_done;
continue;
}
uContext.Delete(ref SpanByte.Reinterpret(ref txn_keys_[idx]), Empty.Default, 1);
++deletes_done;
}

#if DASHBOARD
Expand Down Expand Up @@ -214,9 +206,8 @@ private void RunYcsbUnsafeContext(int thread_idx)
statsWritten[thread_idx].Set();
#endif

Console.WriteLine("Thread " + thread_idx + " done; " + reads_done + " reads, " +
writes_done + " writes, in " + sw.ElapsedMilliseconds + " ms.");
Interlocked.Add(ref total_ops_done, reads_done + writes_done);
Console.WriteLine($"Thread {thread_idx} done; {reads_done} reads, {writes_done} writes, {deletes_done} deletes in {sw.ElapsedMilliseconds} ms.");
Interlocked.Add(ref total_ops_done, reads_done + writes_done + deletes_done);
}

private void RunYcsbSafeContext(int thread_idx)
Expand Down Expand Up @@ -244,6 +235,7 @@ private void RunYcsbSafeContext(int thread_idx)

long reads_done = 0;
long writes_done = 0;
long deletes_done = 0;

#if DASHBOARD
var tstart = Stopwatch.GetTimestamp();
Expand All @@ -266,45 +258,34 @@ private void RunYcsbSafeContext(int thread_idx)

for (long idx = chunk_idx; idx < chunk_idx + YcsbConstants.kChunkSize && !done; ++idx)
{
Op op;
int r = (int)rng.Generate(100);
if (r < readPercent)
op = Op.Read;
else if (readPercent >= 0)
op = Op.Upsert;
else
op = Op.ReadModifyWrite;

if (idx % 512 == 0)
{
if (!testLoader.Options.UseSafeContext)
session.Refresh();
session.CompletePending(false);
}

switch (op)
int r = (int)rng.Generate(100); // rng.Next() is not inclusive of the upper bound so this will be <= 99
if (r < readPercent)
{
case Op.Upsert:
{
session.Upsert(ref SpanByte.Reinterpret(ref txn_keys_[idx]), ref _value, Empty.Default, 1);
++writes_done;
break;
}
case Op.Read:
{
session.Read(ref SpanByte.Reinterpret(ref txn_keys_[idx]), ref _input, ref _output, Empty.Default, 1);
++reads_done;
break;
}
case Op.ReadModifyWrite:
{
session.RMW(ref SpanByte.Reinterpret(ref txn_keys_[idx]), ref _input, Empty.Default, 1);
++writes_done;
break;
}
default:
throw new InvalidOperationException("Unexpected op: " + op);
session.Read(ref SpanByte.Reinterpret(ref txn_keys_[idx]), ref _input, ref _output, Empty.Default, 1);
++reads_done;
continue;
}
if (r < upsertPercent)
{
session.Upsert(ref SpanByte.Reinterpret(ref txn_keys_[idx]), ref _value, Empty.Default, 1);
++writes_done;
continue;
}
if (r < rmwPercent)
{
session.RMW(ref SpanByte.Reinterpret(ref txn_keys_[idx]), ref _input, Empty.Default, 1);
++writes_done;
continue;
}
session.Delete(ref SpanByte.Reinterpret(ref txn_keys_[idx]), Empty.Default, 1);
++deletes_done;
}

#if DASHBOARD
Expand Down Expand Up @@ -333,9 +314,8 @@ private void RunYcsbSafeContext(int thread_idx)
statsWritten[thread_idx].Set();
#endif

Console.WriteLine("Thread " + thread_idx + " done; " + reads_done + " reads, " +
writes_done + " writes, in " + sw.ElapsedMilliseconds + " ms.");
Interlocked.Add(ref total_ops_done, reads_done + writes_done);
Console.WriteLine($"Thread {thread_idx} done; {reads_done} reads, {writes_done} writes, {deletes_done} deletes in {sw.ElapsedMilliseconds} ms.");
Interlocked.Add(ref total_ops_done, reads_done + writes_done + deletes_done);
}

internal unsafe (double, double) Run(TestLoader testLoader)
Expand Down
Loading

0 comments on commit 73fe128

Please sign in to comment.