Skip to content

Conversation

@AnatoliB
Copy link
Contributor

@AnatoliB AnatoliB commented Sep 3, 2020

Resolves #485

  • The first PowerShell instance creation is moved to Worker.Main, and it is now performed immediately after starting the process, not waiting for the function load request. It is important to remember that at this point we cannot initialize $env:PSModulePath because the app root path is not resolved yet. So, for the first PowerShell instance, this step is deferred until the function load request and performed in RequestProcessor.SetupAppRootPathAndModulePath. For all the subsequent PowerShell instances, $env:PSModulePath comes from the initial session state, as before.
  • Handling the function load request involves creating a PowerShell function from a script file (see PowerShellManager.DeployAzFunctionToRunspace), and this takes hundreds of milliseconds even for a short script when performed for the first time. However, the subsequent invocations are significantly faster. So, creating and removing a dummy function proactively saves noticeable time on the function load request (see Worker.WarmUpPowerShell).

This reduces cold start time by about 4 seconds (measured on App Service plan, S1 instance):

Stage Before the change (ms) After the change (ms)
Function load request 3700 200
First function invocation request 2200 1700
Total 5900 1900

@AnatoliB AnatoliB changed the title Placeholder warmup Warm up PowerShell Worker before receiving function load request Sep 3, 2020
@AnatoliB AnatoliB marked this pull request as ready for review September 3, 2020 06:42
Copy link
Contributor

@Francisco-Gamino Francisco-Gamino left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @AnatoliB for sending this out!

A couple of minor comments. Other than that, LGTM.

@AnatoliB AnatoliB merged commit 17d93dc into Azure:dev Sep 3, 2020
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

Successfully merging this pull request may close these issues.

Warm up PowerShell Worker before receiving function load request

2 participants