Performing Better and Provisioning Less with Caching
description
Transcript of Performing Better and Provisioning Less with Caching
Performing Betterand
Provisioning Lesswith
Caching
Jason FishPurdue University
@jasondfish
SlashDot EffectWhen a popular website links to a smaller site, causing a massive increase in traffic - Wikipedia
Syllabus EffectWhen excitement and worry at the start of the semester causes a massive increase in traffic
Before Semester
1st Week 4th Week 8th Week 12th Week0
50,000
100,000
150,000
200,000
250,000
27,937
234,727
130,205
80,85168,116
46 %
65 %70 %
840 %
Assignment EffectWhen an online assignment is due and causes a massive increase in traffic
http://www.flickr.com/photos/philippeleroyer/2070899672
Performance is a feature, and just like any other feature, it must be continuously monitored and tested
- James Socol Mozilla’s Community Platform Manager
Database Caching
• Saving the results of a database query so that they can be used in the future
Total Queries
0 50000 100000 150000 200000 250000 300000 350000
8911
295309
No Cache Top 10 Queries Cached
97%
Requests per Second
Total Requests
Average Request Time
Errors
Total Database Calls
333%
330%
16%
0%
49%
133%
129%
75%
90%
91%
100%
100%
100%
100%
100%
No Cache Top Query Cached Top 6 Queries Cached
ASP.NET C#public static Person GetPersonByID(int personID) {
var person = Cache.Get(“Person_GetPersonByID” + personID.ToString());
if (person == null){
person = from p in peoplewhere p.id = personIDselect 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, PersonAddressfrom Peoplewhere 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
Stan-ford
Penn St Purdue Ohio St Harvard Texas Florida0
10
20
30
40
50
60
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> <clientCache cacheControlMode="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”>
<cfset myImage = 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://www.hanselman.com/blog/NuGetPackageOfTheWeek9ASPNETMiniProfilerFromStackExchangeRocksYourWorld.aspx
http://stackoverflow.com/
http://nuget.org/
http://miniprofiler.com/
: Mini Profiler
: <cfsetting showDebugOutput=“Yes”>
: Zend IDEDBG Extension
APD ExtensionXdebug 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/
purdue.edu/studio