NLog processor performance issue

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

It consumes too much processor time. I have been running a Windows service using Nlog for a long time, and two days later my service consumes more than 80% of the processor time (one core almost 80%, the second 30%). This is not a 100% processor, but it is changing, and after 2 hours it is back to normal. So I run the profiler, and this method can call it: NLog.Targets.Wrappers.AsyncTargetWrapper.ProcessPendingEvents (object state)

I have 10 target files, all of them are configured as async. It is a fact that I have a lot of registration in my application, but only at the Trace level, if I switched to the Info level, it did not help.

Can you help me if I need to register in my application?

+8
source share
3 answers

According to this thread, I would also suggest that setting a larger number for timeToSleepBetweenBatches should shorten the processor’s high performance time. It seems that beta 2.0 of NLog should fix this if only one lazy write stream is running at a time.

At the same time, you do not need to change the source code to change timeToSleepBetweenBatches . You can install 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 - The time in milliseconds to sleep between batches. Installer Default: 50

+5
source

I briefly reviewed the sources. My suggestion:

try changing ctor AsyncTargetWrapper (wrappedTarget, queueLimit, overflowAction) ...

 this.TimeToSleepBetweenBatches = 50; 

to something less frequent:

 this.TimeToSleepBetweenBatches = 1000; 

therefore, the internal timer will not start every 50 ms !

+2
source

I suggest using BufferingWrapper , it starts the timer only when something is logged, and not every 50 ms. Even if nothing is registered.

Update NLog ver. 4.6 now uses timeToSleepBetweenBatches = 1, where it fires a timer event only if something is written.

0
source

All Articles