Very slow database creation within Azure function project deployed to Premium plan

Andrew HB 321 Reputation points
2021-02-12T13:54:29.103+00:00

Something I have discovered whilst investigating some performance issues is that it is taking entity framework between 6 and 7 seconds to perform the first database operation (the database has 152 tables) when deployed into an Azure Premium Function Plan. Our project references Microsoft.NETCore.App 3.1.0 and Microsoft.EntityFrameworkCore 3.1.1 and the database context is added via dependency injection during Startup.cs using the following code: -

builder.Services.AddDbContext<OltpContext>(
                    options => options.UseLazyLoadingProxies()
                        .UseSqlServer(
                            oltpContext,
                            sqloptionsbuilder => { sqloptionsbuilder.EnableRetryOnFailure(5, TimeSpan.FromSeconds(10), null); }),
                    ServiceLifetime.Scoped,
                    ServiceLifetime.Scoped);

Our database context service lifetimes are Scoped because we need to ensure that each request gets it's own copy of the database context because we are using global filters to restrict access to data which can potentially change from request to request.

Surely 6-7 seconds is not acceptable, our synchronisation process calls the API endpoint 10 times for different data sets and this equates to 60 seconds before we've even done any work.

If the answer is to use database contexts with service lifetimes of Singleton how can you use global filters to filter data between requests and maintain integrity of the calls and scale?

Entity Framework Core
Entity Framework Core
A lightweight, extensible, open-source, and cross-platform version of the Entity Framework data access technology.
694 questions
Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
4,200 questions
0 comments No comments
{count} votes

0 additional answers

Sort by: Most helpful