25 apache performance tips

26
25 Apache Performance Tips www.monitis.com

Upload: monitisinc

Post on 17-Dec-2014

382 views

Category:

Technology


1 download

DESCRIPTION

SysAdmins love Apache. It allows one to run websites on the Internet with minimal configuration and administration. However, this fexibility and simplicity is what typically leads Apache to become a memory hog. Utilizing these easy to understand tips, you can significantly boost Apache's performance.

TRANSCRIPT

Page 1: 25 Apache Performance Tips

25 Apache Performance Tips

www.monitis.com

Page 2: 25 Apache Performance Tips

25 Apache Performance Tuning Tips www.monitis.com Uptime & Device Monitoring

1. Remove unused modules

Save memory by not loading modules that aren’t needed, including (but not limited to)… … mod_php, … mod_ruby, … mod_perl, etc.

Page 3: 25 Apache Performance Tips

25 Apache Performance Tuning Tips www.monitis.com Uptime & Device Monitoring

2. Use mod_disk_cache and NOT mod_mem_cache

Mod_mem_cache will not share its cache amongst different apache processes, which results in high memory usage with little performance gain. On an active server mod_mem_cache will rarely serve the same page twice in the same Apache process.

Page 4: 25 Apache Performance Tips

25 Apache Performance Tuning Tips www.monitis.com Uptime & Device Monitoring

3. Configure mod_disk_cache with a flat hierarchy

Make sure you are using CacheDirLength=2 and CacheDirLevels=1 to ensure htcacheclean will not take forever when cleaning up your cache directory.

Page 5: 25 Apache Performance Tips

25 Apache Performance Tuning Tips www.monitis.com Uptime & Device Monitoring

4. Setup appropriate Expires, Etag, and Chache-Control headers

In order to utilize your cache you have to specify when a file expires, otherwise your client will not experience the caching benefits.

Page 6: 25 Apache Performance Tips

25 Apache Performance Tuning Tips www.monitis.com Uptime & Device Monitoring

5. Put the cache on a separate disk

Move your cache to a separate physical disk for the fastest access without slowing down other processes.

Page 7: 25 Apache Performance Tips

25 Apache Performance Tuning Tips www.monitis.com Uptime & Device Monitoring

6. Use piped logging instead of direct logging

Directly logging to a file results in issues when rotating the log file. A restart will be necessary to use the next log file. This causes significant slowness for you users during the restart. Particularly if you are using Passenger or some other app loader.

Page 8: 25 Apache Performance Tips

25 Apache Performance Tuning Tips www.monitis.com Uptime & Device Monitoring

7. Log to a different disk than the disk serving pages

Put your logs on physically different disks than the files you are serving.

Page 9: 25 Apache Performance Tips

25 Apache Performance Tuning Tips www.monitis.com Uptime & Device Monitoring

8. Utilize mod_gzip/mod_deflate

Gzip your content before sending it off. The client will ungzip upon receipt which will minimize the size of file transfers. Also, it will generally improve the user experience.

Page 10: 25 Apache Performance Tips

25 Apache Performance Tuning Tips www.monitis.com Uptime & Device Monitoring

9. Turn off HostnameLookups

Stop doing effortful DNS lookups. You will rarely ever need them and when you do, you can always look them up when really needed.

Page 11: 25 Apache Performance Tips

25 Apache Performance Tuning Tips www.monitis.com Uptime & Device Monitoring

10. Avoid using hostname in configs

If HostnameLookups are turned off, it will keep you from waiting for the DNS resolving the hostnames in your configs. Instead, use IP addresses.

Page 12: 25 Apache Performance Tips

25 Apache Performance Tuning Tips www.monitis.com Uptime & Device Monitoring

11. Use persistent connections

Set KeepAlive, KeepAliveTimeout and KeepAliveRequests. KeepAliveTimeout defines how long Apache will wait for the next request, and KeepAliveRequests defines the maximum number of requests for a client prior to resetting the connection. This will prevent the client from having to reconnect between each request.

Page 13: 25 Apache Performance Tips

25 Apache Performance Tuning Tips www.monitis.com Uptime & Device Monitoring

12. Do not set KeepAliveTimeout too high

If you have more requests than Apache children, settings which are set too high could exhaust your pool of available clients.

Page 14: 25 Apache Performance Tips

25 Apache Performance Tuning Tips www.monitis.com Uptime & Device Monitoring

13. Disable .htaccess

I.e. AllowOverride None. This will keep Apache from checking for an .htaccess file upon each request.

Page 15: 25 Apache Performance Tips

25 Apache Performance Tuning Tips www.monitis.com Uptime & Device Monitoring

14. Allow symlinks

I.e. Options + FoolowSymLinks – SymLinksIfOwnerMatch. Otherwise, Apache will make a separate call on each filename to ensure it is not a symlink.

Page 16: 25 Apache Performance Tips

25 Apache Performance Tuning Tips www.monitis.com Uptime & Device Monitoring

15. Set ExtendStatus off

Although very useful, the ExtendStatus will produce several system calls for each request to gather statistics. It‘s better to only define a certain time frame in order to benchmark and keep it turned off the remainder of the time.

Page 17: 25 Apache Performance Tips

25 Apache Performance Tuning Tips www.monitis.com Uptime & Device Monitoring

16. Avoid Wildcards in DirectoryIndex

Use a specific DirectoryIndex, i.e. index.html or index.php, not index.

Page 18: 25 Apache Performance Tips

25 Apache Performance Tuning Tips www.monitis.com Uptime & Device Monitoring

17. Increase Swappiness

Particularly on single site hosts this will increase the performance. On Linux systems increase /proc/sys/vm/swappiness to at least 60 if not higher. This will result in loading as many files as possible into the memory cache for a quicker access.

Page 19: 25 Apache Performance Tips

25 Apache Performance Tuning Tips www.monitis.com Uptime & Device Monitoring

18. Increase Write Buffer Size

Increase your write buffer size for TCP/IP buffers. On Linux systems increase /proc/sys/net/core/wmem_max and /proc/sys/net/core/wmem_default. If your pages fit within this buffer, Apache will complete a process in just one call to the TCP/IP buffer.

Page 20: 25 Apache Performance Tips

25 Apache Performance Tuning Tips www.monitis.com Uptime & Device Monitoring

19. Increase Max Open Files

If you are handling high loads, increase the number of allowed open files. On Linux increase /proc/sys/fs/file-max and run ulimit –H –n 4096.

Page 21: 25 Apache Performance Tips

25 Apache Performance Tuning Tips www.monitis.com Uptime & Device Monitoring

20. Setup a frontend proxy for images and stylesheets

Allow your main web servers to process the application while images and stylesheets are served from frontend webservers.

Page 22: 25 Apache Performance Tips

25 Apache Performance Tuning Tips www.monitis.com Uptime & Device Monitoring

21. Use mod_passenger for rails

Mod_passenger is able to share memory and resources amongst several processes, allowing for faster spawning of new application instances. It will also monitor these processes and remove them when they become unncessary.

Page 23: 25 Apache Performance Tips

25 Apache Performance Tuning Tips www.monitis.com Uptime & Device Monitoring

23. Don‘t use threaded mpm with mod_php

Look at using mod_itk, mod_php tends to segfault with threaded mpm.

Page 24: 25 Apache Performance Tips

25 Apache Performance Tuning Tips www.monitis.com Uptime & Device Monitoring

24. Flush buffers early for pre-render

It takes a relatively long time to create a webpage on the backend. Flush your buffer prior to page completion to send a partial page to the client, so it can start rendering. A good place to do this is right after the HEAD section – so that the browser can start fetching other objects.

Page 25: 25 Apache Performance Tips

25 Apache Performance Tuning Tips www.monitis.com Uptime & Device Monitoring

25. Use a cache for frequently accessed data

Memcached is a great for frequently used data and sessions. It will speed up your Apache render time as databases are slow.

Page 26: 25 Apache Performance Tips

facebook.com/Monitis.Monitoring

@Monitis

The All-in-One Monitoring Solution

Start your free 15-day trial for free! www.monitis.com