1a.
APC cache was the quickest way to get the most improvement in speed on my server. Memcached is also an option, but only has benefits above APC when you can distribute the caching load to backend servers or if you have multiple front-end servers.
1b. Squid. See
Squid (software) - Wikipedia, the free encyclopedia. You put your LAMP server on another port, and proxy it using SQUID. Squid will cache as much as can be cached and fetch from your LAMP server. If most of your content is dynamic, this may not help much.
2a. You absolutely must minimize swap in such an environment. If you start going to swap, your system loses.
In sysctl.conf, change:
vm.swappiness = 1
and "tune" your swap to use a swap file that's about 80M. If you need more swap then that, your system will crash. Better to let Apache think it cannot get more memory and return 503 (server busy) errors than to wait forever.
2b. You can play around with the following:
- MinSpareServers # keep this at least 5 or 10.
- MaxSpareServers # no problem to set this 1/4th max.
- ServerLimit # set to what your server can handle, memory-wise
- MaxClients # Set to what your server can handle, memory-wise
- KeepAlive # keep on
- KeepAliveTimeout # keep to 30 seconds or less
- HostnameLookups # set to OFF
2c. More tuning at the TCP level. See sysctl parameters such as:
- net.core.somaxxconn
- net.core.netdev_max_backlog
- net.ipv4.tcp_keepalive_intvl
- net.ipv4.tcp_tw_reuse
- net.core.optmem_max
- net.core.rmem_max
- net.core.wmem_max
- net.ipv4.tcp_rmem
- net.ipv4.tcp_wmem
- net.ipv4.tcp_congestion_control
Also, LOWER the amount of shared memory, to ensure you have more memory for HTTP. (Note: This may not work if you are running MySql or postgres on the same server!)
- kernel.shmmax
- kernel.shmall
2d. If you have the memory, put all your HTTP/PHP files onto a ramdisk. Otherwise, install everything on a FAST internal (or SAN) disk. When I say FAST, I mean hardware-RAID1 15k RPM SCSI Fiberchannel. Store all log files on a SEPARATE disk, which can be any junk drive.