EF Core 7 deadly sin

Load testing tool

Bombardier https://github.com/codesenberg/bombardier

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

Leave a comment

Please note that we won't show your email to others, or use it for sending unwanted emails. We will only use it to render your Gravatar image and to validate you as a real person.