internal static void CreateKeyVectors(TestLoader testLoader, out Key[] i_keys, out Key[] t_keys) { InitCount = YcsbConstants.kChunkSize * (testLoader.InitCount / YcsbConstants.kChunkSize); TxnCount = YcsbConstants.kChunkSize * (testLoader.TxnCount / YcsbConstants.kChunkSize); i_keys = new Key[InitCount]; t_keys = new Key[TxnCount]; }
internal FASTER_YcsbBenchmark(Key[] i_keys_, Key[] t_keys_, TestLoader testLoader) { // Pin loading thread if it is not used for checkpointing if (YcsbConstants.kPeriodicCheckpointMilliseconds <= 0) { Native32.AffinitizeThreadShardedNuma(0, 2); } init_keys_ = i_keys_; txn_keys_ = t_keys_; numaStyle = testLoader.Options.NumaStyle; readPercent = testLoader.Options.ReadPercent; functions = new Functions(); #if DASHBOARD statsWritten = new AutoResetEvent[threadCount]; for (int i = 0; i < threadCount; i++) { statsWritten[i] = new AutoResetEvent(false); } threadThroughput = new double[threadCount]; threadAverageLatency = new double[threadCount]; threadMaximumLatency = new double[threadCount]; threadProgress = new long[threadCount]; writeStats = new bool[threadCount]; freq = Stopwatch.Frequency; #endif input_ = new Input[8]; for (int i = 0; i < 8; i++) { input_[i].value = i; } device = Devices.CreateLogDevice(TestLoader.DevicePath, preallocateFile: true); if (YcsbConstants.kSmallMemoryLog) { store = new FasterKV <Key, Value> (YcsbConstants.kMaxKey / 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 <Key, Value> (YcsbConstants.kMaxKey / 2, new LogSettings { LogDevice = device, PreallocateLog = true }, new CheckpointSettings { CheckPointType = CheckpointType.Snapshot, CheckpointDir = testLoader.BackupPath }); } }
internal unsafe (double, double) Run(TestLoader testLoader) { #if DASHBOARD var dash = new Thread(() => DoContinuousMeasurements()); dash.Start(); #endif Thread[] workers = new Thread[testLoader.Options.ThreadCount]; Console.WriteLine("Executing setup."); var storeWasRecovered = testLoader.MaybeRecoverStore(store); long elapsedMs = 0; if (!storeWasRecovered) { // Setup the store for the YCSB benchmark. Console.WriteLine("Loading FasterKV from data"); for (int idx = 0; idx < testLoader.Options.ThreadCount; ++idx) { int x = idx; workers[idx] = new Thread(() => SetupYcsb(x)); } foreach (Thread worker in workers) { worker.Start(); } waiter.Set(); var sw = Stopwatch.StartNew(); foreach (Thread worker in workers) { worker.Join(); } sw.Stop(); elapsedMs = sw.ElapsedMilliseconds; waiter.Reset(); } double insertsPerSecond = elapsedMs == 0 ? 0 : ((double)kInitCount / 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)); if (!storeWasRecovered) { testLoader.MaybeCheckpointStore(store); } // Uncomment below to dispose log from memory, use for 100% read workloads only // store.Log.DisposeFromMemory(); idx_ = 0; if (YcsbConstants.kDumpDistribution) { Console.WriteLine(store.DumpDistribution()); } // Ensure first checkpoint is fast if (YcsbConstants.kPeriodicCheckpointMilliseconds > 0) { store.Log.ShiftReadOnlyAddress(store.Log.TailAddress, true); } Console.WriteLine("Executing experiment."); // Run the experiment. for (int idx = 0; idx < testLoader.Options.ThreadCount; ++idx) { int x = idx; workers[idx] = new Thread(() => RunYcsb(x)); } // Start threads. foreach (Thread worker in workers) { worker.Start(); } waiter.Set(); Stopwatch swatch = new Stopwatch(); swatch.Start(); if (YcsbConstants.kPeriodicCheckpointMilliseconds <= 0) { Thread.Sleep(TimeSpan.FromSeconds(testLoader.Options.RunSeconds)); } else { var checkpointTaken = 0; while (swatch.ElapsedMilliseconds < 1000 * testLoader.Options.RunSeconds) { if (checkpointTaken < swatch.ElapsedMilliseconds / YcsbConstants.kPeriodicCheckpointMilliseconds) { if (store.TakeHybridLogCheckpoint(out _)) { checkpointTaken++; } } } Console.WriteLine($"Checkpoint taken {checkpointTaken}"); } swatch.Stop(); done = true; foreach (Thread worker in workers) { worker.Join(); } waiter.Reset(); #if DASHBOARD dash.Join(); #endif double seconds = swatch.ElapsedMilliseconds / 1000.0; Console.WriteLine(TestStats.GetAddressesLine(AddressLineNum.After, store.Log.BeginAddress, store.Log.HeadAddress, store.Log.ReadOnlyAddress, store.Log.TailAddress)); double opsPerSecond = total_ops_done / seconds; Console.WriteLine(TestStats.GetTotalOpsString(total_ops_done, seconds)); Console.WriteLine(TestStats.GetStatsLine(StatsLineNum.Iteration, YcsbConstants.OpsPerSec, opsPerSecond)); return(insertsPerSecond, opsPerSecond); }
internal FasterSpanByteYcsbBenchmark(KeySpanByte[] i_keys_, KeySpanByte[] t_keys_, TestLoader testLoader) { // Affinize main thread to last core on first socket if not used by experiment var(numGrps, numProcs) = Native32.GetNumGroupsProcsPerGroup(); if ((testLoader.Options.NumaStyle == 0 && testLoader.Options.ThreadCount <= (numProcs - 1)) || (testLoader.Options.NumaStyle == 1 && testLoader.Options.ThreadCount <= numGrps * (numProcs - 1))) { Native32.AffinitizeThreadRoundRobin(numProcs - 1); } init_keys_ = i_keys_; txn_keys_ = t_keys_; numaStyle = testLoader.Options.NumaStyle; readPercent = testLoader.Options.ReadPercent; var lockImpl = testLoader.LockImpl; functions = new FunctionsSB(lockImpl != LockImpl.None); #if DASHBOARD statsWritten = new AutoResetEvent[threadCount]; for (int i = 0; i < threadCount; i++) { statsWritten[i] = new AutoResetEvent(false); } threadThroughput = new double[threadCount]; threadAverageLatency = new double[threadCount]; threadMaximumLatency = new double[threadCount]; threadProgress = new long[threadCount]; writeStats = new bool[threadCount]; freq = Stopwatch.Frequency; #endif input_ = new Input[8]; for (int i = 0; i < 8; i++) { input_[i].value = i; } device = Devices.CreateLogDevice(TestLoader.DevicePath, preallocateFile: true, deleteOnClose: true); if (YcsbConstants.kSmallMemoryLog) { store = new FasterKV <SpanByte, SpanByte> (YcsbConstants.kMaxKey / 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 }, new CheckpointSettings { CheckPointType = CheckpointType.Snapshot, CheckpointDir = testLoader.BackupPath }); } }
internal static void CreateKeyVectors(TestLoader testLoader, out Key[] i_keys, out Key[] t_keys) { i_keys = new Key[testLoader.InitCount]; t_keys = new Key[testLoader.TxnCount]; }
internal unsafe (double, double) Run(TestLoader testLoader) { RandomGenerator rng = new RandomGenerator(); GCHandle handle = GCHandle.Alloc(input_, GCHandleType.Pinned); input_ptr = (Input *)handle.AddrOfPinnedObject(); #if DASHBOARD var dash = new Thread(() => DoContinuousMeasurements()); dash.Start(); #endif Thread[] workers = new Thread[testLoader.Options.ThreadCount]; Console.WriteLine("Executing setup."); // Setup the store for the YCSB benchmark. for (int idx = 0; idx < testLoader.Options.ThreadCount; ++idx) { int x = idx; workers[idx] = new Thread(() => SetupYcsb(x)); } Stopwatch sw = new Stopwatch(); sw.Start(); // Start threads. foreach (Thread worker in workers) { worker.Start(); } foreach (Thread worker in workers) { worker.Join(); } sw.Stop(); double insertsPerSecond = ((double)testLoader.InitCount / sw.ElapsedMilliseconds) * 1000; Console.WriteLine(TestStats.GetLoadingTimeLine(insertsPerSecond, sw.ElapsedMilliseconds)); idx_ = 0; Console.WriteLine("Executing experiment."); // Run the experiment. for (int idx = 0; idx < testLoader.Options.ThreadCount; ++idx) { int x = idx; workers[idx] = new Thread(() => RunYcsb(x)); } // Start threads. foreach (Thread worker in workers) { worker.Start(); } Stopwatch swatch = new Stopwatch(); swatch.Start(); if (testLoader.Options.PeriodicCheckpointMilliseconds <= 0) { Thread.Sleep(TimeSpan.FromSeconds(testLoader.Options.RunSeconds)); } else { double runSeconds = 0; while (runSeconds < testLoader.Options.RunSeconds) { Thread.Sleep(TimeSpan.FromMilliseconds(testLoader.Options.PeriodicCheckpointMilliseconds)); runSeconds += testLoader.Options.PeriodicCheckpointMilliseconds / 1000; } } swatch.Stop(); done = true; foreach (Thread worker in workers) { worker.Join(); } #if DASHBOARD dash.Abort(); #endif handle.Free(); input_ptr = null; double seconds = swatch.ElapsedMilliseconds / 1000.0; double opsPerSecond = total_ops_done / seconds; Console.WriteLine(TestStats.GetTotalOpsString(total_ops_done, seconds)); Console.WriteLine(TestStats.GetStatsLine(StatsLineNum.Iteration, YcsbConstants.OpsPerSec, opsPerSecond)); return(insertsPerSecond, opsPerSecond); }
const int kTrimResultCount = 3; // Use some high value like int.MaxValue to disable public static void Main(string[] args) { var testLoader = new TestLoader(); if (!testLoader.Parse(args)) { return; } var testStats = new TestStats(testLoader.Options); testLoader.LoadData(); var options = testLoader.Options; // shortcut for (var iter = 0; iter < options.IterationCount; ++iter) { Console.WriteLine(); if (options.IterationCount > 1) { Console.WriteLine($"Iteration {iter + 1} of {options.IterationCount}"); } switch (testLoader.BenchmarkType) { case BenchmarkType.Ycsb: var yTest = new FASTER_YcsbBenchmark(testLoader.init_keys, testLoader.txn_keys, testLoader); testStats.AddResult(yTest.Run(testLoader)); yTest.Dispose(); break; case BenchmarkType.SpanByte: var sTest = new FasterSpanByteYcsbBenchmark(testLoader.init_span_keys, testLoader.txn_span_keys, testLoader); testStats.AddResult(sTest.Run(testLoader)); sTest.Dispose(); break; case BenchmarkType.ConcurrentDictionaryYcsb: var cTest = new ConcurrentDictionary_YcsbBenchmark(testLoader.init_keys, testLoader.txn_keys, testLoader); testStats.AddResult(cTest.Run(testLoader)); cTest.Dispose(); break; default: throw new ApplicationException("Unknown benchmark type"); } if (options.IterationCount > 1) { testStats.ShowAllStats(AggregateType.Running); if (iter < options.IterationCount - 1) { GC.Collect(); GC.WaitForFullGCComplete(); Thread.Sleep(1000); } } } Console.WriteLine(); testStats.ShowAllStats(AggregateType.FinalFull); if (options.IterationCount >= kTrimResultCount) { testStats.ShowTrimmedStats(); } }