global-asaxweb-farmserver-farm

How does global.asax function in server farm?


I'm confused as to how the global.asax file would run in a server farm. Does each server have its own instance running or is it a shared instance.

For example in my global.asax in the Application_Start event I initialize a singleton object that collects stats and updates a database table containing the stats. Which of the following happens?

Scenario One

It the first example each server would update the database with it's own collection

Scenario Two

It the above example the servers have access to the same collection. Is this possible?


Solution

  • The servers are not aware of each other, so the global.asax file runs separately for each process and server. This is true even if you setup IIS to allow multiple worker processes on the same site and same machine. Each worker process will have its own global.asax Application_Start().

    So to answer your question directly, Scenario One would more closely model what would actually happen in a web farm.

    If you want the "singleton" to be shared across all servers, you will have to implement a service that all servers can share.