InfluxDB.Client.Net icon indicating copy to clipboard operation
InfluxDB.Client.Net copied to clipboard

Changed dynamic and ExpandoObject to Dictionary<string,object> to dec…

Open PatrickKalkman opened this issue 3 years ago • 2 comments

Hi, first of all, thank you very much for creating this InfluxDB client and making it open-source. We are using it on an embedded system to communicate with an InfluxDB server running on the same embedded device to process a large number of measurements.

We recently saw an enormous increase (leakage) in memory usage of one of our services that runs on the device. After some investigation, we saw that the memory leakages was coming from types in the Microsoft.CSharp.RuntimeBinder.Semantics.* namespace. See the screenshot below of running the !dumpheap -stat command in a WinDBG session.

Further investigation revealed that this could be caused by the use of dynamic and expando object which are hosted in the namespaces that I previously mentioned. See, for example, https://stackoverflow.com/questions/42519547/net4-expandoobject-usage-leaking-memory and https://stackoverflow.com/questions/33080252/memory-overflow-having-an-increasing-number-of-microsoft-csharp-runtimebinder-s

The only place where we were using dynamic and expando objects was in communicating with the InfluxDB.Client.Net. Removing this from our code by switching to the strongly typed method variants was not successful. As a last resort, we changed all the dynamic and expando object usages in InfluxDb.Client.Net to use a Dictionary<string, object> instead.

This actually fixed our problem, we see no more excessive memory usage from the Microsoft.CSharp.RuntimeBinder.Semantics namespace or any other.

This pull request includes the changes we made to fix the memory leakage problem. Although the dynamic and expando object solution is somewhat more elegant, the memory usage when you are processing a large number of samples is a serious problem for us.

We created the pull request, to help someone if they have the same problems

image

PatrickKalkman avatar Jan 06 '21 14:01 PatrickKalkman

hi @PatrickKalkman are you working on fixing the Appveyor failed test case? since it did not pass that stage, I haven't looked at your latest code closely. Please do let me know if you feel I can look at the code and possibly help fix the test failure.

mvadu avatar Jan 25 '21 04:01 mvadu

Hi @mvadu, yes I saw that a test case failed. Still working on the fix. But I have to find some time to do it.

If you could help, that would be great. But as I broke it, I feel like I should fix it :)

PatrickKalkman avatar Jan 27 '21 06:01 PatrickKalkman