Pergunta

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

  • Server 1 -> (Stat = 10) -> Updates database with 10
  • Server 2 -> (Stat = 8) -> Updates database with 8
  • Server 3 -> (Stat = 25) -> Updates database with 25
  • Server 4 -> (Stat = 5) -> Updates database with 5

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

Scenario Two

  • Server 1 -> (Stat = 10) -> Updates database with 10
  • Server 2 -> (Stat = 10) -> Updates database with 10
  • Server 3 -> (Stat = 10) -> Updates database with 10
  • Server 4 -> (Stat = 10) -> Updates database with 10

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

Foi útil?

Solução

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.

Outras dicas

Another option is to use a ScaleOut State Server (SOSS), which I have seen being used in high availability environments.

[This] runs on every server within a Web or application server farm to store mission-critical, workload data. ScaleOut StateServer’s in-memory data grid with integrated, in-memory distributed caching provides extremely fast access to your critical but fast changing data, and its performance and capacity grow as you add servers to the farm. The software automatically replicates stored data between servers so that critical data are not lost if a server fails, and it maintains scalable, highly available access that a standalone database server (or even a failover database cluster) cannot duplicate. You can also use the Windows version of ScaleOut StateServer to transparently save and retrieve ASP.NET session-state.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top