300 likes | 425 Views
Performing Better and Provisioning Less with Caching. Jason Fish Purdue University @ jasondfish. SlashDot Effect When a popular website links to a smaller site, causing a massive increase in traffic - Wikipedia. Syllabus Effect
E N D
Performing BetterandProvisioning LesswithCaching Jason Fish Purdue University @jasondfish
SlashDot Effect When a popular website links to a smaller site, causing a massive increase in traffic - Wikipedia
Syllabus Effect When excitement and worry at the start of the semester causes a massive increase in traffic
Assignment Effect When an online assignment is due and causes a massive increase in traffic
Performance is a feature, and just like any other feature, it must be continuously monitored and tested • James Socol • Mozilla’s Community Platform Manager http://www.flickr.com/photos/philippeleroyer/2070899672
Database Caching • Saving the results of a database query so that they can be used in the future
ASP.NET C# public static Person GetPersonByID(intpersonID) { var person = Cache.Get(“Person_GetPersonByID” + personID.ToString()); if (person == null) { person = from p in people where p.id = personID select p; Cache.Insert(“Person_GetPersonByID” + personID.ToString(), person); } return (Person)person; } http://msdn.microsoft.com/en-us/library/system.web.caching.cache.aspx
ColdFusion <cfquery name=“getPersonByID” datasource=“MyDataSourceName” cachedwithin=“#CreateTimeSpan(0,6,0,0)#”> select PersonID, PersonName, PersonAddress from People where PersonID = <cfqueryparam value=“#url.personid#” cfsqltype = “CF_SQL_INTEGER”> </cfquery> http://help.adobe.com/en_US/ColdFusion/9.0/CFMLRef/WSc3ff6d0ea77859461172e0811cbec22c24-7fae.html
PHP <?php $mysqli = new mysqli(“host”, “user”, “password”, “database”); $res = $mysqli ->query( “/*” . MYSQLND_QC_ENABLE_SWITCH . “*/” . “Select PersonID, PersonName From People where PersonID = 1” ); var_dump($res->fetch_assoc()); $res->free(); ?> http://php.net/manual/en/mysqlnd-qc.quickstart.caching.php
Expires Header The Expires Header tells the client to use the cached version of a component until a date in the future
93% 98%
ASP.NET <configuration> <system.webServer> <staticContent> <clientCachecacheControlMode="UseExpires"httpExpires="Tue, 19 Jan 2038 03:14:07 GMT" /> </staticContent> </system.webServer></configuration> http://www.iis.net/configreference/system.webserver/staticcontent/clientcache
ColdFusion <cfheader name=“Expires” value=“Sat, 12 Jan 2019 17:00:00 GMT”> <cfsetmyImage = imageRead(expandPath(“image.jpg”))> <cfcontent type=“image/jpg” variable= “#imageGetBlob(myImage)#”> http://livedocs.adobe.com/coldfusion/8/htmldocs/help.html?content=Tags_g-h_07.html
PHP <?php $offset = 60*60*24*14; $expire = ‘Expires: ' . gmdate ('D, d M Y H:i:s', time() + $offset) . ' GMT'; header ($expire); ?> http://php.net/manual/en/function.header.php
ASP.NET http://miniprofiler.com/ http://nuget.org/ http://stackoverflow.com/ http://www.hanselman.com/blog/NuGetPackageOfTheWeek9ASPNETMiniProfilerFromStackExchangeRocksYourWorld.aspx
: Mini Profiler : <cfsettingshowDebugOutput=“Yes”> : Zend IDE DBG Extension APD Extension Xdebug Extension
SQL Server Profiler http://msdn.microsoft.com/en-us/library/ms181091.aspx
Free for up to 25 simultaneous users • Academic discounts available • Easy to use • Produces easy to understand reports http://loadstorm.com/
developer.yahoo.com/yslow/ developers.google.com/speed/