New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Memory Leak With Async File Target on Mono 4.2 #1137
Comments
Hey! |
I have read your post wrong. First of all, there is a config two (common) mistakes with the following config: <targets async="true">
<target name="asyncFileDebug" xsi:type="AsyncWrapper">
<target xsi:type="File" name="fileLogDebug" ... />
</target>
</targets>
<rules>
<logger name="MemoryLeakTestLog" level="Debug" writeTo="fileLogDebug" />
</rules>
It should be (no <targets async="true">
<target xsi:type="File" name="fileLogDebug" ... />
</targets>
<rules>
<logger name="MemoryLeakTestLog" level="Debug" writeTo="fileLogDebug" />
</rules> OR (no <targets >
<target name="asyncFileDebug" xsi:type="AsyncWrapper">
<target xsi:type="File" name="fileLogDebug" ... />
</target>
</targets>
<rules>
<logger name="MemoryLeakTestLog" level="Debug" writeTo="asyncFileDebug" />
</rules> Can you test with one of the two configs? Also, can you give me:
Thanks in Advance! |
Hello, glad to help, i tested both configurations and the result is the same, memory consumption increases over time. This is the output when installing NLog from nuget PM> Install-Package NLog If i see the propertys of NLog.dll i get the following This only hapens when running under mono Mono JIT compiler version 4.2.1 (Stable 4.2.1.102/6dd2d0d Thu Nov 12 09:52:44 UTC 2015) This didn't happen with the previous mono version, and this behaviour is shown even if the service isn't processing any requests. If you send 1 request and leave the service running idle the memory starts rising even if you don't send any other request. |
Whats the previous version? 4.2.2? 4.1.0? |
|
In Mono 3.12.1 NLog runs async without a problem. |
I'm sorry, but what version do you mean? There is no NLog 3.12.1? |
No, that's the mono version where the same code works without any problem. |
Ow, so it's only a problem in Mono 4 and not in Mono 3.1.2? But is there an NLog version (you know) which works well on Mono 4?
I did read NLog 4.2 for 4.2 here. Sorry about the confusion |
you're using the nuget package right? There is some mono-optimized code in NLog, but it won't work with the NuGet packages :( (there is no mono platform) |
Yeah, i'm using the nuget package |
edit: that's a too old post... related code: https://github.com/NLog/NLog/blob/master/src/NLog/Targets/Wrappers/AsyncTargetWrapper.cs |
There was also a PR for Mono 4 a while ago, but AFAIK it did only copied the code #958 |
Has this been fixed in newer Mono builds? |
I don't know if we can fix this. At least we need more info to look into this. |
Is this still an issue? |
Yes, I'm expiriencing exact same issues when using NLog 4.4 with sync file target. Mono 4.6 and 4.8, but I believe leak is due mono bug. Donwgrade to Mono 4.0.4 solves the issue. |
Sounds like a different problem, as the original poster doesn't have the problem when using sync-target (disappear when removing async). Maybe the problem is reduced for original poster if the async-target uses timeToSleepBetweenBatches=0 (Requires NLog ver. 4.3.11 or newer). This will make the async-behavior more aggressive and decrease the chance that logevents are "captured" by the garbage collector for later cleanup (but instead will get immediate GC0 cleanup). Also if using keepFilesOpen=false (the default, but slowest), then it can be a very good idea to lower bufferSize for the file-targets. Use bufferSize=4096 (Instead of default bufferSize=32768, that only makes sense when keepFilesOpen=true. No longer needed after #3444 in NLog 4.6.5) |
An example of MONO_GC_PARAMS for keeping memory as low as possible:
If the device has a limited physical memory (Like Pi), then one can also consider to configure max-heap-size=256m for MONO_GC_PARAMS |
Is anyone having this issue when deploying with docker?? |
Not sure what your issue is, but apparently there can be dragons when using console-out: |
Btw. original poster also posted a bug report to Xamarin/MONO, but their testers failed to reproduce the leak. When major collection occurred then memory dropped correctly: |
I dropped my mono version to v3.8.0 and the memory leak disappeared which works for me at the moment when I am less busy. I'll update my project .NET framework to 4.6 and test with mono version 4.2 again. Its just a hunch but I think there is some sort of correlation between the mono version and .NET framework. |
Will close this as this is a known issue as it's polluting the issue list - there is no action for us here. |
We found that when we updated to the latest Mono Version (4.2) our services began to show an increase in memory usage, after some profiling and testing and some research we found out it was the Logging section the one to be blamed, this section uses NLog async writting to save different purpose logs. We removed the async part and the problem was fixed. You can find some test code and more details here https://github.com/eleonel1/Mono4.2NLogMemoryLeak
The text was updated successfully, but these errors were encountered: