-
Notifications
You must be signed in to change notification settings - Fork 338
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
Buffered Result Sets over-allocating memory #244
Comments
As a bit of a postmortem, I'm fairly sure that the sequence of events that read to this bug were:
Most people using this library will use the default The effects of this bug are that memory usage per row read from MySQL will often be If all rows are read from the buffered result set, then memory would be returned properly. This bug becomes a really big issue if several thousand rows are read. For example, 62,500 rows being read would cause the reader to consume 1GB of memory before it was available for consumption so that memory could be freed. |
Fixed in 0.18.2. |
One thing to note here is that ArrayPool will return an existing array, and not allocate one if it already had an array of equal or bigger size available (rented somewhere else in the app, used by previous mysql result etc). One thing I notice with the old code is it was renting Over the long run of the app, ArrayPool probably wins over the manual cache, as other places in the app can also be sharing the pool. https://learn.microsoft.com/en-us/dotnet/api/system.buffers.arraypool-1.rent?view=net-8.0#remarks Context: I was looking at memory allocations in ReadPayloadAsync, which would be caused by |
Originally reported at PomeloFoundation/Pomelo.EntityFrameworkCore.MySql#262
Here are the actual allocations by ArrayPool.Shared.Rent/Return:
bufferedPayload
must span multiple MySQL rows, need to re-work buffering. ArrayPool.Shared.Rent/Return may be overkill here as it seems to like to allocate a power of 2, we should probably switch this to allocating the correct sized objects.The text was updated successfully, but these errors were encountered: