Using application context with multi worker process setting.

N

nicerun

I'm using the Application_Start event at Global.asax.cs to invoke
thread that do some job.
I know that Application_Start event occurs when the very first request
to Web Application received.

- Setting worker process count
1. Start | Programs | Administrative Tools | Internet Information
Services
2. Right-click on the application pool, e.g. ‘DefaultAppPool’, and
select ‘Properties’
3. In performance tab you can change the worker process count

In case of 1 worker process it works fine. Only one thread runs.

But in case of multi process. The count of thread is same as the count
of processes.
I thought that the Application_Start event occurs in every process.

Is this behavior is natural or I've been using Application_Start in
wrong way?

Thank you.
 
B

bruce barker

there are 3 thing to know:

appPools host web sites.
each appPool has 1 or more worker processes that process the requests
each worker process hosts an appdomain that runs the website code.

an appdomain has a thread pool. when a request comes a thread from the
pool is used. if its the first request for the appdomain the application
start event is run. during the processing of a request, the processing
thread can be returned to pool, and another used to complete the request
(thread agility). as each appdomain is seperate memory, application
start is run to allow initialization of this memory.

if you change a file in the website, the appdomain that represents the
site is shutdown (after completing all pending requests) and a new
appdomain is started at the next request and will fire application
start. if the request comes quick enough, both domain can run at the
same time. this is why if logged you can see both start events before
the first end event

if you set up 2 worker process per appPool, then an appdomain in each
worker process will be created for each website in the pool (at when the
sites are active) and an application start will be run in each worker
processes. in this case a recycle on a busy site can could have 4
appdomains each running your background thread at the same time.



-- bruce (sqlwork.com)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top