• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
Clug 2011 March  web server optimisation
 

Clug 2011 March web server optimisation

on

  • 576 views

How to optimise a web server to reduce latency and bandwidth to viewers

How to optimise a web server to reduce latency and bandwidth to viewers

Statistics

Views

Total Views
576
Views on SlideShare
576
Embed Views
0

Actions

Likes
0
Downloads
2
Comments
0

0 Embeds 0

No embeds

Accessibility

Categories

Upload Details

Uploaded via as OpenOffice

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    Clug 2011 March  web server optimisation Clug 2011 March web server optimisation Presentation Transcript

    • Website Optimisation CLUG March 2012
    • contentsNetworkCompressionHTTP CachingStructuringMeasurementApplication CachingMonitoring
    • contents ClientNetworkCompressionHTTP CachingStructuringMeasurementApplication CachingDatabase tuningMonitoring Server
    • Networkmtr ­c 10 ­r www.openquery.comHOST: spaceman.localhost           Loss%   Snt   Last   Avg  Best   Wrst StDev  1.|­­ 192.168.1.1                 0.0%    10    0.8   2.6   0.7  19.3    5.8  2.|­­ 192.168.3.254               0.0%    10    1.1   1.2   1.1   1.5    0.1
    • Network (DNS)Check whois is showing the right nameserver whois openquery.com NS1.LINODE.COM NS2.LINODE.COM NS3.LINODE.COM NS4.LINODE.COM NS1.CREATIVECONTINGENCIES.COM NS2.CREATIVECONTINGENCIES.COM NS3.CREATIVECONTINGENCIES.COMEnsure correct record is returned by querying each nameserverdig www.openquery.com @ns1.creativecontingencies.com
    • Network (SSL/TLS)
    • Network (SSL/TLS)Session Tickets - 8 packets 3 roundtrips before application dataEDH crypto – computational expensive by has perfect forwards secrecy
    • Network (HTTP keep-alive)Request / Response headerConnection:keep-aliveOn by default. Cant handle variable length pages
    • CompressionGzip/deflate
    • CompressionApaches HTTPd Enable mod_deflate<IfModule mod_deflate.c> SetOutputFilter DEFLATE</IfModule>Lighty Enable “mod_compress” in server.modulesNginx gzip on;
    • CompressionPHP Php.ini zlib.output_compression On
    • HTTP CachingRFC 2616 Hypertext Transfer Protocol – HTTP/1.1
    • HTTP CachingEtag Unique string – usual some form of digestBrowsers request with HTTP header:If-None-Match: “uniquestring....”Server response: 304 not modified if nothing changes
    • HTTP Caching (Etag)HTTPdFileETag Mtime
    • HTTP Caching (Expires)HTTP Response headerExpires: Thu, 01 Dec 2012 16:00:00 GMTDate:Thu, 22 Mar 2012 01:00:17 GMTLast-Modified:Sun, 11 Mar 2012 20:55:16 GMTHTTP RequestIf-Modified-Since: Sat, 29 Oct 1994 19:43:31 GMT
    • HTTP Caching (Cache-Control) Cache-Control = "Cache-Control" ":"1#cache-directivecache-directive = cache-request-directive | cache-response-directivecache-request-directive = "no-cache" ; Section14.9.1
    • Gzip + Caching Savings On initial response: 104.2K (vs 255.6K) / 44trunk/roundcubemail/.htaccess ¶ requests)<IfModule mod_deflate.c>next page: 6.2K 2 requests (vs 204.7K / 44 On requests)SetOutputFilter DEFLATE</IfModule><IfModule mod_headers.c># replace append with merge for Apache version 2.2.9 and laterHeader append Cache-Control public env=!
    • Use Yslow / Firebug Structuring
    • Measurement
    • Measurement (Application)create table `timings` ( `id` int(4) NOT NULL AUTO_INCREMENT, host varchar(20),page varchar(120), int t1,int t2, int t3.....)And in the index.php$sample = rand(0,100) < 5; # 5% sample rateif ($sample) $t0 = microtime(TRUE);
    • Application CachingBe strategic – cost / benefitHard to generate – graphs, database queries, complex mathsFrequent pages: front pages, rss, ajax
    • Application Caching (duplicate) if (!$db->count(name, $name, DB_CACHE)) { // if no cache entry exists, fetch the appropriate html and insert... } else { // row exists - determine if it is still valid
    • Application CachingCache an entire pageMemcache is your friend – RAM, autoexpire, overload intelligent expireShare between serversNice API in all languages e.g. PHP public mixed Memcached::get ( string $key [, callable $cache_cb [, float &$cas_token ]] )
    • Application scalingIf the application scales by adding webservers you will save on hosting on high power serversEnsure application is statelessReverse proxy state-full bits to central server if neededCDNs or separated servers for static content saves lots of cpu (latency, keep alives)
    • Application APCGraph from apc.php as part of the php_apc package
    • DatabaseKnow what indexes are and which queries arent using them.EXPLAIN {sql expression} (Postgresql and Mysql)EXPLAIN ANALYSE {sql expression}Slow query log – enableKnow differences between MySQL enginesTune your server Defaults well out of proportion with your sever.
    • Database (continued)Searching text in SQL – Use Sphinxsearch insteadSame sql interfaces, pulls off database – much quicker at full text search
    • Databases (application)Eventually one DB will be too littlePlan to buy big hardware (Oracle) or plan to use a replicated database (for reads)Some reads will need to occur on the master. The ones where the data was likely just changed very recently
    • Monitoring
    • MonitoringInclude resource usageCpu / RAM / processes / forking / swap / IO / Bandwidth...Web server – pages/second, threadsDatabase – query cache hits/misses, connections, replication delayBusiness value: page load time.Alert if boundaries exceeded