[英]Serilog async high CPU usage upto 100%
I use Serilog async logging and while doing performance testing with multiple users we found that serilog is taking all the CPU (up to 100%).我使用 Serilog 异步日志记录,在对多个用户进行性能测试时,我们发现 serilog 占用了所有 CPU(高达 100%)。 ASP.net code creates log file using Serilog Async (log.info, log.warning, log.error) and it has logging on all web pages due to security logging requirements.
ASP.net 代码使用 Serilog Async(log.info、log.warning、log.error)创建日志文件,并且由于安全日志记录要求,它已登录所有 web 页面。 CPU usage spikes after 2 hours and remains 100% continuously and system is getting major performance hit.
CPU 使用率在 2 小时后达到峰值,并且持续保持 100%,系统性能受到重大影响。
We also tested application without SeriLog enabled, the application does not spike up to 100% CPU usage.我们还测试了未启用 SeriLog 的应用程序,该应用程序的 CPU 使用率不会达到 100%。
I would really appreciate if I get any help here.如果我在这里得到任何帮助,我将不胜感激。 I can share code (logger class) I created if needed.
如果需要,我可以共享我创建的代码(记录器类)。
And how the logging is configured:以及如何配置日志记录:
var logConfig = new LoggerConfiguration()
.MinimumLevel.Information()
.WriteTo.Async(logSink =>
{
logSink.File(
logFilePath,
rollingInterval: RollingInterval.Day,
retainedFileCountLimit: null,
outputTemplate: OutputTemplate,
hooks: new HeaderWriter(header),
flushToDiskInterval: TimeSpan.FromSeconds(10),
shared: true
);
});
Log.Logger = logConfig.CreateLogger();
Some thoughts on further investigation Serilog performance:关于进一步调查 Serilog 性能的一些想法:
Serilog.Debugging.SelfLog.Enable(Console.Error);
// Don't:
Log.Information("The time is " + DateTime.Now);
// Do:
Log.Information("The time is {Now}", DateTime.Now);
If you log large strings, log them as property to prevent parsing and caching.如果您记录大字符串,请将它们记录为属性以防止解析和缓存。
Task
, Stream
, etcTask
, Stream
等// Don't
// Destructuring entire Request with @ will generate a lot of useless data
Log.Information("Got request {@HttpRequest}", HttpContext.Request);
if you want to log such complex objects, define Destructure.ByTransforming() or IDestructuringPolicy.如果要记录此类复杂对象,请定义Destructure.ByTransforming()或 IDestructuringPolicy。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.