Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NLog cpu performance issue

Tags:

c#

.net

nlog

I have problem with this method in NLog library: NLog.Targets.Wrappers.AsyncTargetWrapper.ProcessPendingEvents(object state)

It consume too much cpu time. I have long running windows service using Nlog and after two days my service consume over 80% cpu time (one core is almost on 80%, second 30%). It is not 100% cpu time but it is changing and after cca 2 hours its back to normal. So I have run profiler and this metod maybe cause it: NLog.Targets.Wrappers.AsyncTargetWrapper.ProcessPendingEvents(object state)

I have 10 file targets all are setted as async. It is a fact that I have lot of logging in my app but only on level Trace, if I switched to Info level it not helped.

Can you help me, should I decrease logging in my app?

like image 616
Simon Avatar asked Feb 22 '11 13:02

Simon


1 Answers

According to this thread I would also guess that setting a higher number for timeToSleepBetweenBatches should reduce the high cpu time. Seems that the 2.0 beta of NLog should fix this behavor by only having one lazy writer thread running at a time.

In the meanwhile you don't have to change the source code to change timeToSleepBetweenBatches. You can set it in the configuration file:

<targets>
  <target xsi:type="AsyncWrapper"
          name="String"
          queueLimit="Integer"
          timeToSleepBetweenBatches="Integer"
          batchSize="Integer"
          overflowAction="Enum">
    <target xsi:type="wrappedTargetType" ...target properties... />
  </target>
</targets>

Buffering Options
timeToSleepBetweenBatches - Time in milliseconds to sleep between batches.Integer Default: 50

like image 142
Martin Buberl Avatar answered Sep 24 '22 01:09

Martin Buberl