コード例 #1
0
        private void SetupYcsb(int thread_idx)
        {
            if (numaStyle == 0)
            {
                Native32.AffinitizeThreadRoundRobin((uint)thread_idx);
            }
            else
            {
                Native32.AffinitizeThreadShardedNuma((uint)thread_idx, 2); // assuming two NUMA sockets
            }
            waiter.Wait();

            var session = store.For(functions).NewSession <Functions>(null, YcsbConstants.kAffinitizedSession);

#if DASHBOARD
            var tstart           = Stopwatch.GetTimestamp();
            var tstop1           = tstart;
            var lastWrittenValue = 0;
            int count            = 0;
#endif

            Value value = default;

            for (long chunk_idx = Interlocked.Add(ref idx_, YcsbConstants.kChunkSize) - YcsbConstants.kChunkSize;
                 chunk_idx < kInitCount;
                 chunk_idx = Interlocked.Add(ref idx_, YcsbConstants.kChunkSize) - YcsbConstants.kChunkSize)
            {
                for (long idx = chunk_idx; idx < chunk_idx + YcsbConstants.kChunkSize; ++idx)
                {
                    if (idx % 256 == 0)
                    {
                        session.Refresh();

                        if (idx % 65536 == 0)
                        {
                            session.CompletePending(false);
                        }
                    }

                    session.Upsert(ref init_keys_[idx], ref value, Empty.Default, 1);
                }
#if DASHBOARD
                count += (int)kChunkSize;

                //Check if stats collector is requesting for statistics
                if (writeStats[thread_idx])
                {
                    var tstart1 = tstop1;
                    tstop1 = Stopwatch.GetTimestamp();
                    threadThroughput[thread_idx] = (count - lastWrittenValue) / ((tstop1 - tstart1) / freq);
                    lastWrittenValue             = count;
                    writeStats[thread_idx]       = false;
                    statsWritten[thread_idx].Set();
                }
#endif
            }

            session.CompletePending(true);
            session.Dispose();
        }
コード例 #2
0
        private void SetupYcsb(int thread_idx)
        {
            if (numaStyle == 0)
            {
                Native32.AffinitizeThreadRoundRobin((uint)thread_idx);
            }
            else
            {
                Native32.AffinitizeThreadShardedNuma((uint)thread_idx, 2); // assuming two NUMA sockets
            }
            store.StartSession();

#if DASHBOARD
            var tstart           = Stopwatch.GetTimestamp();
            var tstop1           = tstart;
            var lastWrittenValue = 0;
            int count            = 0;
#endif

            Value value = default(Value);

            for (long chunk_idx = Interlocked.Add(ref idx_, kChunkSize) - kChunkSize;
                 chunk_idx < kInitCount;
                 chunk_idx = Interlocked.Add(ref idx_, kChunkSize) - kChunkSize)
            {
                for (long idx = chunk_idx; idx < chunk_idx + kChunkSize; ++idx)
                {
                    if (idx % 256 == 0)
                    {
                        store.Refresh();

                        if (idx % 65536 == 0)
                        {
                            store.CompletePending(false);
                        }
                    }

                    Key key = init_keys_[idx];
                    store.Upsert(&key, &value, null, 1);
                }
#if DASHBOARD
                count += (int)kChunkSize;

                //Check if stats collector is requesting for statistics
                if (writeStats[thread_idx])
                {
                    var tstart1 = tstop1;
                    tstop1 = Stopwatch.GetTimestamp();
                    threadThroughput[thread_idx] = (count - lastWrittenValue) / ((tstop1 - tstart1) / freq);
                    lastWrittenValue             = count;
                    writeStats[thread_idx]       = false;
                    statsWritten[thread_idx].Set();
                }
#endif
            }


            store.CompletePending(true);
            store.StopSession();
        }
コード例 #3
0
        internal FasterSpanByteYcsbBenchmark(KeySpanByte[] i_keys_, KeySpanByte[] 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;
            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);

            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
                });
            }
        }
コード例 #4
0
        public FASTER_YcsbBenchmark(int threadCount_, int numaStyle_, string distribution_, int readPercent_, int backupOptions_)
        {
            // Pin loading thread if it is not used for checkpointing
            if (kPeriodicCheckpointMilliseconds <= 0)
            {
                Native32.AffinitizeThreadShardedNuma(0, 2);
            }

            threadCount     = threadCount_;
            numaStyle       = numaStyle_;
            distribution    = distribution_;
            readPercent     = readPercent_;
            this.backupMode = (BackupMode)backupOptions_;

#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

            var path = "D:\\data\\FasterYcsbBenchmark\\";
            device = Devices.CreateLogDevice(path + "hlog", preallocateFile: true, useIoCompletionPort: false);

            // Increase throttle limit for higher concurrency runs
            if (threadCount > 8)
            {
                device.ThrottleLimit *= 2;
            }

            if (kSmallMemoryLog)
            {
                store = new FasterKV <Key, Value>
                            (kMaxKey / 2, new LogSettings {
                    LogDevice = device, PreallocateLog = true, PageSizeBits = 22, SegmentSizeBits = 26, MemorySizeBits = 26
                }, new CheckpointSettings {
                    CheckPointType = CheckpointType.FoldOver, CheckpointDir = path
                });
            }
            else
            {
                store = new FasterKV <Key, Value>
                            (kMaxKey / 2, new LogSettings {
                    LogDevice = device, PreallocateLog = true
                }, new CheckpointSettings {
                    CheckPointType = CheckpointType.FoldOver, CheckpointDir = path
                });
            }
        }
コード例 #5
0
        private void SetupYcsb(int thread_idx)
        {
            if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
            {
                if (numaStyle == 0)
                {
                    Native32.AffinitizeThreadRoundRobin((uint)thread_idx);
                }
                else
                {
                    Native32.AffinitizeThreadShardedNuma((uint)thread_idx, 2); // assuming two NUMA sockets
                }
            }
#if DASHBOARD
            var tstart           = Stopwatch.GetTimestamp();
            var tstop1           = tstart;
            var lastWrittenValue = 0;
            int count            = 0;
#endif

            Value value = default;

            for (long chunk_idx = Interlocked.Add(ref idx_, YcsbConstants.kChunkSize) - YcsbConstants.kChunkSize;
                 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)
                {
                    Key key = init_keys_[idx];
                    store[key] = value;
                }
#if DASHBOARD
                count += (int)kChunkSize;

                //Check if stats collector is requesting for statistics
                if (writeStats[thread_idx])
                {
                    var tstart1 = tstop1;
                    tstop1 = Stopwatch.GetTimestamp();
                    threadThroughput[thread_idx] = (count - lastWrittenValue) / ((tstop1 - tstart1) / freq);
                    lastWrittenValue             = count;
                    writeStats[thread_idx]       = false;
                    statsWritten[thread_idx].Set();
                }
#endif
            }
        }
コード例 #6
0
        private void RunYcsb(int thread_idx)
        {
            RandomGenerator rng = new RandomGenerator((uint)(1 + thread_idx));

            if (numaStyle == 0)
            {
                Native32.AffinitizeThreadRoundRobin((uint)thread_idx);
            }
            else
            {
                Native32.AffinitizeThreadShardedNuma((uint)thread_idx, 2); // assuming two NUMA sockets
            }
            Stopwatch sw = new Stopwatch();

            sw.Start();


            Span <byte> value  = stackalloc byte[kValueSize];
            Span <byte> input  = stackalloc byte[kValueSize];
            Span <byte> output = stackalloc byte[kValueSize];

            ref SpanByte      _value  = ref SpanByte.Reinterpret(value);
コード例 #7
0
        private void RunYcsb(int thread_idx)
        {
            RandomGenerator rng = new RandomGenerator((uint)(1 + thread_idx));

            if (numaStyle == 0)
            {
                Native32.AffinitizeThreadRoundRobin((uint)thread_idx);
            }
            else
            {
                Native32.AffinitizeThreadShardedNuma((uint)thread_idx, 2); // assuming two NUMA sockets
            }
            Stopwatch sw = new Stopwatch();

            sw.Start();


            Value  value  = default;
            Input  input  = default;
            Output output = default;

            long reads_done  = 0;
            long writes_done = 0;

#if DASHBOARD
            var tstart           = Stopwatch.GetTimestamp();
            var tstop1           = tstart;
            var lastWrittenValue = 0;
            int count            = 0;
#endif

            var session = store.For(functions).NewSession <Functions>(null, kAffinitizedSession);

            while (!done)
            {
                long chunk_idx = Interlocked.Add(ref idx_, kChunkSize) - kChunkSize;
                while (chunk_idx >= kTxnCount)
                {
                    if (chunk_idx == kTxnCount)
                    {
                        idx_ = 0;
                    }
                    chunk_idx = Interlocked.Add(ref idx_, kChunkSize) - kChunkSize;
                }

                for (long idx = chunk_idx; idx < chunk_idx + 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 (kAffinitizedSession)
                        {
                            session.Refresh();
                        }
                        session.CompletePending(false);
                    }

                    switch (op)
                    {
                    case Op.Upsert:
                    {
                        session.Upsert(ref txn_keys_[idx], ref value, Empty.Default, 1);
                        ++writes_done;
                        break;
                    }

                    case Op.Read:
                    {
                        session.Read(ref txn_keys_[idx], ref input, ref output, Empty.Default, 1);
                        ++reads_done;
                        break;
                    }

                    case Op.ReadModifyWrite:
                    {
                        session.RMW(ref txn_keys_[idx], ref input_[idx & 0x7], Empty.Default, 1);
                        ++writes_done;
                        break;
                    }

                    default:
                        throw new InvalidOperationException("Unexpected op: " + op);
                    }
                }

#if DASHBOARD
                count += (int)kChunkSize;

                //Check if stats collector is requesting for statistics
                if (writeStats[thread_idx])
                {
                    var tstart1 = tstop1;
                    tstop1 = Stopwatch.GetTimestamp();
                    threadProgress[thread_idx]   = count;
                    threadThroughput[thread_idx] = (count - lastWrittenValue) / ((tstop1 - tstart1) / freq);
                    lastWrittenValue             = count;
                    writeStats[thread_idx]       = false;
                    statsWritten[thread_idx].Set();
                }
#endif
            }

            session.CompletePending(true);
            session.Dispose();

            sw.Stop();

#if DASHBOARD
            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);
        }
コード例 #8
0
ファイル: FasterYcsbBenchmark.cs プロジェクト: wjdz99/FASTER
        public unsafe void Run()
        {
            Native32.AffinitizeThreadShardedNuma((uint)0, 2);

            RandomGenerator rng = new RandomGenerator();

            LoadData();

            input_ = new Input[8];
            for (int i = 0; i < 8; i++)
            {
                input_[i].value = i;
            }

#if DASHBOARD
            var dash = new Thread(() => DoContinuousMeasurements());
            dash.Start();
#endif

            Thread[] workers = new Thread[threadCount];

            Console.WriteLine("Executing setup.");

            Stopwatch sw = new Stopwatch();
            if (!kRecoverStoreContents)
            {
                // Setup the store for the YCSB benchmark.
                for (int idx = 0; idx < threadCount; ++idx)
                {
                    int x = idx;
                    workers[idx] = new Thread(() => SetupYcsb(x));
                }

                sw.Start();
                // Start threads.
                foreach (Thread worker in workers)
                {
                    worker.Start();
                }
                foreach (Thread worker in workers)
                {
                    worker.Join();
                }
                sw.Stop();
            }
            else
            {
                sw.Start();
                store.Recover();
                sw.Stop();
            }
            Console.WriteLine("Loading time: {0}ms", sw.ElapsedMilliseconds);



            long startTailAddress = store.Log.TailAddress;
            Console.WriteLine("Start tail address = " + startTailAddress);

            if (kCheckpointStoreContents)
            {
                store.TakeFullCheckpoint(out _);
                store.CompleteCheckpointAsync().GetAwaiter().GetResult();
                Console.WriteLine("Completed checkpoint");
            }

            store.Log.DisposeFromMemory();

            idx_ = 0;

            if (kDumpDistribution)
            {
                Console.WriteLine(store.DumpDistribution());
            }

            Console.WriteLine("Executing experiment.");

            // Run the experiment.
            for (int idx = 0; idx < 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 (kCheckpointSeconds <= 0)
            {
                Thread.Sleep(TimeSpan.FromSeconds(kRunSeconds));
            }
            else
            {
                int runSeconds = 0;
                while (runSeconds < kRunSeconds)
                {
                    Thread.Sleep(TimeSpan.FromSeconds(kCheckpointSeconds));
                    store.TakeFullCheckpoint(out Guid token);
                    runSeconds += kCheckpointSeconds;
                }
            }

            swatch.Stop();

            done = true;

            foreach (Thread worker in workers)
            {
                worker.Join();
            }

#if DASHBOARD
            dash.Abort();
#endif

            double seconds        = swatch.ElapsedMilliseconds / 1000.0;
            long   endTailAddress = store.Log.TailAddress;
            Console.WriteLine("End tail address = " + endTailAddress);

            Console.WriteLine("Total " + total_ops_done + " ops done " + " in " + seconds + " secs.");
            Console.WriteLine("##, " + distribution + ", " + numaStyle + ", " + readPercent + ", "
                              + threadCount + ", " + total_ops_done / seconds + ", "
                              + (endTailAddress - startTailAddress));
            device.Close();
        }
コード例 #9
0
        private void RunYcsb(int thread_idx)
        {
            RandomGenerator rng = new RandomGenerator((uint)(1 + thread_idx));

            if (numaStyle == 0)
            {
                Native32.AffinitizeThreadRoundRobin((uint)thread_idx);
            }
            else
            {
                Native32.AffinitizeThreadShardedNuma((uint)thread_idx, 2); // assuming two NUMA sockets
            }
            Stopwatch sw = new Stopwatch();

            sw.Start();

            Value value       = default;
            long  reads_done  = 0;
            long  writes_done = 0;

#if DASHBOARD
            var tstart           = Stopwatch.GetTimestamp();
            var tstop1           = tstart;
            var lastWrittenValue = 0;
            int count            = 0;
#endif

            while (!done)
            {
                long chunk_idx = Interlocked.Add(ref idx_, YcsbConstants.kChunkSize) - YcsbConstants.kChunkSize;
                while (chunk_idx >= testLoader.TxnCount)
                {
                    if (chunk_idx == testLoader.TxnCount)
                    {
                        idx_ = 0;
                    }
                    chunk_idx = Interlocked.Add(ref idx_, YcsbConstants.kChunkSize) - YcsbConstants.kChunkSize;
                }

                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;
                    }

                    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 DASHBOARD
                count += (int)kChunkSize;

                //Check if stats collector is requesting for statistics
                if (writeStats[thread_idx])
                {
                    var tstart1 = tstop1;
                    tstop1 = Stopwatch.GetTimestamp();
                    threadProgress[thread_idx]   = count;
                    threadThroughput[thread_idx] = (count - lastWrittenValue) / ((tstop1 - tstart1) / freq);
                    lastWrittenValue             = count;
                    writeStats[thread_idx]       = false;
                    statsWritten[thread_idx].Set();
                }
#endif
            }

            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);
        }