Пример #1
0
        public Value GetValue(RandomShift random)
        {
            if (fixedValue != null)
            {
                return(fixedValue);
            }

            // Generate random value.
            switch (binType)
            {
            case BinType.Integer:
                return(Value.Get(random.Next()));

            case BinType.String:
                StringBuilder sb = new StringBuilder(binSize);

                for (int i = 0; i < binSize; i++)
                {
                    sb.Append((char)random.Next(33, 127));
                }
                return(Value.Get(sb.ToString()));

            case BinType.Byte:
                byte[] bytes = new byte[binSize];
                random.NextBytes(bytes);
                return(Value.Get(bytes));

            default:
                return(null);
            }
        }
        private void RunWorker()
        {
            while (example.valid)
            {
                // Roll a percentage die.
                int die = random.Next(0, 100);

                if (die < args.readPct)
                {
                    if (args.batchSize <= 1)
                    {
                        int key = random.Next(0, args.records);
                        Read(key);
                    }
                    else
                    {
                        BatchRead();
                    }
                }
                else
                {
                    // Perform Single record write even if in batch mode.
                    int key = random.Next(0, args.records);
                    Write(key);
                }

                // Throttle throughput
                if (args.sync && args.throughput > 0)
                {
                    int transactions = shared.writeCount + shared.readCount;

                    if (transactions > args.throughput)
                    {
                        long millis = 1000L - shared.periodBegin.ElapsedMilliseconds;

                        if (millis > 0)
                        {
                            Util.Sleep((int)millis);
                        }
                    }
                }
            }
        }
Пример #3
0
        private void RunWorker()
        {
            while (example.valid)
            {
                // Choose key at random.
                int key = random.Next(0, args.records);

                // Roll a percentage die.
                int die = random.Next(0, 100);

                if (die < args.readPct)
                {
                    Read(key);
                }
                else
                {
                    Write(key);
                }
            }
        }