-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
Extremely large memory consumption in "ToListAsync()" when using cancellation token #30691
Comments
Try to update to Microsoft.Data.SqlClient 5.0.2 or 5.1.1 |
Wow that's strange! Im also using "Microsoft.Data.SqlClient" in version 5.1.1 but not directly included in the app, but using another nuget package which contains this. Thanks for your help - now i need to understand what happened here :-D |
@roji Any plans to adopt 5.0.2 for EF Core 7.0.x ? |
@ErikEJ yeah, I think we'll be doing that - though it's probably wise to wait a little bit to see that 5.0.2 is stable... |
Duplicate of dotnet/SqlClient#1810 |
@roji agree, issue is that it will have small adoption now that higher versions are out (5.1.x) |
Dear community,
i faced a memory issue and a big difference in selecting data from a microsoft sql database when using an async "ToListAsync()" with and without a cancellation token.
Im selecting "ids" of type "bigint / long" from a table in the database by using this statement which returns 140 mio ids:
return await _context.Items.AsNoTracking().Select(s => s.Id.GetValueOrDefault(0)).Distinct().ToListAsync();
The memory consumption of the app is round about 2 GB of memory.
The largest object in memory monitor is the list with "Ids". That's clear so far :-)
If i modify the statement and pass a cancellation token to the "ToListAsync(ct)", then the memory consumption increases to > 15 GB
return await _context.Items.AsNoTracking().Select(s => s.Id.GetValueOrDefault(0)).Distinct().ToListAsync(ct);
Now there are really large "CancellationTokenSource" and "CallBacknode" objects, which cause the high memory usage:
In general i could just remove the cancellation token but i would like to understand how i can still use a cancellation token and prevent such a large memory consumption.
The text was updated successfully, but these errors were encountered: