public SimpleLatencyBenchmarkResult Bench(int warmingMessageCount, int totalMessageCount, int producingThreadCount) { var appender = new NLogTestTarget(false); var config = new LoggingConfiguration(); config.AddTarget(nameof(appender), appender); config.LoggingRules.Add(new LoggingRule(nameof(appender), LogLevel.Debug, appender)); NLog.LogManager.Configuration = config; NLog.LogManager.ReconfigExistingLoggers(); var logger = NLog.LogManager.GetLogger(nameof(appender)); var signal = appender.SetMessageCountTarget(totalMessageCount); var produce = new Func <HistogramBase>(() => { var warmingMessageByProducer = warmingMessageCount / producingThreadCount; int[] counter = { 0 }; var warmingResult = SimpleLatencyBenchmark.Bench(() => logger.Info("Hi {0} ! It's {1:HH:mm:ss}, and the message is #{2}", "dude", DateTime.UtcNow, counter[0]++), warmingMessageByProducer); var messageByProducer = totalMessageCount / producingThreadCount; counter[0] = 0; return(SimpleLatencyBenchmark.Bench(() => logger.Info("Hi {0} ! It's {1:HH:mm:ss}, and the message is #{2}", "dude", DateTime.UtcNow, counter[0]++), messageByProducer)); }); var result = SimpleLatencyBenchmark.RunBench(producingThreadCount, produce, signal); LogManager.Shutdown(); return(result); }
public List <HistogramBase> Bench(int queueSize, int warmingMessageCount, int totalMessageCount, int producingThreadCount) { var appender = new NLogTestTarget(false); var asyncTarget = (new AsyncTargetWrapper(appender, queueSize, overflowAction: AsyncTargetWrapperOverflowAction.Block)); var config = new LoggingConfiguration(); config.AddTarget(nameof(asyncTarget), asyncTarget); config.LoggingRules.Add(new LoggingRule(nameof(asyncTarget), LogLevel.Debug, asyncTarget)); NLog.LogManager.Configuration = config; NLog.LogManager.ReconfigExistingLoggers(); var logger = NLog.LogManager.GetLogger(nameof(asyncTarget)); var signal = appender.SetMessageCountTarget(warmingMessageCount + totalMessageCount); var produce = new Func <HistogramBase>(() => { var warmingMessageByProducer = warmingMessageCount / producingThreadCount; var warmingResult = SimpleLatencyBenchmark.Bench(i => logger.Info("Hi {0} ! It's {1:HH:mm:ss}, and the message is #{2}", "dude", DateTime.UtcNow, i), warmingMessageByProducer); var messageByProducer = totalMessageCount / producingThreadCount; return(SimpleLatencyBenchmark.Bench(i => logger.Info("Hi {0} ! It's {1:HH:mm:ss}, and the message is #{2}", "dude", DateTime.UtcNow, i), messageByProducer)); }); var flusher = new Action(() => { while (!signal.IsSet) { NLog.LogManager.Flush(); } }); Task.Factory.StartNew(flusher, TaskCreationOptions.LongRunning); var tasks = new List <Task <HistogramBase> >(); for (var i = 0; i < producingThreadCount; i++) { tasks.Add(Task.Factory.StartNew(produce, TaskCreationOptions.LongRunning)); } signal.Wait(TimeSpan.FromSeconds(30)); LogManager.Shutdown(); return(tasks.Select(x => x.Result).ToList()); }
// // NLog Sync // private void SetupLogNLog() { _nLogTestTarget = new NLogTestTarget(false); _nLogAsyncTestTarget = new NLogTestTarget(false); var asyncTarget = (new AsyncTargetWrapper(_nLogAsyncTestTarget, QueueSize, overflowAction: AsyncTargetWrapperOverflowAction.Block)); var config = new LoggingConfiguration(); config.AddTarget(nameof(_nLogTestTarget), _nLogTestTarget); config.AddTarget(nameof(asyncTarget), asyncTarget); config.LoggingRules.Add(new LoggingRule(nameof(NLogSync), LogLevel.Debug, _nLogTestTarget)); config.LoggingRules.Add(new LoggingRule(nameof(NLogAsync), LogLevel.Debug, asyncTarget)); NLog.LogManager.Configuration = config; NLog.LogManager.ReconfigExistingLoggers(); _nLogLogger = NLog.LogManager.GetLogger(nameof(NLogSync)); _nLogAsyncLogger = NLog.LogManager.GetLogger(nameof(NLogAsync)); }
public SimpleLatencyBenchmarkResult Bench(int queueSize, int warmingMessageCount, int totalMessageCount, int producingThreadCount) { var appender = new NLogTestTarget(false); var asyncTarget = (new AsyncTargetWrapper(appender, queueSize, overflowAction: AsyncTargetWrapperOverflowAction.Block)); var config = new LoggingConfiguration(); config.AddTarget(nameof(asyncTarget), asyncTarget); config.LoggingRules.Add(new LoggingRule(nameof(asyncTarget), LogLevel.Debug, asyncTarget)); NLog.LogManager.Configuration = config; NLog.LogManager.ReconfigExistingLoggers(); var logger = NLog.LogManager.GetLogger(nameof(asyncTarget)); var signal = appender.SetMessageCountTarget(warmingMessageCount + totalMessageCount); var produce = new Func <HistogramBase>(() => { var warmingMessageByProducer = warmingMessageCount / producingThreadCount; int[] counter = { 0 }; var warmingResult = SimpleLatencyBenchmark.Bench(() => logger.Info("Hi {0} ! It's {1:HH:mm:ss}, and the message is #{2}", "dude", DateTime.UtcNow, counter[0]++), warmingMessageByProducer); var messageByProducer = totalMessageCount / producingThreadCount; counter[0] = 0; return(SimpleLatencyBenchmark.Bench(() => logger.Info("Hi {0} ! It's {1:HH:mm:ss}, and the message is #{2}", "dude", DateTime.UtcNow, counter[0]++), messageByProducer)); }); var flusher = new Action(() => { while (!signal.IsSet) { NLog.LogManager.Flush(); } }); Task.Factory.StartNew(flusher, TaskCreationOptions.LongRunning); var result = SimpleLatencyBenchmark.RunBench(producingThreadCount, produce, signal); LogManager.Shutdown(); return(result); }