fb

Ads

Pages

Operating System Tuning for High Performance [PHP]

There is a strong argument that if you do not want to perform local caching, then using a reverse proxy is overkill.A way to get a similar effect without running a separate server is to allow the operating system itself to buffer all the data. In the discussion of reverse proxies earlier in this chapter, you saw that a major component of the network wait time is the time spent blocking between data packets to the client.
The application is forced to send multiple packets because the operating system has a limit on how much information it can buffer to send over a TCP socket at one time. Fortunately, this is a setting that you can tune.
 


On FreeBSD, you can adjust the TCP buffers via the following:

#sysctl –w net.inet.tcp.sendspace=131072
#sysctl –w net.inet.tcp.recvspace=8192

 

On Linux, you do this:

#echo “131072” > /proc/sys/net/core/wmem_max


When you make either of these changes, you set the outbound TCP buffer space to 128KB and the inbound buffer space to 8KB (because you receive small inbound requests and make large outbound responses).This assumes that the maximum page size you will be sending is 128KB. If your page sizes differ from that, you need to change the tunings accordingly. In addition, you might need to tune kern.ipc.nmbclusters to allocate sufficient memory for the new large buffers. (See your friendly neighborhood systems administrator for details.) After adjusting the operating system limits, you need to instruct Apache to use the large buffers you have provided. For this you just add the following directive to your httpd.conf file:


SendBufferSize 131072


Finally, you can eliminate the network lag on connection close by installing the lingerd patch to Apache.When a network connection is finished, the sender sends the receiver a FIN packet to signify that the connection is complete.The sender must then wait for the receiver to acknowledge the receipt of this FIN packet before closing the socket to ensure that all data has in fact been transferred successfully. After the FIN packet is sent, Apache does not need to do anything with the socket except wait for the FIN-ACK packet and close the connection.The lingerd process improves the efficiency of this operation by handing the socket off to an exterior daemon (lingerd), which just sits
around waiting for FIN-ACKs and closing sockets.


For high-volume Web servers, lingerd can provide significant performance benefits, especially when coupled with increased write buffer sizes. lingerd is incredibly simple to compile. It is a patch to Apache (which allows Apache to hand off file descriptors for closing) and a daemon that performs those closes. lingerd is in use by a number of major sites, including Sourceforge.com, Slashdot.org, and LiveJournal.com.

0 comments:

Post a Comment