Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
ApacheWebPerformanceLeveraging Apache to makeyour site fly
Who am I?&Why would you listen to me?Why would you listen to me?Why would you listen to me?
DevonHillardWeb Application ArchitectBuilt 10MinuteMailRun Spark::red, an enterpriseeCommerce HostingcompanyComplex Web Ap...
What is Performance?
• Traffic Capacity• Request handlingspeed• Request handlingthroughput• LowerCPU/memory/bandwidth usage• Scalability
• Page Load Time• First draw• Inter-actable• Complete• Page InteractionResponsiveness• Time to Complete UseCase
These two are TIED• Browser caching of static assets reduces pageload time AND reduces the number of requeststhe server ha...
Why Should I Care?
Everyone Wins!• Client-Side Performance means• happier users• increased conversions• increased SEO ranking• Server-Side Pe...
IncreasedConversions•+100 ms of page load time = 1% drop in sales•+500 ms of page load time = 20% drop in searches•+400 ms...
Why Apache?
Why I Use Apache• Popular web server - it’s everywhere• Easy to install, troubleshoot, and find informationon• Mature and ...
CPU Util @ 930Mbit/sechttp://www.webperformance.com/load-testing/blog/2011/11/what-is-the-fastest-webserver/
PCAAwards• Saw 4x the planned fortraffic during spikes• 140,000+ pages/minute- 2,333 pps (2012)• 3,000+ Mbit/sec (2011)• 1...
Puppies
Basic Apache Configs
Every AppisDifferentDifferentDifferent
Which MPM?• Worker MPM scales for high traffic withoutrunning out of memory better• Less time spent tuning worker configs•...
Default<IfModule worker.c>StartServers 2MaxClients 150MinSpareThreads 25MaxSpareThreads 75ThreadsPerChild 25MaxRequestsPer...
ab with small fileVersionApache 2.2.3 MPMWorkerDocument Size 119 bytesConcurrency Level 1,000Total Requests 100,000Request...
ab with large fileVersionApache 2.2.3 MPMWorkerDocument Size 95,002 bytesConcurrency Level 1,000Total Requests 100,000Requ...
Linux KernelConfigsnet.ipv4.tcp_max_syn_backlog=30000net.core.netdev_max_backlog=1200net.ipv4.tcp_timestamps=0net.ipv4.tcp...
Keepalive - On orOff?• reduces overhead of establishing newconnections for each request from the browser• can waste memory...
GZip - mod_deflate• gzip compressing text resources - html, js, xml,css dramatically decreases the size of theresponse for...
Browser Caching• Tell the browser to cache all static assets, for aslong as you can bear it• Set the ETag• Set cache contr...
Disk Caching• Why not use mod_mem_cache?• Transparent web server caching of assetsreduces load without deployment anddevel...
Disk Caching -Config<IfModule mod_disk_cache.c>CacheRoot /var/cache/mod_disk_cacheCacheDirLevels 2CacheDirLength 1CacheEna...
Mod_PageSpeed• Open Source Apache Module• Lots and Lots of filters• image compression• combine js/css• sprite images• doma...
Three TierArchitecture• SSL Termination• Load Balancing• Mod_proxy/mod_cluster• Mod_Security
BuildingScalableClustersw/Apache• VIP• heartbeat• haproxy• DNS LB• simple round robin• smart
Questions?
Thank you!devon@sparkred.comdevon@sparkred.comdevon@sparkred.com
Upcoming SlideShare
Loading in …5
×

Configuring Apache Servers for Better Web Perormance

6,079 views

Published on

Apache is the most popular web server in the world, yet its default configuration can't handle high traffic. Learn how to setup Apache for high performance sites and leverage many of its available modules to deliver a faster web experience for your users. Discover how Apache can max out a 1 Gbps NIC and how to serve over 140,000 pages per minute with a small Apache cluster. This presentation was given by Spark::red's founding partner Devon Hillard in March 2012 at the Boston Web Performance Meetup.

Published in: Technology
  • Sex in your area is here: ❶❶❶ http://bit.ly/2u6xbL5 ❶❶❶
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • Dating direct: ♥♥♥ http://bit.ly/2u6xbL5 ♥♥♥
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here

Configuring Apache Servers for Better Web Perormance

  1. 1. ApacheWebPerformanceLeveraging Apache to makeyour site fly
  2. 2. Who am I?&Why would you listen to me?Why would you listen to me?Why would you listen to me?
  3. 3. DevonHillardWeb Application ArchitectBuilt 10MinuteMailRun Spark::red, an enterpriseeCommerce HostingcompanyComplex Web Apps withextremely high traffic andcritical performance needsdevon@sparkred.com
  4. 4. What is Performance?
  5. 5. • Traffic Capacity• Request handlingspeed• Request handlingthroughput• LowerCPU/memory/bandwidth usage• Scalability
  6. 6. • Page Load Time• First draw• Inter-actable• Complete• Page InteractionResponsiveness• Time to Complete UseCase
  7. 7. These two are TIED• Browser caching of static assets reduces pageload time AND reduces the number of requeststhe server has to handle for the same numberof page views• AJAX requests can typically be handled with farfewer resources than full page requests• Reduced asset sizes means less bandwidthused and shorter request response sendingtimes• Solving for the Client brings Server performancegains!
  8. 8. Why Should I Care?
  9. 9. Everyone Wins!• Client-Side Performance means• happier users• increased conversions• increased SEO ranking• Server-Side Performance means• more capacity on same hardware• saves money• scaling is easier
  10. 10. IncreasedConversions•+100 ms of page load time = 1% drop in sales•+500 ms of page load time = 20% drop in searches•+400 ms of page load time = 5-9% increase inclicking “back” button before the page finishedloading
  11. 11. Why Apache?
  12. 12. Why I Use Apache• Popular web server - it’s everywhere• Easy to install, troubleshoot, and find informationon• Mature and stable• Lots of extensions• Enterprise support requirements• It Is fast enough to max out your hardware!
  13. 13. CPU Util @ 930Mbit/sechttp://www.webperformance.com/load-testing/blog/2011/11/what-is-the-fastest-webserver/
  14. 14. PCAAwards• Saw 4x the planned fortraffic during spikes• 140,000+ pages/minute- 2,333 pps (2012)• 3,000+ Mbit/sec (2011)• 1,200+ Mbit/sec PLUSAkamai CDN offloadedtraffic (2012)• The site stayed up andwas quick to load andresponsive to interactwith the whole timeiftop output - 613 Mbit/sec
  15. 15. Puppies
  16. 16. Basic Apache Configs
  17. 17. Every AppisDifferentDifferentDifferent
  18. 18. Which MPM?• Worker MPM scales for high traffic withoutrunning out of memory better• Less time spent tuning worker configs• Unless you’re still using non-threadsafe Apachecode (some PHP, etc..)• New in Apache 2.4 is the Event MPM
  19. 19. Default<IfModule worker.c>StartServers 2MaxClients 150MinSpareThreads 25MaxSpareThreads 75ThreadsPerChild 25MaxRequestsPerChild0</IfModule>Mine<IfModule worker.c>ThreadLimit 100StartServers 5MaxClients 5500ServerLimit 200MinSpareThreads 100MaxSpareThreads 1000ThreadsPerChild 100MaxRequestsPerChild0</IfModule>MPM WorkerConfigs
  20. 20. ab with small fileVersionApache 2.2.3 MPMWorkerDocument Size 119 bytesConcurrency Level 1,000Total Requests 100,000Requests Per Second 20,790 r/sThroughput 8,077 kb/shex core X5675
  21. 21. ab with large fileVersionApache 2.2.3 MPMWorkerDocument Size 95,002 bytesConcurrency Level 1,000Total Requests 100,000Requests Per Second 1,258 r/sThroughput 119,966 kb/shex core X5675
  22. 22. Linux KernelConfigsnet.ipv4.tcp_max_syn_backlog=30000net.core.netdev_max_backlog=1200net.ipv4.tcp_timestamps=0net.ipv4.tcp_sack=0net.ipv4.tcp_window_scaling=0net.ipv4.tcp_max_tw_buckets=2000000net.ipv4.tcp_mem=100000000 100000000 100000000net.ipv4.tcp_wmem=100000000 100000000 100000000net.ipv4.tcp_rmem=30000000 30000000 30000000net.ipv4.ip_conntrack_max = 231072
  23. 23. Keepalive - On orOff?• reduces overhead of establishing newconnections for each request from the browser• can waste memory and other resources if leftopen too long• Common practice is to disable them• I turn keepalive on, set to 6 seconds or 500requests• For CDNs like Akamai, you’ll want to turn up thetime to more like 120 seconds
  24. 24. GZip - mod_deflate• gzip compressing text resources - html, js, xml,css dramatically decreases the size of theresponse for those assets: often up to 90%reduction in size• reduces transfer time, especially for clients withslower connections (or big files)• This decreases page load time (Client) andreduces the time the server thread is sendingthe response (Server)# Removing Hosts varyHeader unset Vary<IfModule mod_deflate.c>AddOutputFilterByType DEFLATE text/html text/plaintext/xml text/css application/x-javascriptBrowserMatch ^Mozilla/4 gzip-only-text/htmlBrowserMatch ^Mozilla/4.0[678] no-gzipBrowserMatch bMSIE !no-gzip !gzip-only-text/html</IfModule>
  25. 25. Browser Caching• Tell the browser to cache all static assets, for aslong as you can bear it• Set the ETag• Set cache control and expiration responseheaders<LocationMatch ^/pca/images/.*>FileETag MTime SizeHeader set Cache-Control "max-age=2764800, public"<IfModule mod_expires.c>ExpiresActive OnExpiresByType image/jpg A2764800ExpiresByType image/jpeg A2764800ExpiresByType image/png A2764800</IfModule></LocationMatch>
  26. 26. Disk Caching• Why not use mod_mem_cache?• Transparent web server caching of assetsreduces load without deployment anddevelopment complexities• Some warnings!• Doesn’t auto clean itself• Can grow to be huge if you don’t check theheaders being cached• Can grow to be huge if you have dynamicURI content - blah.jpg;jsessionid=foo• Another place to purge cache for changedfiles
  27. 27. Disk Caching -Config<IfModule mod_disk_cache.c>CacheRoot /var/cache/mod_disk_cacheCacheDirLevels 2CacheDirLength 1CacheEnable disk /pca/imgCacheEnable disk /pca/flashCacheEnable disk /pca/cssCacheEnable disk /pca/jsCacheEnable disk /pca/imagesCacheMaxFileSize 200715200CacheDefaultExpire 3600CacheIgnoreHeaders Set-Cookie</IfModule>
  28. 28. Mod_PageSpeed• Open Source Apache Module• Lots and Lots of filters• image compression• combine js/css• sprite images• domain sharding• etc...
  29. 29. Three TierArchitecture• SSL Termination• Load Balancing• Mod_proxy/mod_cluster• Mod_Security
  30. 30. BuildingScalableClustersw/Apache• VIP• heartbeat• haproxy• DNS LB• simple round robin• smart
  31. 31. Questions?
  32. 32. Thank you!devon@sparkred.comdevon@sparkred.comdevon@sparkred.com

×