Пример #1
0
        private static void PopulateStore(FasterKV <CacheKey, CacheValue> store)
        {
            // Start session with FASTER
            using var s = store.For(new CacheFunctions()).NewSession <CacheFunctions>();

            Console.WriteLine("Writing keys from 0 to {0} to FASTER", numKeys);

            Stopwatch sw = new Stopwatch();

            sw.Start();
            for (int i = 0; i < numKeys; i++)
            {
                if (i % (1 << 19) == 0)
                {
                    long workingSet = Process.GetCurrentProcess().WorkingSet64;
                    Console.WriteLine($"{i}: {workingSet / 1048576}M");
                }
                var key   = new CacheKey(i);
                var value = new CacheValue(i);
                s.Upsert(ref key, ref value);
            }
            sw.Stop();
            Console.WriteLine("Total time to upsert {0} elements: {1:0.000} secs ({2:0.00} inserts/sec)", numKeys, sw.ElapsedMilliseconds / 1000.0, numKeys / (sw.ElapsedMilliseconds / 1000.0));
        }
Пример #2
0
        private static void RandomReadWorkload(int threadid)
        {
            Console.WriteLine("Issuing uniform random read workload of {0} reads from thread {1}", numKeys, threadid);

            var sessions = new ClientSession <CacheKey, CacheValue, CacheValue, CacheValue, CacheContext, CacheFunctions> [kNumTables];

            for (int ht = 0; ht < kNumTables; ht++)
            {
                sessions[ht] = h[ht].NewSession <CacheValue, CacheValue, CacheContext, CacheFunctions>(new CacheFunctions());
            }

            var rnd = new Random(threadid);

            int        statusPending = 0;
            CacheValue output        = default;
            Stopwatch  sw            = new Stopwatch();

            sw.Start();

            int i = 0;

            while (true)
            {
                if (i > 0 && (i % 256 == 0))
                {
                    for (int htcnt = 0; htcnt < kNumTables; htcnt++)
                    {
                        sessions[htcnt].CompletePending(false);
                    }
                    Interlocked.Add(ref totalReads, 256);
                }
                long k = rnd.Next(numKeys);

                var hts    = sessions[rnd.Next(kNumTables)];
                var key    = new CacheKey(k);
                var status = hts.Read(ref key, ref output);

                switch (status)
                {
                case Status.PENDING:
                    statusPending++;
                    break;

                case Status.OK:
                    if (output.value != key.key)
                    {
                        throw new Exception("Read error!");
                    }
                    break;

                default:
                    throw new Exception("Error!");
                }
                i++;
            }

            /*
             * sw.Stop();
             * Console.WriteLine("Total time to read {0} elements: {1:0.000} secs ({2:0.00} reads/sec)", max, sw.ElapsedMilliseconds / 1000.0, max / (sw.ElapsedMilliseconds / 1000.0));
             * Console.WriteLine($"Reads completed with PENDING: {statusPending}");
             *
             * for (int ht = 0; ht < kNumTables; ht++)
             *  sessions[ht].Dispose();
             */
        }