예제 #1
0
        public void Setup()
        {
            var docGenerator = new JsonDocumentGenerator(DocSize, DocSize);
            var keyGenerator = new GuidKeyGenerator();

            _operation = docGenerator.GenerateDocumentsWithKeys(keyGenerator, 1)
                         .Select(p => new Replace <object>("fake", p.Key)
            {
                Content = p.Value
            })
                         .First();
        }
        public void Setup()
        {
            var docGenerator = new JsonDocumentGenerator(DocSize, DocSize);
            var keyGenerator = new GuidKeyGenerator();

            _operation = docGenerator.GenerateDocumentsWithKeys(keyGenerator, 1)
                         .Select(p => new Replace <object>
            {
                Key       = p.Key,
                Content   = p.Value,
                Completed = state => Task.CompletedTask
            })
                         .First();
        }
예제 #3
0
        public async Task LargeDocuments()
        {
            // Arrange

            const int totalOperations = 10000;
            const int mutationPercent = 10;
            var       maxSimultaneous = Environment.ProcessorCount * 2;

            var collection = await _fixture.GetDefaultCollection();

            var docGenerator = new JsonDocumentGenerator(65536, 524288);
            var keyGenerator = new GuidKeyGenerator();
            var random       = new Random();

            var documents = docGenerator.GenerateDocumentsWithKeys(keyGenerator, 100).ToList();

            await documents.ExecuteRateLimited(document => Upsert(collection, document), maxSimultaneous);

            // Act

            var stopwatch = new Stopwatch();

            stopwatch.Start();

            await Enumerable.Range(0, totalOperations)
            .ExecuteRateLimited(i =>
            {
                var document = documents[i % documents.Count];

                if (random.Next(0, 100) < mutationPercent)
                {
                    return(Upsert(collection, document));
                }
                else
                {
                    return(Get(collection, document.Key));
                }
            }, maxSimultaneous);

            stopwatch.Stop();
            _outputHelper.WriteLine($"Elapsed: {stopwatch.Elapsed}");
        }
예제 #4
0
        private byte[] CreateResponse(ITypeTranscoder transcoder, int size)
        {
            var docGenerator = new JsonDocumentGenerator(size, size);
            var keyGenerator = new GuidKeyGenerator();

            var extras = CreateExtras();

            return(docGenerator.GenerateDocumentsWithKeys(keyGenerator, 1)
                   .Select(p =>
            {
                var body = transcoder.Serializer.Serialize(p.Value);
                var header = CreateHeader(extras.Length, body.Length);

                var operation = new byte[header.Length + extras.Length + body.Length];
                Buffer.BlockCopy(header, 0, operation, 0, header.Length);
                Buffer.BlockCopy(extras, 0, operation, header.Length, extras.Length);
                Buffer.BlockCopy(body, 0, operation, header.Length + extras.Length, body.Length);
                return operation;
            })
                   .First());
        }