Quantcast
Channel: Configuration & Scripting
Viewing all articles
Browse latest Browse all 780

IProcessHostPreloadClient doesn't know which application it's running for - causes unnecessary load

$
0
0

Hi,

We have an issue where we have several applications hosted under the same site in IIS, and several of them have relatively expensive operations that happen daily (pre-calculating and caching info mostly) that we like to do at off-hours rather than first use (which punishes the first user).

So, we've tried using IProcessHostPreloadClient... trouble is, we have around 30 application pools, and an application pool, though assigned to a particular application in the IIS configuration, doesn't know which application it's been assigned to -- so there is no way (I can find) to determine whether or not we should run the expensive operation in a particular application pool from inside the IProcessHostPreloadClient.Preload function.

For instance, if you have a pair of WCF services applications -- say a multiply application and an addition application both hosted under a main site bound to port 80. Both applications are set to always running and to start automatically, you've implemented IProcessHostPreloadClient for both, one to store the multiplication tables to 100, and one to store addition tables to 100 to speed service response. You've got 2 application pools, one for each. When you start the pools both pools will run both IProcessHostPreloadClients (you might think that the configuration of the clients - one per site -- would lead IIS to be a little smarter about which ones get run based on which is configured for the site the app pool is starting for -- you'd be wrong!) and you'll find you do more work than you want to.

I've tried pretty hard to determine which app pool I am. Trouble is you have to be running as an admin to query IIS for the associations between application pool names and their identities -- everything I've tried gives me the application name, not the app pool name. AppDomain.CurrentDomain for instance is about what application I am, not which app pool I am. From what I can tell I have to do something like this -- but I'd much prefer not to run app pools as admin (seems dangerous doesn't it?). Another option might be to run every app pool as a different user and then just look up our user id. This probably isn't reliable (and definitely isn't scalable -- we actually have over 30 applications so this would be an unpleasant meeting with the folks that set up users).

(I'm currently trying to punt and add an application setting to the web.config to determine if/which autostart should run... hope that works... but would appreciate any help or ideas).

[Update] web.config doesn't work -- the configuration manager presents the config per-application, so in the above example, during preload both add and multiply application pools use multiply's web.config when multiply's preload is called and use add's web.config when add's preload is called.

Smiley-face to the robo-post telling me this is the wrong forum, please reboot, have you tried looking at the documentation (which is poorer for IIS than some of the other Microsoft stuff), etc... from the poor Microsoft person that has to post some sort of response within 24 hours here -- I feel your pain for the legislative burden (this is clearly not a level 1 support question)!

 thanks, Andrew

Some code:

             try {
                int ourpid = System.Diagnostics.Process.GetCurrentProcess().Id;
                using (ServerManager serverManager = new ServerManager()) {
                    foreach (ApplicationPool ap in serverManager.ApplicationPools) {
                        if (appPoolName.Equals(ap.Name)) {
                            foreach (WorkerProcess wp in ap.WorkerProcesses) {
                                if (ourpid == wp.ProcessId) { // requires admin privilege, dang!
                                    Logging.log.Info("We have found ourself!!!");
                                }
                            }
                        }
                    }
                }
            } catch (Exception ex) {
                Logging.log....

            }


Viewing all articles
Browse latest Browse all 780

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>