コード例 #1
0
        public FASTER_YcsbBenchmark(int threadCount_, int numaStyle_, string distribution_, int readPercent_)
        {
            threadCount  = threadCount_;
            numaStyle    = numaStyle_;
            distribution = distribution_;
            readPercent  = readPercent_;

#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 = HiResTimer.EstimateCPUFrequency();
#endif

            device = FASTERFactory.CreateLogDevice("C:\\data\\hlog");

#if USE_CODEGEN
            store = FASTERFactory.Create <Key, Value, Input, Output, Context, Functions, IFASTER>
#else
            store = new FasterKV
#endif
                        (kMaxKey / 2, device);
        }
コード例 #2
0
        public RandomGenerator(uint seed = 0)
        {
            if (seed == 0)
            {
                long counter = 0;
                HiResTimer.QueryPerformanceCounter(ref counter);
                x = (uint)(counter & 0x0FFFFFFF);
            }
            else
            {
                x = seed;
            }

            y = 362436069;
            z = 521288629;
            w = 88675123;
        }
コード例 #3
0
        private void SetupYcsb(int thread_idx)
        {
            if (numaStyle == 0)
            {
                Native32.AffinitizeThreadRoundRobin((uint)thread_idx);
            }
            else
            {
                Native32.AffinitizeThreadShardedTwoNuma((uint)thread_idx);
            }

#if DASHBOARD
            var tstart           = HiResTimer.Rdtsc();
            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)
                {
                    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 = HiResTimer.Rdtsc();
                    threadThroughput[thread_idx] = (count - lastWrittenValue) / ((tstop1 - tstart1) / freq);
                    lastWrittenValue             = count;
                    writeStats[thread_idx]       = false;
                    statsWritten[thread_idx].Set();
                }
#endif
            }
        }
コード例 #4
0
        public ConcurrentDictionary_YcsbBenchmark(int threadCount_, int numaStyle_, string distribution_, int readPercent_)
        {
            threadCount  = threadCount_;
            numaStyle    = numaStyle_;
            distribution = distribution_;
            readPercent  = readPercent_;

#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 = HiResTimer.EstimateCPUFrequency();
#endif


            store = new ConcurrentDictionary <Key, Value>(threadCount, kMaxKey, new KeyComparer());
        }
コード例 #5
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.AffinitizeThreadShardedTwoNuma((uint)thread_idx);
            }

            Stopwatch sw = new Stopwatch();

            sw.Start();

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

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

            store.StartSession();

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

                var local_txn_keys_ptr = txn_keys_ptr + chunk_idx;

                for (long idx = chunk_idx; idx < chunk_idx + kChunkSize && !done; ++idx, ++local_txn_keys_ptr)
                {
                    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 % 256 == 0)
                    {
                        store.Refresh();

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

                    switch (op)
                    {
                    case Op.Upsert:
                    {
                        store.Upsert(local_txn_keys_ptr, &value, null, 1);
                        ++writes_done;
                        break;
                    }

                    case Op.Read:
                    {
                        Status result = store.Read(local_txn_keys_ptr, null, (Output *)&value, null, 1);
                        if (result == Status.OK)
                        {
                            ++reads_done;
                        }
                        break;
                    }

                    case Op.ReadModifyWrite:
                    {
                        Status result = store.RMW(local_txn_keys_ptr, input_ptr + (idx & 0x7), null, 1);
                        if (result == Status.OK)
                        {
                            ++writes_done;
                        }
                        break;
                    }

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

#if DASHBOARD
                count += (int)kChunkSize;

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

            store.CompletePending(true);
            store.StopSession();
            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);
        }
コード例 #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.AffinitizeThreadShardedTwoNuma((uint)thread_idx);
            }

            Stopwatch sw = new Stopwatch();

            sw.Start();

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

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

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

                var local_txn_keys_ptr = txn_keys_ptr + chunk_idx;

                for (long idx = chunk_idx; idx < chunk_idx + kChunkSize && !done; ++idx, ++local_txn_keys_ptr)
                {
                    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[*local_txn_keys_ptr] = value;
                        ++writes_done;
                        break;
                    }

                    case Op.Read:
                    {
                        if (store.TryGetValue(*local_txn_keys_ptr, out value))
                        {
                            ++reads_done;
                        }
                        break;
                    }

                    case Op.ReadModifyWrite:
                    {
                        store.AddOrUpdate(*local_txn_keys_ptr, *(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 = HiResTimer.Rdtsc();
                    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);
        }