示例#1
0
        private static void InteractiveReadWorkload(FasterKV <CacheKey, CacheValue, CacheInput, CacheOutput, CacheContext, CacheFunctions> h, int max)
        {
            Console.WriteLine("Issuing interactive read workload");

            var context = new CacheContext {
                type = 1
            };

            while (true)
            {
                Console.Write("Enter key (int), -1 to exit: ");
                int k = int.Parse(Console.ReadLine());
                if (k == -1)
                {
                    break;
                }

                var output = new CacheOutput();
                var input  = default(CacheInput);
                var key    = new CacheKey(k);

                context.ticks = DateTime.Now.Ticks;
                var status = h.Read(ref key, ref input, ref output, context, 0);
                switch (status)
                {
                case Status.PENDING:
                    h.CompletePending(true);
                    break;

                case Status.OK:
                    long ticks = DateTime.Now.Ticks - context.ticks;
                    if (output.value.value != key.key)
                    {
                        Console.WriteLine("Sync: Incorrect value {0} found, latency = {1}ms", output.value.value, new TimeSpan(ticks).TotalMilliseconds);
                    }
                    else
                    {
                        Console.WriteLine("Sync: Correct value {0} found, latency = {1}ms", output.value.value, new TimeSpan(ticks).TotalMilliseconds);
                    }
                    break;

                default:
                    ticks = DateTime.Now.Ticks - context.ticks;
                    Console.WriteLine("Sync: Value not found, latency = {0}ms", new TimeSpan(ticks).TotalMilliseconds);
                    break;
                }
            }
        }
示例#2
0
        private static void RandomReadWorkload(FasterKV <CacheKey, CacheValue, CacheInput, CacheOutput, CacheContext, CacheFunctions> h, int max)
        {
            Console.WriteLine("Issuing uniform random read workload of {0} reads", max);

            var rnd = new Random(0);

            int       statusPending = 0;
            var       output        = new CacheOutput();
            var       context       = new CacheContext();
            var       input         = default(CacheInput);
            Stopwatch sw            = new Stopwatch();

            sw.Start();

            for (int i = 0; i < max; i++)
            {
                long k = rnd.Next(max);

                var key    = new CacheKey(k);
                var status = h.Read(ref key, ref input, ref output, context, 0);

                switch (status)
                {
                case Status.PENDING:
                    statusPending++;
                    if (statusPending % 1000 == 0)
                    {
                        h.CompletePending(false);
                    }
                    break;

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

                default:
                    throw new Exception("Error!");
                }
            }
            h.CompletePending(true);
            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}");
        }