示例#1
0
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        private static async Task ExecuteBenchmarkBodyAsync(IDatabase database, Contract contract, int sampleSize)
        {
            var random = new Random();
            var index  = 0;

            Dictionary <string, object>[] cache = null;

            while (!_cancellationSource.IsCancellationRequested)
            {
                var tinySampler = new Sampler(1);
                tinySampler.FillUpWith(contract);
                var singleModel = TranslateDataToContract(tinySampler.Buffer, contract, 1)[0];

                var massiveSampler = new Sampler(sampleSize);
                massiveSampler.FillUpWith(contract);

                if (index % 3 == 0 || index == 0)
                {
                    cache = TranslateDataToContract(massiveSampler.Buffer, contract);
                }

                await database.InsertManyAsync(massiveSampler.Buffer, contract.Names, _cancellationSource.Token);

                await database.SelectAsync(cache[random.Next(cache.Length)], _cancellationSource.Token);

                await database.InsertOneAsync(singleModel, _cancellationSource.Token);

                await Task.Delay(10);

                index++;
            }
        }
示例#2
0
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        private static async Task Prologue(IReadOnlyList <IDatabase> databases, Contract contract, int tableSize)
        {
            foreach (var database in databases)
            {
                await database.SetupAsync(_cancellationSource.Token);
            }

            var batchSize = 50_000;
            var processed = 0;
            var tasks     = new Task[databases.Count];

            while (processed != tableSize && !_cancellationSource.IsCancellationRequested)
            {
                var size    = Math.Min(tableSize - processed, batchSize);
                var sampler = new Sampler(size);
                sampler.FillUpWith(contract);

                for (var i = 0; i < databases.Count; i++)
                {
                    tasks[i] = databases[i].InsertManyAsync(sampler.Buffer, contract.Names, _cancellationSource.Token);
                }

                try
                {
                    Task.WaitAll(tasks);
                }
                catch (OperationCanceledException)
                {
                    return;
                }

                processed += size;
            }
        }