Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Entity Framework Core Slow First Time Loading

I am dealing with Entity Framework Core DbContext Warm Up time. I have very large DbContext, and I am registering out DbContexes with AddDbContextPool() option, which register DbContext as a singleton and application reuses it.

in an earlier version of EF, to speed up your application startup time following workarrounds are applied: Using a Cached DbModelStore, Generate pre-compiled Views, and/or Generate pre-compiled version of entity framework using NGen to avoid jitting.

However, I dont see any valid way of applying these on Entity Framework Core. I even could not find any other way of avoiding initial start-up / worm-up time of the DbContext.

The worm up time of our application is arround 30+ seconds.

I tried to initialize DbContextes when my application first starts however this doest seems an elegant or event affordable solution.

there is a feature request for compiled views on Entity Framework Core team (Github) however, there is no deadline for this feature.

I need to know if there is any workaround and/or solution which I can apply.

Thank you

like image 995
Derviş Kayımbaşıoğlu Avatar asked Nov 08 '22 02:11

Derviş Kayımbaşıoğlu


1 Answers

First start is slow because EF configuring table mappings. Most important thing that you can do is to redesign you dbcontext. You must split configurations into different contexts. One context must contains few entities, associated in meaning (as is done in DDD). E.g. UserDbContext (for authorization. Provides users, tokens, personalData...), CustomerDbContext (provides all customer data: customers, contacts, contracts, offers...)

like image 84
Igorgy Avatar answered Nov 14 '22 21:11

Igorgy