public async Task ShouldDeliverToBoth()
        {
            var count1 = 0;
            var count2 = 0;

            IPipe <InitialContext> pipe2 = Pipe.New <InitialContext>(cfg =>
            {
                cfg.UseExecuteAsync(async cxt =>
                {
                    IPipe <SubContext> pipe1 = Pipe.New <SubContext>(subCfg =>
                    {
                        subCfg.UseExecute(subCxt =>
                        {
                            Interlocked.Increment(ref count1);
                        });
                    });


                    await pipe1.Send(new SubContext()).ConfigureAwait(false);

                    Interlocked.Increment(ref count2);
                });
            });


            await pipe2.Send(new InitialContext()).ConfigureAwait(false);

            Assert.That(count1, Is.EqualTo(1));
            Assert.That(count2, Is.EqualTo(1));


            Console.WriteLine(pipe2.GetProbeResult().ToJsonString());
        }
 public void TearDown()
 {
     Console.WriteLine(_thePipe.GetProbeResult().ToJsonString());
 }
Esempio n. 3
0
        public void Run(CancellationToken cancellationToken = default(CancellationToken))
        {
            _capture = new MessageMetricCapture(_settings.MessageCount);

            IPipe <TestContext> pipe = Pipe.New <TestContext>(x =>
            {
                if (_settings.RetryCount > 0)
                {
                    x.UseRetry(r => r.Immediate(_settings.RetryCount));
                }

                if (_settings.ConcurrencyLimit > 0)
                {
                    x.UseConcurrencyLimit(_settings.ConcurrencyLimit);
                }

                x.UseExecuteAsync(async context =>
                {
                    if (_settings.Yield)
                    {
                        await Task.Yield();
                    }
                });

                x.UseFilter(new ThroughputFilter(_capture, _settings.FaultCount));
            });


            Console.WriteLine("Running Throughput Benchmark");

            Console.WriteLine(pipe.GetProbeResult().ToJsonString());

            RunBenchmark(pipe).Wait(cancellationToken);

            Console.WriteLine("Message Count: {0}", _settings.MessageCount);
            Console.WriteLine("Clients: {0}", _settings.Clients);
            Console.WriteLine("Payload Length: {0}", _payload?.Length ?? 0);
            Console.WriteLine("Concurrency Limit: {0}", _settings.ConcurrencyLimit);
            Console.WriteLine("Yield: {0}", _settings.Yield);
            Console.WriteLine("Retry: {0}", _settings.RetryCount);

            Console.WriteLine("Total send duration: {0:g}", _sendDuration);
            Console.WriteLine("Send message rate: {0:F2} (msg/s)",
                              _settings.MessageCount * 1000 / _sendDuration.TotalMilliseconds);
            Console.WriteLine("Total consume duration: {0:g}", _consumeDuration);
            Console.WriteLine("Consume message rate: {0:F2} (msg/s)",
                              _settings.MessageCount * 1000 / _consumeDuration.TotalMilliseconds);

            MessageMetric[] messageMetrics = _capture.GetMessageMetrics();

            Console.WriteLine("Avg Consume Time: {0:F0}us",
                              messageMetrics.Average(x => x.ConsumeLatency) * 1000000 / Stopwatch.Frequency);
            Console.WriteLine("Min Consume Time: {0:F0}us",
                              messageMetrics.Min(x => x.ConsumeLatency) * 1000000 / Stopwatch.Frequency);
            Console.WriteLine("Max Consume Time: {0:F0}us",
                              messageMetrics.Max(x => x.ConsumeLatency) * 1000000 / Stopwatch.Frequency);
            Console.WriteLine("Med Consume Time: {0:F0}us",
                              messageMetrics.Median(x => x.ConsumeLatency) * 1000000 / Stopwatch.Frequency);
            Console.WriteLine("95t Consume Time: {0:F0}us",
                              messageMetrics.Percentile(x => x.ConsumeLatency) * 1000000 / Stopwatch.Frequency);

            Console.WriteLine();
            DrawResponseTimeGraph(messageMetrics, x => x.ConsumeLatency);
        }