Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I'm aware of the Apache directives MaxClients and ListenBacklog. I'm trying to set a limit of, let's say 100 concurrent connections after which the new connections will be served a static page. Can this be done? Should MaxClients and ListenBacklog be higher or lower than that limit? How can I test it?

share|improve this question

2 Answers 2

If Apache can't accept the incoming connection because it's already handling MaxClients, then it can't serve a static page. So, I don't have any hard evidence, but I don't see how you could achieve this with just Apache alone. You might be able to put something in front of Apache which returns a static page if Apache returns a connection failure, but it seems like a lot of complex config to me. Hopefully someone will be along to prove me wrong.

share|improve this answer
    
I believe you are correct; is there a way then to set MaxClients to, let's say, 300, and configure Apache to serve the static page when it reaches 100 simultaneous connections? –  altvali Jun 14 '12 at 9:29
    
Not from within Apache that I'm aware of. Maybe you need to step back from the detailed question, and ask a more general question such as, for busy sites, how do you gracefully handle the situation of exceeding Apache's MaxClients value. –  EightBitTony Jun 14 '12 at 10:55
up vote 0 down vote accepted

Here's how I did it: Let's say that I want to allow X concurrent requests, after which the following Y concurrent requests will stay in a queue, waiting for the frist X to finish, and everything exceeding X+Y will be served a static page:

  1. In httpd.conf the following directives must be set:

    MaxClients X
    ServerLimit X
    ListenBacklog Y
    
  2. Logged as root in MySQL, set max_connections:

    set global max_connections = X
    
  3. Edit the .htaccess file from your server's public root folder:

    ErrorDocument 503 error_503.html
    
  4. Make sure that your error_503.html is served in one request. All stylesheets and scripts must be in this file. If you want to include images, you'll have to use the data uri scheme. Also, you'll have to slice your images up because in IE data URIs have to be smaller than 32KiB.

share|improve this answer
    
I don't how you'd get apache to serve the 503 once the backlog is full. This is a TCP backlog, which is opaque - as far as I know, applications can't even get its size, but can only dequeue from it by accepting connections. –  Kelvin Nov 15 '12 at 20:04

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.