public RegisterCollectedProfilerStatsStep(PipelineStepProfilerStats profilerStats) => _profilerStats = profilerStats;
static TimeSpan RunTest(int numberOfMessages, PipelineStepProfilerStats profilerStats, PipelineInvokerMode pipelineInvokerMode) { using (var adapter = new BuiltinHandlerActivator()) { var network = new InMemNetwork(); Configure.With(adapter) .Logging(l => l.Console(LogLevel.Warn)) .Transport(t => t.UseInMemoryTransport(network, "perftest")) .Options(o => { o.SetNumberOfWorkers(0); o.SetMaxParallelism(1); o.Decorate <IPipeline>(c => new PipelineStepProfiler(c.Get <IPipeline>(), profilerStats)); switch (pipelineInvokerMode) { case PipelineInvokerMode.Default: o.Register <IPipelineInvoker>(c => new DefaultPipelineInvoker(c.Get <IPipeline>())); break; case PipelineInvokerMode.DefaultNew: o.Register <IPipelineInvoker>(c => new DefaultPipelineInvokerNew(c.Get <IPipeline>())); break; case PipelineInvokerMode.Compiled: o.Register <IPipelineInvoker>(c => new CompiledPipelineInvoker(c.Get <IPipeline>())); break; case PipelineInvokerMode.Action: o.Register <IPipelineInvoker>(c => new ActionPipelineInvoker(c.Get <IPipeline>())); break; default: throw new ArgumentOutOfRangeException($"Unknown pipeline invoker: {pipelineInvokerMode}"); } }) .Start(); var serializer = new JsonSerializer(); var boy = new SomeMessage("hello there!"); numberOfMessages.Times(() => { var headers = new Dictionary <string, string> { { Headers.MessageId, Guid.NewGuid().ToString() } }; var message = new Message(headers, boy); var transportMessage = serializer.Serialize(message).Result; var inMemTransportMessage = transportMessage.ToInMemTransportMessage(); network.Deliver("perftest", inMemTransportMessage); }); var numberOfReceivedMessages = 0; var gotAllMessages = new ManualResetEvent(false); adapter.Handle <SomeMessage>(async m => { Interlocked.Increment(ref numberOfReceivedMessages); if (Volatile.Read(ref numberOfReceivedMessages) == numberOfMessages) { gotAllMessages.Set(); } }); var stopwatch = Stopwatch.StartNew(); adapter.Bus.Advanced.Workers.SetNumberOfWorkers(1); gotAllMessages.WaitOrDie(TimeSpan.FromSeconds(30)); return(stopwatch.Elapsed); } }
/// <summary> /// Creates the profiler /// </summary> public PipelineStepProfiler(IPipeline pipeline, PipelineStepProfilerStats profilerStats) { _pipeline = pipeline ?? throw new ArgumentNullException(nameof(pipeline)); _profilerStats = profilerStats ?? throw new ArgumentNullException(nameof(profilerStats)); }