Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cold start time took more more than 10 secs with C# compiled + "Run from package" for Azure function v2 #3965

Open
RudyLu opened this issue Jan 16, 2019 · 55 comments

Comments

@RudyLu
Copy link

RudyLu commented Jan 16, 2019

Investigative information

Please provide the following:

  • Timestamp: 2019-01-16 01:01:11.130
  • Function App version (1.0 or 2.0): 2
  • Function App name: test-vs-func
  • Function name(s) (as appropriate): test_vs_func
  • Invocation ID: 24594d05-f1bb-4840-8439-f0227fb02678
  • Region: East Asia

Repro steps

Provide the steps required to reproduce the problem:

  1. Compiled the sample app with visual studio for mac.
  2. Change function app to "Run from package"
  3. Zip it and do the zip deployment.
    az functionapp deployment source config-zip -g rudy-dev -n test-vs-func --src csharp.zip

Expected behavior

I would expect that C# compiled + "Run from package" would have the lowest cold start time.

Actual behavior

The cold start time is even worse than C# without "Run from package" and C# script.

Known workarounds

no

Related information

Provide any related information

Source
using System;
using System.IO;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Extensions.Http;
using Microsoft.AspNetCore.Http;
using Microsoft.Azure.WebJobs.Host;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;

namespace test_vs_func
{
    public static class test_vs_func
    {
        [FunctionName("test_vs_func")]
        public static async Task<IActionResult> Run([HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)]HttpRequest req, ILogger log)
        {
            log.LogInformation("C# HTTP trigger function processed a request.");

            string name = req.Query["name"];

            string requestBody = await new StreamReader(req.Body).ReadToEndAsync();
            dynamic data = JsonConvert.DeserializeObject(requestBody);
            name = name ?? data?.name;

            return name != null
                ? (ActionResult)new OkObjectResult($"Hello, {name}")
                : new BadRequestObjectResult("Please pass a name on the query string or in the request body");
        }
    }
}
@safihamid
Copy link
Contributor

Please take a look at our docs here: https://docs.microsoft.com/en-us/azure/azure-functions/run-functions-from-deployment-package

"When running a function app on Windows, the external URL option yields worse cold-start performance. When deploying your function app to Windows, you should set WEBSITE_RUN_FROM_PACKAGE to 1 and publish with zip deployment."

@RudyLu
Copy link
Author

RudyLu commented Mar 10, 2019

I think I already did this with these steps,

Change function app to "Run from package"
Zip it and do the zip deployment.
az functionapp deployment source config-zip -g rudy-dev -n test-vs-func --src csharp.zip

Can you suggest any specific step that I might miss?
Or what's the expected cold start time for a simplest hello world function?

@safihamid
Copy link
Contributor

You might be hitting this issue: Azure/azure-functions-core-tools#1086

@safihamid
Copy link
Contributor

safihamid commented Mar 11, 2019

Also we are tracking cold start improvements with these two issues:

  1. [V2 cold start] Enabling AppInsights is increasing functions cold start by 500-800 milliseconds  #4183
  2. [V2 cold start] Cache Expression compilation results during placeholder mode to avoid recompiles during specialization mode #4184

For a simple hello world C# function, we see cold start of ~2 seconds and once issue #2 is fixed that should be improved by another 30-40%.

@ChristianWeyer
Copy link

@safihamid the second issue you mention has been closed by @fabiocav - why exactly? And does this mean that there are/will not be further cold start improvements? 🤔

@safihamid
Copy link
Contributor

@ChristianWeyer both issues mentioned above have already been addressed. For the issue which is closed we ended up doing an alternative approach.

And we are constantly working on improving cold starts. It is one of the most important tasks of few of us here at msft :-) there are some major improvements coming in the next couple of months :-)

@ChristianWeyer
Copy link

Glad to hear! :-)

@petro2050
Copy link

@safihamid @fabiocav @jeffhollan According to this article (https://mikhail.io/2019/03/reducing-azure-functions-cold-start-time/), running from a zip file actually increases cold start times. Can you comment on that?

I have C# functions as well that are deployed as a package, and my cold starts can be as long as 12-15 seconds. This is unacceptable for a production app. What is the future of consumption plans? If I purchase a premium plan, why should I choose Functions over App Service Plan?

@safihamid
Copy link
Contributor

@petro2050 running from zip should not increase your cold start. Make sure you are deploying using the latest Functions SDK which actually decreases the zip size. Is it V2 or V3 app? Are you adding lots of extra dependencies? If yes make sure you publish with ReadyToRun set to true.

@petro2050
Copy link

petro2050 commented Apr 19, 2020

@safihamid It's V3.

<TargetFramework>netcoreapp3.1</TargetFramework>
<AzureFunctionsVersion>v3</AzureFunctionsVersion>
  • Do I need to update my host.json file as well?

{
"version": "2.0"
}

  • As for the dependencies, in bin folder, I have 133 dlls. The unzipped size for all is 29 MBs. Is this too much?

  • Do you have support for ReadyToRun? When I set it to true, I cannot publish the app via VS. I'm getting the following error:

Unable to optimize assemblies for performance: a valid runtime package was not found. Either set the PublishReadyToRun property to false, or use a supported runtime identifier when publishing.

#5876

  • Do you run any optimizations on your end with respect to assemblies? I realized out of the 29 MBs, EntityFramework takes up 8 MBs. Maybe you can GAC it on the server and avoid transferring the files? Most .NET server projects use EF nowadays (though versioning can be a problem).

@safihamid
Copy link
Contributor

safihamid commented Apr 19, 2020

@petro2050 i answered on the other git issue you mentioned. Make sure your Microsoft.NET.Sdk.Functions SDK version in .csproj file is 3.0.5 or higher.

And then you can publish your project by passing RID to publish command:
dotnet publish your prod.csproj -r win-x86 -c release

You can add the RID like win-x86, win-x64, ... to your csproj as well.

Zip file size for your function app is large. We are releasing some major improvements for download time in the next few months but in the mean time you might want to consider using premium azure files for your file storage if zip size for your scenario continues to be large. But I am pretty sure most of your cold start time is JIT time for your external assemblies and R2R should significantly improve it.

@petro2050
Copy link

I'm on SDK 3.0.3 right now and unable to upgrade due to an issue with System.IdentityModel.Tokens.Jwt.

System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.IdentityModel.Tokens, Version=6.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. The system cannot find the file specified.File name: 'Microsoft.IdentityModel.Tokens, Version=6.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'

Is this related to you or JWT?

I will use premium storage since I don't expect the zip size to shrink as I'm using only the most essential packages for my server infrastructure. Looking forward to the updates in the coming months. :)

@safihamid
Copy link
Contributor

@petro2050 not sure about that issue, @fabiocav do you know why he can’t upgrade to 3.0.5, have you seen above error?
@petro2050 again I think enabling R2R should significantly improve your cold start. If it didn’t send me your app name and I will look further.

@petro2050
Copy link

@fabiocav Any input with regards to the JWT issue would be appreciated.

@vitalybibikov
Copy link

@petro2050 It's yet another not tested release of AF with an issue in 3.0.6

To fix it, for now add in project file.

  <PropertyGroup>
    <_FunctionsSkipCleanOutput>true</_FunctionsSkipCleanOutput>
  </PropertyGroup>

Still can't deploy with the settings below:

  <PropertyGroup>
    <TargetFramework>netcoreapp3.1</TargetFramework>
    <AzureFunctionsVersion>v3</AzureFunctionsVersion>
    <PublishReadyToRun>true</PublishReadyToRun>
    <RuntimeIdentifiers>win-x64</RuntimeIdentifiers>
  </PropertyGroup>

with error:

Unable to optimize assemblies for performance: a valid runtime package was not found. Either set the PublishReadyToRun property to false, or use a supported runtime identifier when publishing.

@safihamid
Copy link
Contributor

@vitalybibikov are you trying to build from a non-windows machine? If RID is win-x86 or win-x64 then you will need to build from a Windows machine, similarly you can’t build Linux-x64 from Windows.

@vitalybibikov
Copy link

vitalybibikov commented Apr 29, 2020

Hi, @safihamid
No, I'm building from Windows machine, Win10, Ver 2004, 19582.1001 if it matters

It actually works locally, so with RID I can run the function and it operates (locally)
But Publish to Azure fails, till RID + R2R are removed

@safihamid
Copy link
Contributor

safihamid commented Apr 29, 2020

@vitalybibikov I was able to repro your issue and there is a typo in your .csproj file. when R2R is enabled you will need to use
<RuntimeIdentifier> and not <RuntimeIdentifiers>

Here is how your .csproj file should look like:

`

<TargetFramework>netcoreapp3.1</TargetFramework>
<AzureFunctionsVersion>v3</AzureFunctionsVersion>
<PublishReadyToRun>true</PublishReadyToRun>
<RuntimeIdentifier>win-x64</RuntimeIdentifier>

<ItemGroup> <PackageReference Include="Microsoft.NET.Sdk.Functions" Version="3.0.6" /> </ItemGroup>

Also remember Azure Functions by default are 32bit in Windows, if you are deploying win-x64 you must change the platform to 64bit here is the screenshot from Azure portal:
image

@vitalybibikov
Copy link

@safihamid Whoa, thanks, not easy to spot this one

@vitalybibikov
Copy link

vitalybibikov commented Apr 30, 2020

And the reason why I'm using x64 is that x86 currently does not work.
I've tried it on a newly created VM as well as on my machine.

OS: Win10
Azure Functions Core Tools (3.0.2245 Commit hash: 1d094e2f3ef79b9a478a1621ea7ec3f93ac1910d)
Function Runtime Version: 3.0.13139.0
VS 16.5.4

How to repro:

  1. Just create an app from template.
  2. Set the following: RID win-x86 or win10-x86
  <PropertyGroup>
    <TargetFramework>netcoreapp3.1</TargetFramework>
    <AzureFunctionsVersion>v3</AzureFunctionsVersion>
    <RuntimeIdentifier>win-x86</RuntimeIdentifier>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="Microsoft.NET.Sdk.Functions" Version="3.0.6" />
  </ItemGroup>

And you will get:

image

If I switch it to x64, it starts.

  <PropertyGroup>
    <TargetFramework>netcoreapp3.1</TargetFramework>
    <AzureFunctionsVersion>v3</AzureFunctionsVersion>
    <RuntimeIdentifier>win-x64</RuntimeIdentifier>
  </PropertyGroup>

image

Might it be that recently cli goes x64 by default, I haven't checked yet.

@vitalybibikov
Copy link

vitalybibikov commented Apr 30, 2020

The reason is that default "Platform Target" for Azure Functions projects is now x86.
So it does not work in configuration: win-x86 + platform x86. (why?)

However, it starts in the Cofiguration of win-x86 + Any CPU
But then it fails if you have SqlClient lib installed (I guess everything with Dapper, ADO, EF Core)
with an error:

System.TypeInitializationException: The type initializer for 'Microsoft.Data.SqlClient.TdsParser' threw an exception
due to some issue with SNI deps, they have a bunch of bugs related to that in github.

So, the only possible configuration is win-x64 + target x64, Unfortunately.
Which actually performs slower during load/perf testing, than a simple configuration.

@safihamid
Copy link
Contributor

safihamid commented Apr 30, 2020

@vitalybibikov I understand there seem to be some issues with CLI when RuntimeIdentifier is win-x86 but that's only for running locally. when deploying to Azure it should work fine for both win-x86 or win-x64. isn't that the case for you?
tracking the CLI issue here: https://github.com/Azure/azure-functions-vs-build-sdk/issues/382

@vitalybibikov
Copy link

vitalybibikov commented May 1, 2020

Unfortunately, no.

32bit in azure + 
<RuntimeIdentifier>win-x86</RuntimeIdentifier>

In Azure:
The 'XFunction' function is in error: Microsoft.Azure.WebJobs.Host: Error indexing method 'XFunction'. Microsoft.Azure.WebJobs.Host: Cannot bind parameter 'token' to type FunctionTokenResult. Make sure the parameter Type is supported by the binding. If you're using binding extensions (e.g. Azure Storage, ServiceBus, Timers, etc.) make sure you've called the registration method for the extension(s) in your startup code (e.g. builder.AddAzureStorage(), builder.AddServiceBus(), builder.AddTimers(), etc.).

Locally:
image

64bit in azure + 
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
  • Works in azure
  • Works locally

@MikePennington
Copy link

I've seen similarly horrendous startup times with http-triggered dotnet function apps (10+ seconds) and have tried everything I've found online and then some to bring it down. The best option I've found is actually to use the func azure functionapp publish command instead running dotnet publish and az functionapp deployment source config-zip yourself. I don't know what kind of magic it is doing under the hood, but my cold starts now average out to just a little under 2 seconds.

@petro2050
Copy link

petro2050 commented May 25, 2020

@safihamid

Zip file size for your function app is large. We are releasing some major improvements for download time in the next few months but in the mean time you might want to consider using premium azure files for your file storage if zip size for your scenario continues to be large. But I am pretty sure most of your cold start time is JIT time for your external assemblies and R2R should significantly improve it.

I wanted to switch to using a premium storage account, but it looks like Azure Functions only works with general-purpose accounts. How can I use premium azure files? Would appreciate your input on that as I expect to go to production this year.

https://docs.microsoft.com/en-us/azure/azure-functions/storage-considerations

@safihamid
Copy link
Contributor

@petro2050 you can create your func app using a premium storage account then add the AzureWebJobsStorage app setting and sets its value to a general-purpose storage account. that storage account will be used for logging, ... but your content will be stored on premium storage account. Again we are significantly improving the download time from regular storage in the next few months.

@safihamid
Copy link
Contributor

@MikePennington not sure why you see 10+ seconds of cold start, you should see the cold starts of ~1 second or so. feel free to share your app name and we can take a look.

@MikePennington
Copy link

Thanks @safihamid, I'd love the help! As I mentioned above, I see much better results when I deploy using the func cli, so I thought I had a solution to the issue, but now I am having difficulty using func in Azure DevOps, so I would greatly appreciate more insight here.

I have deployed the same codebase using two different methods. The infra is defined in an ARM template and is the same for both.

Using az functionapp deployment source config-zip. Cold start times between 9 - 11 seconds.
https://mpapiaz-mikepenn.azurewebsites.net/api/rop/65?siteNumber=1

Using func azure functionapp publish. Cold start times between 1 - 1.5 seconds.
https://mpapifunc-mikepenn.azurewebsites.net/api/rop/65?siteNumber=1

@petro2050
Copy link

@safihamid It says premium storage accounts only support page blobs. Don't I need file shares with Azure Functions?

cap

When I try to create a function app with premium storage, I'm getting BadRequest on Azure Portal. It's unable to resolve _accountname_.file.core.windows.net.

@safihamid
Copy link
Contributor

@MikePennington took a look at the logs, az functionapp deployment include several other config, app settings, ... and cause the process to restart and that's why it takes longer because after restart it's not going to use our specialized process for cold start and that's by design. but it only happens the very first time after a redeploy and subsequent cold starts are fast and should all be well below 1 sec.

@safihamid
Copy link
Contributor

@petro2050 you should be using premium azure files. not sure if portal gives you that option or not. maybe you should do ARM calls to set it up. anyhow we have major improvements being deployed in the next month or so which improves this significantly as long as you have a .zip file and use 'run from package' and will not need premium azure files.

@MikePennington
Copy link

@safihamid Thank you very much for the info!

I have been testing cold-start times throughout the day. The following table shows response time, in seconds, for the function app deployed via the az command and the func command.

time        az          func
5:25PM      1.3         1.2
9:10PM      0.9         1.1
-- REMOVED TIMER TRIGGED FUNCTION --
9:45AM      14.2        4.6
11:45AM     4.5         2.8
1:01PM      3.7         4.3
4:17PM      4.3         4.7

The good news is that they two apps do indeed behave similarly after the first warm-up event after deployment!

I also had a timer-triggered function in the same function app that triggered every 5 minutes. This didn't actually do anything, but I added it because in my testing I found that it helped lower cold start times. After the first two tests I removed this timer trigger and cold start times got much worse.

Based on your experience with Azure functions, are these cold-start times normally expected? Is there anything else I can do to decrease the cold-start time besides adding the timer trigger? Once they warm up these functions return in well under 100ms.

@safihamid
Copy link
Contributor

@MikePennington it's still pretty high, should be around 1 sec and soon it should be even lower. make sure you don't have any extra logging enabled in your host.json file. also make sure you do have compiled and deployed with PublishReadyToRun set to true. feel free to email me your function app code at hamids at microsoft dot com and I will take a look.

@petro2050
Copy link

@safihamid

as long as you have a .zip file and use 'run from package' and will not need premium azure files

Thanks. I will wait for the improvements then.

@vitalybibikov
Copy link

vitalybibikov commented Jun 4, 2020

These are my cold starts for 1 of 4 applications:

Quite far from 1 second:

Deployed as Package.

image

For instance, another one is about to be OK:

image

Both, deployed in the same way, there is no that much difference in resulting package's size.

@safihamid
Copy link
Contributor

@vitalybibikov so you are saying 1 out of your 4 applications has a random long cold start and the rest are well below 500 msec? Do you have any external calls in your apps that might increase your cold start? Feel free to share with me the names of your apps and I can take a look.

@MikePennington
Copy link

MikePennington commented Jun 4, 2020

@safihamid To make sure I'm not doing anything wrong, I went into Visual Studio code and created and deployed a new http-triggered function using the Azure Functions (azuretools.vscode-azurefunctions) VS Code addon. I would assume this would give me the best case scenario for cold starts since its all sample code from Microsoft. Using this auto-generated hello world function, I get the following results:

time		seconds
9:12AM		10.6 <= Assuming this is the first-time startup penalty
10:10AM		1.4
11:07AM		1.2
2:10AM		1.4
2:32AM		2.2

I am on a mac, so using PublishReadyToRun into a windows function is not an option. The mythical sub-second cold start time seems elusive to me.

@safihamid
Copy link
Contributor

@MikePennington yes 1.4 sec is about right and soon it will be even much lower and in the sub-second range. the 2.2 sec is most likely the azure files latency and will go away soon as well. if your project has more complex code, you will need to publish with PublishReadyToRun enabled or else you will pay the JIT cost during cold start.

@vitalybibikov
Copy link

vitalybibikov commented Jun 15, 2020

@safihamid
The one that is most affected is "loyaltyprogram-dev" function app

I can see 30 seconds cold starts from time to time. As I"ve mentioned before.

@vitalybibikov
Copy link

Hi @safihamid,

Have you found anything specific?

@jcageman
Copy link

We are seeing very long startup times (30+ seconds) during scale out of our function app within an appservice plan. Any suggestions to analyse such long startup times? We noticed that it does decrease with better hardware, but we would expect 2-3 seconds at most.

@a-vishar
Copy link

Went through this with Azure Support recently. Even on Premium we see the 30+ second times seemingly randomly (host still available and serving traffic and no spike in calls/resource consumption)... Advised to move to dedicated, but that the "Expected" cost of up to 1.5 seconds will still be present there.

@jeffhollan
Copy link

@a-vishar do you have any info you can share on this one? For premium we do all you to define the pre-warmed buffer where we should be pre-emptively scaling and warming apps for you, even custom containers.

@a-vishar
Copy link

@jeffhollan - I have an open case with support (120061622003116). If you require specific information to help you debug, please do reach out.

@judyanndixon
Copy link

I've seen similarly horrendous startup times with http-triggered dotnet function apps (10+ seconds) and have tried everything I've found online and then some to bring it down. The best option I've found is actually to use the func azure functionapp publish command instead running dotnet publish and az functionapp deployment source config-zip yourself. I don't know what kind of magic it is doing under the hood, but my cold starts now average out to just a little under 2 seconds.

I also got better cold starts using func azure functionapp publish with a simple functionapp that just does a redirect. I was seeing around 15 seconds after a deployment using Visual Studio, with the func azure functionapp publish it was down around 2. Wonder what the one tool is doing that the other needs to be doing?????

@MikePennington
Copy link

@judyanndixon I went pretty deep down this rabbit hole a few months back. Here's what I learned:

There are two different levels of cold start times. "First time ever called" cold start and "normal" cold-start. Best I can tell is that the only difference is that func azure functionapp publish pre-warms the function where az functionapp deployment does not. This removes the penalty of the "first time ever" penalty. Once they have both sit for a while I've seen similar cold start times between the two deployment methods.

The best way I've found to reduce unacceptable cold start times in Azure functions is to add this:

        [FunctionName("keepalive")]
        public void KeepAlive([TimerTrigger("0 */10 * * * *")]TimerInfo myTimer)
        {
            // Do nothing, this is used to improve cold-start time
        }

@judyanndixon
Copy link

judyanndixon commented Oct 10, 2020 via email

@antonysmith-mando
Copy link

@safihamid is the above suggestion - re: using a TimerTrigger to keep a Consumption plan Function App warm - a valid one?

I have added a TimerTrigger to my Function App for this purpose. I can see that the function executions are logged every 5 minutes, but that the AppDomains remains at 0:

Function executions, steady line at 1 execution through the night:

image

However, Total App Domains is 0 during this time:

image

This results in a cold start being experienced as part of the first request of the day.

Sorry to drag up a (very!) old thread, but would be very interested to know if this is expected behaviour, or if there's something wrong with my setup.

Thanks!

@safihamid
Copy link
Contributor

That is one way but there are many other ways to make sure you are getting best cold start. check Risk Alerts in Azure portal for your app and see if there are any suggestions to improve cold start of your app. Are you deploying with Ready2Run? Are you using WEBSITE_RUN_FROM_PACKAGE=1 if running on Windows? ...

@antonysmith-mando
Copy link

antonysmith-mando commented Sep 20, 2023

Thanks for getting back to me.

I am running from a package, not sure about R2R, would have to check.

However, the idea of me using a TimerTrigger is to keep the Function App warm and avoid the cold start, rather than improve it. Is that not achievable?

For instance, see the log extract below. You can see that my timer function runs at 09:45:00 and my HTTP function is run at 09:45:16 and 09:48:40. All 3 invocations are are on the same instance. My intention behind running the timer trigger is for no cold start to be observed on the HTTP function in this scenario, but the first call to it is ~4x slower than the first. Is this indicative of cold start? And can this be avoided in the way I am trying to avoid it?

image

Many thanks for your support.

@safihamid
Copy link
Contributor

The fact that your timer trigger and http Function landed on same instance means the timer trigger did the job of cold starting your function app for the Azure Functions platform. Meaning your instance was assigned, your zip package was downloaded and extracted, the env variables and app settings for your app where applied, ...

The fact that your 1st http trigger still took longer means your timer trigger didn't exercise much of your own code needed for your http trigger execution.

Is this a .NET app? if yes, most likely time was spent JITting your code. did you need to setup some outbound connections? the more of your code you exercise in your timer trigger the less time spent on your very 1st http trigger.

The concept is very similar to Azure Function warmup triggers documented here: https://learn.microsoft.com/en-us/azure/azure-functions/functions-bindings-warmup?tabs=in-process&pivots=programming-language-csharp

But keep in mind warmup triggers are only supported for Premium and App Service plans and are not supported for consumption. but you can implement same logic for your custom timer trigger code.

@antonysmith-mando
Copy link

@safihamid thanks very much for your detailed response.

I've had a look back at the cold start times before I added the TimerTrigger and these look to generally be in excess of 2s - double what they are now.

If I understand what you're saying correctly, that's because:

  1. The TimerTrigger is now ensuring that the instance is warm, and the environment prepared
  2. But there's still work to do to warm up the specific code in my HTTP trigger that hasn't been warmed by what the TimerTrigger does (which is nothing more than log a message that the function was executed)

The former is why I'm seeing a ~50% improvement, but the latter is why I'm still seeing some slowness on the first request to the HTTP trigger.

The HTTP function in question is made up of primarily C# calculation logic. The only dependency is on Azure Blob Storage for config files - there are no other outbound calls. Am I right in thinking that the platform should be keeping that connection warm for me? In which case the time being taken on first invocation is purely for JITing the code and I think my next approach would be to warm up the HTTP trigger function itself.

Thanks for your help!

@safihamid
Copy link
Contributor

yep, maybe easiest is to fake call all the logic that you have in your http trigger function into your Time Trigger so all code paths are JITted and warmed up? And make sure you deploy with Ready2Run to minimize overall JIT time.
Do you call into Azure blob storage on your http trigger? if yes that code needs to be warmed up as well.

@antonysmith-mando
Copy link

antonysmith-mando commented Sep 21, 2023

I think it may actually be easier for me to just call the real HTTP function. Its execution is reliant on all of the config files from Blob Storage being present and it will fail fast if they're not. So I'd need to also provide all of those to my TimerTrigger in order to warm up all of the code paths, in which case I may as well just run the real thing (otherwise I'd be basically duplicating this specific HTTP function within the TimerTrigger function, which wasn't my intention, it was to have a generic 'keep-alive' function, which I now understand isn't completely valid because the function-specific code still needs to be warmed).

The function is executed on submission of a web form, so I should be able to eagerly call the HTTP function with a dummy request on load of the form, meaning that warm up has occurred prior to submission of the form and the 'real' invocation.

As part of this work, I will ensure I've got R2R set up and will enjoy the additional benefits that brings for cold start times. Thanks again for all of your help.

@safihamid
Copy link
Contributor

Yep, sounds like a good plan. We in Azure Functions team are constantly working on improving Functions cold start specially what is related to the cold start of the platform itself. In fact in the past few months, we improved the platform cold start by ~40% in most regions. the deployment is still ongoing.

But if cold start is related to the specific Function code itself, you need to make sure zip package is minimized by removing all unnecessary content, the code is compiled with Ready2Run or AOT compiled and follow all the guidance of cold start Risk Alerts if any that we show on the portal under Diagnose & Solve problems. And don't forget about warmup triggers if running in premium or App Service plans.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests