I have an Azure Functions app where I'm trying to eliminate delays in requests as much as possible. To combat cold start times, we've upgraded our Azure Functions plan to ensure we generally have one or more pre-warmed instances ready to go.
However, even with a pre-warmed instance, the very first HttpTrigger call to a newly launched function has a delay because it needs to establish a connection to the database. It appears a database connections is not established until the DataContext is instantiated, which in turn, doesn't happen until it is needed by an HttpTrigger. After that first request to the database, everything is quite performant.
I'm using Dependency Injection to create a DbContextPool in my FunctionsStartup class:
services.AddDbContextPool<DataContext>(options => {
options.UseSqlServer(connectionString);
});
I understand that establishing a database connection is going to naturally take a little bit of time, but is there any way to get Azure Functions to get its connection pool going at startup rather than waiting until the first HttpTrigger to instantiate my DbContext and connect to the database?