microsoft / IIS.ServiceMonitor

An entrypoint process for running IIS in Windows containers
MIT License
127 stars 39 forks source link

PERF: Each call to AppCmd.exe takes 130 - 280ms #9

Closed pharring closed 6 years ago

pharring commented 7 years ago

From my local testing (SSD with a recent RS3 image), each call to AppCmd.exe takes between 130ms and 280ms. Can we do better?

Each (non-filtered) environment variable results in two calls to AppCmd (one to remove it if it's already there, then another to add), that's 260ms, at best, per environment variable added.

One improvement would be to batch multiple changes together. AppCmd.exe does allow multiple writes in a "set config" command but it will error out if any of them fail. That includes the attempted removal of non-existent elements. So, we could batch together the add commands, but not the remove commands (since they are expected to fail).

A (radical) alternative is to avoid calling AppCmd.exe altogether and doing the applicationHost manipulation directly in ServiceMonitor.exe

shirhatti commented 7 years ago

Ahh sorry for not creating a tracking bug. See https://github.com/Microsoft/IIS.ServiceMonitor/tree/mcy94w/CallAppcmdOnce for a WIP

pharring commented 7 years ago

@Shirhatti thanks for taking a look. If I read it correctly, that will batch together all the removes. As I mentioned above, when I tried it myself on the command line, I found that AppCmd would error out without making any modifications if just one of the removed items didn't exist. One other consideration, when it comes to testing this: If there's a large number of environment variables, we will end up with a very long command line. We should make sure that AppCmd.exe can cope. There might be a limit.

Do you have insight into the inner workings of AppCmd.exe? Is it out of the question to make modifications there or to build a custom version that can be 'scripted' or given a sort of 'response' file?