According to Apache documentation:

The Keep-Alive extension provides long-lived HTTP sessions which allow multiple requests to be sent over the same TCP connection.

What is the definition of "same TCP connection", is that meaning the same unique user visiting me web site?

If I have KeepAliveTimeout 5, is that meaning that user will have to re-establish a connection to my httpd after 5 secs?

Please help me to clearify the puzzle in my head, thank you.

    Don't think users, think individual http transactions. Remember, every single embedded image is a completely different http transaction, as are the components of frames. The point of KeepAlive isn't to try to give you (the server-side programmer) the ability to somehow maintain state via a persistent tcp connection, but rather to cut down on the overhead of making and breaking multiple tcp connections just to get a single page (or quick series of successive pages) loaded.

      The terminoloy is really confusing.

      What the differences between "TimeOut" and "KeepAliveTimeout"?

      In MaxClients, StartServers, MaxRequestsPerChild, what is the definition of "clients", "servers", and "child"?

      Are they all referring to the same thing, the "httpd" process?

      What determines the size of httpd process in memory? Each of my httpd process is occupying 16M, is that too much? How do I adjust the size of it?

      Thank you.

        One of the main reasons for Apache's reliability is its overall design. I hope I have all the details right here, but at any rate the overall picture is accurate:

        There is one overall server process that listens on port 80. This master server creates 'StartServers' child process to handle the actual requests, and hands off each incoming request to a child in a round-robin fashion. (I.e. to the next available child process.) If no child is available, the master server will start another child to handle the request, up to the absolute max of 'MaxClients'.

        Here's where the reliability part comes in: after a child handles 'MaxRequestsPerChild' http request, it dies, freeing up any memory or other resources in use. A runaway module (including user-written perl using mod_perl or php programs using mod_php) that allocates memory without every freeing it will nevertheless not be able to bring down the whole machine.

          After 12 hours, when I use the 'top' command to check my server status, each httpd is using 365M of memory.

          What's the cause of this? How do I fix this?

            Whoa! That's a lot.

            (1) What are the relevant variables in httpd.conf set at?

            KeepAlive
            MaxKeepAliveRequests
            KeepAliveTimeout
            MinSpareServers
            MaxSpareServers
            StartServers
            MaxClients
            MaxRequestsPerChild

            (2) Are you using a persistent connection to your database? Try using the non-persistent connection instead.

            (3) What OS are you hosting this on?

              (1)

              KeepAlive on
              MaxKeepAliveRequests 50
              KeepAliveTimeout 2
              MinSpareServers 5
              MaxSpareServers 10
              StartServers 250
              MaxClients 700
              MaxRequestsPerChild 100

              (2) I don't think I using persistent connection to my database at this moment.

              (3) Red Hat Linux 6.1

              Each httpd process starts with 4M in size but ended up growing to large.

              This server is receiving over 5 millions page requests per day, how should I tune these setting?

              By the way, I'm issuing "kill -USR1 cat /var/run/httpd.pid" every minute to restart the server for my log rotation purpose.

                This makes no sense to me, but I'm not really an Apache expert. Mind if I refer this to someone I know?

                  That would be great.

                  I was wondering if the command kill -USR1 /var/run/httpd.pid is preventing the httpd from dying out.

                  My httpd is growing larger and larger every time I restart apache.

                  Following is my latest configuration, which is still having this problem:

                  TimeOut 10
                  KeepAlive on
                  MaxKeepAliveRequests 50
                  KeepAliveTimeout 3
                  MinSpareServers 5
                  MaxSpareServers 10
                  StartServers 10
                  MaxClients 600
                  MaxRequestsPerChild 50

                  Thank you for your help.

                    OK, here's the first installment from my friend:

                    I have only dealt with servers that are in the low 1 million
                    page visits per day, so what I have for settings may not be
                    entirely correct for his. On that note, is he using the
                    standard apache rpm's that got installed with the base 6.1?
                    If so, he REALLY needs to compile from source.

                    Is he running any php or perl (cgi) that has possible runaway
                    code? How much ram does he have in the machine? Our servers
                    that get > 1 million hits have at the very least 1 gig of ram.
                    For one machine, its just barely enough.

                    This site also has some good guidance for tuning apache:
                    http://perl.apache.org/guide/performance.html
                    #Performance_Tuning_by_Tweaking_A

                    [Join these two lines! It looked too long on phpbuilder'd edit box...]

                    I am concerned about his statement that he runs a "kill pid"
                    for log rotation every minute! There are external programs
                    that can be written for log rotation that will not interfere with
                    apache.

                      I think I found the problem.

                      I was performing a log rotation script every minute via external system call from my script. This problem only exist when I use the "kill pid" to reset the log files. The httpd just kept growing larger and larger.

                      However, if I change it to "httpd restart", everything becomes normal again, the size of each httpd is never over 7M.

                      Do you know why? I've heard that "kill pid" will give me the minimum down time for apache.

                      You metioned there's external programs that can be written for log rotation that will not interfere with apache, can you give me more info about that?

                      By the way, I'll take some time to look at the tuning guidance to optimize my server performance.

                      Thank you for your help 🙂

                        Write a Reply...