|
Threading and ASP/IIS by Charles
Carroll
Threads - Worker Bees of the Web Site
All the work done by a webserver is handled by
threads.
Threads are the worker bees of the
web server.
Like any employees you want them working hard!
Any ASP script running on the
webserver runs on a given thread. If for example, 100 scripts are requested an IIS
has 4 threads to service them typically each thread will process 25
scripts.
Think of threads as cashiers at McDonalds or at
the supermarket. 4 cashiers could handle 4 customers simultaneously.
In IIS4, the default is 4 threads (which is
simply a registry setting) in initial install but extensive real-world testing
on Microsoft.com and hig volume sites indicated 20 per CPU would be ideal.
example:
100 scripts arrive at a web-server with 4 threads. 4 scripts run simultaneously,
round-robin style ala:
http://www.learnasp.com/advice/roundrobin.asp
and eventually the 4 threads would probably handle 25 requests each.
100 scripts arrive at a web-server with 20
threads. 20 scripts run simultaneously, round-robin style ala:
http://www.learnasp.com/advice/roundrobin.asp
and eventually the 20 threads would probably handle 5 requests each.
In IIS5 / Win2000 that registry setting is
irrelevant. IIS5 dynamically changes the number of threads processing ASP
scripts as needed to optimize performance.
IIS4 / NT4 TIP:
Increase threads from 4 to 20 for each CPU!
thanks to Smiling Jack for this one:
http://www.aspmagazine.com/aspmagazine/issue10kb.asp
see
http://support.microsoft.com/support/kb/articles/q196/0/16.asp
for more details.
Thread Affinity - Enemy of Scalability
Since a request can normally be serviced by any
available thread it is like "hopping lines" at cashiers to get to the
shortest line. Usually that is true. If a thread finishes its request it just
grabs the next waiting script UNLESS the request has thread affinity (which Ted
Pattison famed VB author calls a monagomous thread) in which case no matter how
many threads are idle the request must wait for the specific thread it has
affinity too. Don't make your requests have thread affinity (more on how they
can be screwed up this way @
http://www.learnasp.com/advice/dbsessionapp.asp)
Read Up on Threads! Have an
Aspirin Ready!

Threads can affect ASP in several ways
|