You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@httpd.apache.org by Brian Behlendorf <br...@organic.com> on 1995/10/10 22:15:52 UTC

Hints on running a high-performance web server (fwd)

I added his comments to docs/perf.html and docs/virtual-host.html - what 
do you think about his patch to add setrlimit() calls?  I think it 
determine the value to set NOPROC_LIMIT to either be a config file call 
or a multiple of the number of virtual hosts used....

	brian

--=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=--
brian@organic.com  brian@hyperreal.com  http://www.[hyperreal,organic].com/

---------- Forwarded message ----------
Date: Tue, 10 Oct 1995 13:29:42 -0600
From: Aaron Gifford <ag...@InfoWest.COM>
To: brian@organic.com
Subject: Hints on running a high-performance web server

Hi,

I noticed that on performance hints page (http://www.apache.org/docs/perf.html)
you mention a problem with the listen() queue under Linux.  I've also seen
this problem under BSD/OS 1.1 (the old version from BSDI) and under FreeBSD
2.0.5.  The fix was the same on both machines:


Edit the following two files:
  /usr/include/sys/socket.h
  /usr/src/sys/sys/socket.h

In each file, look for the following:
    /*
     * Maximum queue length specifiable by listen.
     */
    #define SOMAXCONN       5

Just change the "5" to whatever appears to work.  I bumped the two machines I
was having problems with up to 30 and haven't noticed the problem since.

After the edit, recompile the kernel and recompile the apache server then
reboot.

Another problem I had was encountering resource limits for the number of
processes allowable on the system for the user under which the server
was running (I run apache as a standalone and start it as root, then
the server becomes user "http" on my system).  I lame fix for this was to
edit http_main.c and at the top of the "main()" function add some setrlimit()
calls at the top.  No effort was made to make this any sort of general
solution, just a quick fix for the problem on my system.

Here's what mine looks like:
    int
    main(int argc, char *argv[])
    {
        int c;
        struct rlimit rlp;
    
        rlp.rlim_cur = rlp.rlim_max = 350;
        if (setrlimit(RLIMIT_NPROC, &rlp)) {
            fprintf(stderr, "setrlimit(RLIMIT_NPROC) failed.\n");
            exit(1);
        }
        rlp.rlim_cur = rlp.rlim_max = 512;
        if (setrlimit(RLIMIT_NOFILE, &rlp)) {
            fprintf(stderr, "setrlimit(RLIMIT_NOFILE) failed.\n");
            exit(1);
        }



One of the symptoms of the resource limitation was seen as a failure of many
external cgi scripts and an error_log entry that mentioned the inability
to fork.  I also fixed a problem that didn't exist on my systems (or at least
I hadn't noticed it causing problems) by also doing a setrlimit() to boost
the no. of fd's allowed.  I probably didn't need to do the second setrlimit().

On a REALLY heavily used system, an additional change or two to the kernel
might be necessary to increase the overall system resource limits compiled
into the kernel.

DISCLAIMER:
While I do operate a few BSD based systems (running on Pentiums), I'm still
a newbie to the BSD 4.3 and 4.4 systems and have only lightly browsed a few
of the kernel source files, so I'd be HAPPY to hear of better ways to do
what I've done.  Likewise, feel free to let me know what I might have done
wrong.

Thanks,
Aaron Gifford
InfoWest Networking
<ag...@infowest.com>


Re: Hints on running a high-performance web server (fwd)

Posted by Tony Sanders <sa...@bsdi.com>.
Brian Behlendorf writes:
> I added his comments to docs/perf.html and docs/virtual-host.html - what 
> do you think about his patch to add setrlimit() calls?  I think it 

An alternative is to create a shell script (e.g., /usr/local/bin/relimit):
    #!/bin/sh
    limit maxproc 512
    limit openfiles 512
    limit datasize 32m
    exec "$@"

And start the server using that script:
    relimit apache -myflags ...