-
Notifications
You must be signed in to change notification settings - Fork 441
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
Comments
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." |
I think I already did this with these steps,
Can you suggest any specific step that I might miss? |
You might be hitting this issue: Azure/azure-functions-core-tools#1086 |
Also we are tracking cold start improvements with these two issues:
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%. |
@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? 🤔 |
@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 :-) |
Glad to hear! :-) |
@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? |
@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. |
@safihamid It's V3.
|
@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: 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. |
I'm on SDK 3.0.3 right now and unable to upgrade due to an issue with
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. :) |
@petro2050 not sure about that issue, @fabiocav do you know why he can’t upgrade to 3.0.5, have you seen above error? |
@fabiocav Any input with regards to the JWT issue would be appreciated. |
@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.
Still can't deploy with the settings below:
with error:
|
@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. |
Hi, @safihamid It actually works locally, so with RID I can run the function and it operates (locally) |
@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 Here is how your .csproj file should look like: `
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: |
@safihamid Whoa, thanks, not easy to spot this one |
And the reason why I'm using x64 is that x86 currently does not work. OS: Win10 How to repro:
And you will get: If I switch it to x64, it starts.
Might it be that recently cli goes x64 by default, I haven't checked yet. |
The reason is that default "Platform Target" for Azure Functions projects is now x86. However, it starts in the Cofiguration of win-x86 + Any CPU
So, the only possible configuration is win-x64 + target x64, Unfortunately. |
@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? |
Unfortunately, no.
In Azure:
|
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 |
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 |
@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. |
@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. |
Thanks @safihamid, I'd love the help! As I mentioned above, I see much better results when I deploy using the 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 Using |
@safihamid It says premium storage accounts only support page blobs. Don't I need file shares with Azure Functions? When I try to create a function app with premium storage, I'm getting |
@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. |
@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. |
@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
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. |
@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. |
Thanks. I will wait for the improvements then. |
@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. |
@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:
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. |
@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. |
@safihamid I can see 30 seconds cold starts from time to time. As I"ve mentioned before. |
Hi @safihamid, Have you found anything specific? |
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. |
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. |
@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. |
@jeffhollan - I have an open case with support (120061622003116). If you require specific information to help you debug, please do reach out. |
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????? |
@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 The best way I've found to reduce unacceptable cold start times in Azure functions is to add this:
|
Good to know. Thanks!
…Sent from my iPhone
On Oct 9, 2020, at 4:02 PM, Mike Pennington ***@***.***> wrote:
@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
}
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or unsubscribe.
|
@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: However, Total App Domains is 0 during this time: 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! |
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? ... |
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? Many thanks for your support. |
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. |
@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:
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! |
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. |
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. |
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. |
Investigative information
Please provide the following:
Repro steps
Provide the steps required to reproduce the problem:
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
https://drive.google.com/file/d/1FzEm9QLNeOj5eJlv_U64kuRpw-nIOb8f/view?usp=sharing
Source
The text was updated successfully, but these errors were encountered: