efcore: Core 3.1.* streaming results - slower, and higher memory usage than 2.2.*
I used Entity Framework Core 2.2.* to stream results from a database over Web API. The speed that results were returned was “very good” and the memory usage we also “very good”.
When I switched to EF Core 3.1.8 (no other code changes), the speed the results were returned was “very poor” compared to 2.2.* and the memory usage was also “very poor” compared to 2.2.*.
In my test, 2.2.* was about twice as fast as 3.1.8 and consumed about a quarter of the memory. The linked blog post below shows the numbers.
Steps to reproduce
Using .NET 3.1 create a Web API application. Seed a database with “Products”. Add a controller like below. Use EF Core 2.2.6. Measure speed of return of results and memory usage. Use EF Core 3.1.8. Measure speed of return of results and memory usage.
[Route("api/[controller]")]
[ApiController]
public class ProductsController : ControllerBase
{
private readonly SalesContext _salesContext;
public ProductsController(SalesContext salesContext)
{
_salesContext = salesContext;
}
[HttpGet("streaming/{count}")]
public ActionResult GetStreamingFromService(int count)
{
IQueryable<Product> products = _salesContext.Products.OrderBy(o => o.ProductId).Take(count).AsNoTracking();
return Ok(products);
}
}
A functioning solution with database seeding is available here. There is a zip file linked at the top and bottom of the post.
Further technical details
EF Core version: 2.2.6 and 3.1.8 Database provider: Microsoft.EntityFrameworkCore.SqlServer Target framework: .NET Core 3.1 Operating system: Windows 10 IDE: Visual Studio 2019 16.7.3
About this issue
- Original URL
- State: open
- Created 4 years ago
- Comments: 18 (8 by maintainers)
@roji I’m happy to help if I can, and will try some variations of your code to see if I can produce the same problem narrowed to the nub of the issue.
I was using Fiddler to perform the web requests, the screenshots in the blog post are captured from that.