BingAds / BingAds-dotNet-SDK

Other
27 stars 42 forks source link

High memory usage in V12 #63

Closed franckyj closed 6 years ago

franckyj commented 6 years ago

We just deployed one of our windows services that deals with Bing Ads using the new V12 API. We instantly saw a massive jump in memory usage (the memory consumption doubled at the minimum). One of our services went as high as using 12GB of memory (according to the task manager).

So we took a process dump and trying to analyze that thing the best I can I find that there is a huge amount of strings (778490298 bytes). Looking at those strings I see serialized Bing Ads requests. Looking at what has its hand on that string I see a Microsoft.BingAds.Internal.MessagePair object that is part of a list of Microsoft.BingAds.Internal.MessagePairs which is stored in a Microsoft.BingAds.Internal.SimpleMessageStore class.

So now clone the Bing Ads repo to see where that message store comes into play. The SimpleMessageStore class is used in the Microsoft.BingAds.Internal.SimpleMessageTracer class which accesses a static Store property. So going up the chain (SimpleTraceBehavior, ServiceClientFactory, ServiceClient => of which all our custom proxy class inherits) I see that the SimpleTraceBehavior is added in the ServiceClientFactory.CreateChannelFactory method. Looking at the recent changes on that method I see that this behavior wasn't there before (commit 34e6183f, update to version 11.12.1).

Could it be that the static message store is adding all the MessagePair instances in the BeforeSendRequest method and since the store is a static property, it is never removed from memory?

I'm by no mean an expert in debugging memory leaks (was using WinDbg for the second time for this analysis...) so I might have skipped something important.

We're using the 11.12.3 version of the Microsoft.BingAds.SDK package on nuget BTW.

Thanks in advance, Francois

qitia commented 6 years ago

Thanks for raising the issue. You are right SimpleMessageStore will increase memory usage. We will provide a fix soon.

qitia commented 6 years ago

@franckyj we released a hotfix version V11.12.4.1. In which we remove cache of request/reply. Please try and let's know the result.

franckyj commented 6 years ago

Perfect

I'll let you know when we do the update.

Thanks for the quick answer + fix.