-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0fcd97c
commit 722bbac
Showing
9 changed files
with
143 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,4 +15,5 @@ Thumbs.db | |
*.binlog | ||
*.orig | ||
|
||
BenchmarkDotNet.Artifacts/ | ||
*.received.* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
src/ZeroLog.Benchmarks/LatencyTests/SerilogMultiProducer.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
using System; | ||
using HdrHistogram; | ||
using ZeroLog.Benchmarks.Tools; | ||
using ZeroLog.Configuration; | ||
using ZeroLog.Tests; | ||
|
||
namespace ZeroLog.Benchmarks.LatencyTests; | ||
|
||
public class SerilogMultiProducer | ||
{ | ||
public SimpleLatencyBenchmarkResult Bench(int warmingMessageCount, int totalMessageCount, int producingThreadCount) | ||
{ | ||
var sink = new SerilogTestSink(false); | ||
|
||
var logger = new Serilog.LoggerConfiguration() | ||
.WriteTo.Sink(sink) | ||
.CreateLogger(); | ||
|
||
var signal = sink.SetMessageCountTarget(warmingMessageCount + totalMessageCount); | ||
|
||
var produce = new Func<HistogramBase>(() => | ||
{ | ||
var warmingMessageByProducer = warmingMessageCount / producingThreadCount; | ||
int[] counter = { 0 }; | ||
var warmingResult = SimpleLatencyBenchmark.Bench(() => logger.Information("Hi {name} ! It's {date:HH:mm:ss}, and the message is #{number}", "dude", DateTime.UtcNow, counter[0]++), warmingMessageByProducer); | ||
|
||
var messageByProducer = totalMessageCount / producingThreadCount; | ||
counter[0] = 0; | ||
return SimpleLatencyBenchmark.Bench(() => logger.Information("Hi {name} ! It's {date:HH:mm:ss}, and the message is #{number}", "dude", DateTime.UtcNow, counter[0]++), messageByProducer); | ||
}); | ||
|
||
var result = SimpleLatencyBenchmark.RunBench(producingThreadCount, produce, signal); | ||
|
||
return result; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Threading; | ||
using Serilog.Core; | ||
using Serilog.Events; | ||
|
||
namespace ZeroLog.Benchmarks.Tools; | ||
|
||
public class SerilogTestSink : ILogEventSink | ||
{ | ||
private readonly bool _captureLoggedMessages; | ||
private readonly object _lock = new(); | ||
private int _messageCount; | ||
private ManualResetEventSlim _signal; | ||
private int _messageCountTarget; | ||
|
||
public List<string> LoggedMessages { get; } = new(); | ||
|
||
public SerilogTestSink(bool captureLoggedMessages) | ||
{ | ||
_captureLoggedMessages = captureLoggedMessages; | ||
} | ||
|
||
public ManualResetEventSlim SetMessageCountTarget(int expectedMessageCount) | ||
{ | ||
_signal = new ManualResetEventSlim(false); | ||
_messageCount = 0; | ||
_messageCountTarget = expectedMessageCount; | ||
return _signal; | ||
} | ||
|
||
public void Emit(LogEvent logEvent) | ||
{ | ||
var formatted = logEvent.RenderMessage(); | ||
|
||
lock (_lock) | ||
{ | ||
if (_captureLoggedMessages) | ||
LoggedMessages.Add(formatted); | ||
|
||
if (++_messageCount == _messageCountTarget) | ||
_signal.Set(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters