public void LotsOfConcurrentMapRedRequestsShouldWork() { var keys = new List <string>(); for (var i = 1; i < 11; i++) { var key = "key" + i; var doc = new RiakObject(MapReduceBucket, key, new { value = i }); keys.Add(key); var result = Client.Put(doc, new RiakPutOptions { ReturnBody = true }); result.ShouldNotBeNull(); } var input = new RiakBucketKeyInput(); keys.ForEach(k => input.Add(MapReduceBucket, k)); var query = new RiakMapReduceQuery() .Inputs(input) .MapJs(m => m.Source(@"function(o){return[1];}")) .ReduceJs(r => r.Name(@"Riak.reduceSum").Keep(true)); query.Compile(); var results = new List <RiakMapReduceResult> [ThreadCount]; var watch = Stopwatch.StartNew(); Parallel.For(0, ThreadCount, i => { results[i] = DoMapRed(query); }); watch.Stop(); var executionTime = watch.Elapsed; var failures = 0; foreach (var r in results.SelectMany(l => l)) { if (r != null) { var resultValue = JsonConvert.DeserializeObject <int[]>(r.PhaseResults.ElementAt(1).Values.First().FromRiakString())[0]; resultValue.ShouldEqual(10); //r.Value.PhaseResults.ElementAt(1).GetObject<int[]>()[0].ShouldEqual(10); } else { // the only acceptable result is that it ran out of retries when // talking to the cluster (trying to get a connection) //r.ResultCode.ShouldEqual(ResultCode.NoRetries); ++failures; } } Console.WriteLine("Total of {0} out of {1} failed to execute due to connection contention. Execution time = {2} milliseconds, for an average of {3} milliseconds", failures, ThreadCount * ActionCount, executionTime.TotalMilliseconds, (executionTime.TotalMilliseconds / (ThreadCount * ActionCount))); }
public void LotsOfConcurrentStreamingMapRedRequestsShouldWork() { var keys = new List <string>(); for (var i = 1; i < 11; i++) { var key = "key" + i; var doc = new RiakObject(MapReduceBucket, key, new { value = i }); keys.Add(key); var result = Client.Put(doc, new RiakPutOptions { ReturnBody = true }); result.ShouldNotBeNull(); } var input = new RiakBucketKeyInput(); keys.ForEach(k => input.Add(MapReduceBucket, k)); var query = new RiakMapReduceQuery() .Inputs(input) .MapJs(m => m.Source(@"function(o){return[1];}")) .ReduceJs(r => r.Name(@"Riak.reduceSum").Keep(true)); query.Compile(); var results = new List <RiakMapReduceResultPhase> [ThreadCount]; var watch = Stopwatch.StartNew(); Parallel.For(0, ThreadCount, i => { results[i] = DoStreamingMapRed(query); }); watch.Stop(); var executionTime = watch.Elapsed; var failures = 0; foreach (var result in results) { if (result.Count > 0) { var lastResult = result.OrderByDescending(r => r.Phase).First(); var resultValue = JsonConvert.DeserializeObject <int[]>(lastResult.Values.First().FromRiakString()); //var resultValue = JsonConvert.DeserializeObject<int[]>(r.Value.PhaseResults.ElementAt(1).Values.First().FromRiakString())[0]; // due to the speed which things happen at, we can't gaurantee all 10 will be in the result set resultValue[0].IsAtLeast(5); //lastResult.GetObject<int[]>()[0].ShouldEqual(10); } else { ++failures; } } Console.WriteLine("Total of {0} out of {1} failed to execute due to connection contention. Execution time = {2} milliseconds, for an average of {3} milliseconds", failures, ThreadCount * ActionCount, executionTime.TotalMilliseconds, (executionTime.TotalMilliseconds / (ThreadCount * ActionCount))); }