HTTP Error 503 – Service is unavailable (how fix?)

iis-7.5windows-server-2008-r2

i have a web site for download mobile files and there many users in my web site.
sometimes i have the error below :
HTTP Error 503 - Service is unavailable

1-so why this error happens and what is that mean?

2-as i know appache free up itself when it's oveloaded, but what about iis?

how can i put some limitations in my server (i have remote access to my server) for prevent this error happening?

a.is limitation of dowload's speed efficient for prevent that error's occur?
how can i do that?
is squid useful for this job or i can do that with another iis extension.

b.is limitation of download's Bandwidth efficient for prevent that error's occur?
how can i do that (with iis or another extension)?

in right side of iis -> configure area -> i found some limits.
what do those limits mean and can i use them for keep my server alive all the time?

EDIT:
after viewing event viewer of windows -> custom views -> server rols -> web server (iis)
i figure out there is no error in that area.
but many warnings and information.
the latest warnings and information are like below :
warning

A worker process '2408' serving application pool 'ASP.NET 4.0
(Integrated)' failed to stop a listener channel for protocol 'http' in
the allotted time. The data field contains the error number.

warning

A process serving application pool 'ASP.NET 4.0 (Integrated)' exceeded
time limits during shut down. The process id was '6764'.

warning

A worker process '3232' serving application pool 'ASP.NET 4.0
(Integrated)' failed to stop a listener channel for protocol 'http' in
the allotted time. The data field contains the error number.

warning

A process serving application pool 'ASP.NET 4.0 (Integrated)' exceeded
time limits during shut down. The process id was '3928'.

thanks in advance
best regards

Best Answer

My guess is that you are hitting the limit of available threads that IIS has available. IIS allocates a certain number of threads depending on the version of IIS and the configuration settings which by default depend on the number of processors/cores in your server. You can tune this specifically to your needs.

You probably run out of threads because you stream downloads to the clients. If you do this in a synchronous way your website will eventually run out of the threads as each thread will be occupied by a single download. If possible you should modify your download code to work asynchronously, e.g. by implementing it as a asynchronous HTTP handler.

EDIT: The 503 error is occuring because IIS is running out of threads to service additional requests and thus can't handle the request. The errors in the event log are a consequence of this as IIS is trying to free up threads and resources by trying to quit/recycle the application pool as it's not responding to the internal 'alive' pings.

Limiting the download speed will actually increase the problem as you will run out of threads even sooner. You should only limit the download speed if you run out of total bandwidth, otherwise just let clients download as fast as they can.

The only real solution that will make your server scale is to change your code so that downloads are handled asynchronously. Or change your solution so that the download is handled by the static file handler of IIS itself, for example by using rewrite rules or a custom rewrite provider. Difficult to say anymore without knowing a bit more details about your application.