Load testing tool
EF Core 7 deadly sin
- Get only the rows that you need
- Casting IQueryable -> IEnumerable
- use .Count() from IQueryable rather than IEnumerable, which will query all data and parsing all.
- Not using AsNoTracking
- Can be faster 4x times.
- Explicit joins
- Select and map to the object directly rather than use ‘Include’ and add everything.
- Get only columns you need
- Related to #4. Be explicit about what you select. This can be achieved by using projectto() in AutoMapper.
- Do paging in the query rather than in memory.
- Non-cancellable queries
- It will help recover quickly from a massive bad requests or a missive request attack.
A few tips
- Utilize DbContextPool
- This helps 1) reduce a connection start-up time 2) recycle unused SQL connections.
- Bulk processing in chunks
- e.g. foreach(var x in List.Chunk(count))
- e.g. TagWith(“This is my spatial query!”) help find it in log.
- Sometimes raw SQL is good
This article is a quick summary from the full video, https://www.youtube.com/watch?v=x4TumMHiB6w