Performing Better and Provisioning Less with Caching

30
Performing Better and Provisioning Less with Caching Jason Fish Purdue University @jasondfish

description

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 - PowerPoint PPT Presentation

Transcript of Performing Better and Provisioning Less with Caching

Page 1: Performing Better and Provisioning Less with Caching

Performing Betterand

Provisioning Lesswith

Caching

Jason FishPurdue University

@jasondfish

Page 2: Performing Better and Provisioning Less with Caching

SlashDot EffectWhen a popular website links to a smaller site, causing a massive increase in traffic - Wikipedia

Page 3: Performing Better and Provisioning Less with Caching

Syllabus EffectWhen excitement and worry at the start of the semester causes a massive increase in traffic

Page 4: Performing Better and Provisioning Less with Caching

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 %

Page 5: Performing Better and Provisioning Less with Caching

Assignment EffectWhen an online assignment is due and causes a massive increase in traffic

Page 6: Performing Better and Provisioning Less with Caching

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

Page 7: Performing Better and Provisioning Less with Caching
Page 8: Performing Better and Provisioning Less with Caching
Page 9: Performing Better and Provisioning Less with Caching

Database Caching

• Saving the results of a database query so that they can be used in the future

Page 10: Performing Better and Provisioning Less with Caching

Total Queries

0 50000 100000 150000 200000 250000 300000 350000

8911

295309

No Cache Top 10 Queries Cached

97%

Page 11: Performing Better and Provisioning Less with Caching

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

Page 12: Performing Better and Provisioning Less with Caching

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

Page 13: Performing Better and Provisioning Less with Caching

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

Page 14: Performing Better and Provisioning Less with Caching

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

Page 15: Performing Better and Provisioning Less with Caching
Page 16: Performing Better and Provisioning Less with Caching
Page 17: Performing Better and Provisioning Less with Caching
Page 18: Performing Better and Provisioning Less with Caching

Stan-ford

Penn St Purdue Ohio St Harvard Texas Florida0

10

20

30

40

50

60

Page 19: Performing Better and Provisioning Less with Caching

Expires Header

The Expires Header tells the client to use the cached version of a component until a date in the future

Page 20: Performing Better and Provisioning Less with Caching

93%

98%

Page 21: Performing Better and Provisioning Less with Caching

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

Page 22: Performing Better and Provisioning Less with Caching

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

Page 23: Performing Better and Provisioning Less with Caching

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

Page 24: Performing Better and Provisioning Less with Caching
Page 25: Performing Better and Provisioning Less with Caching

ASP.NET

http://www.hanselman.com/blog/NuGetPackageOfTheWeek9ASPNETMiniProfilerFromStackExchangeRocksYourWorld.aspx

http://stackoverflow.com/

http://nuget.org/

http://miniprofiler.com/

Page 26: Performing Better and Provisioning Less with Caching

: Mini Profiler

: <cfsetting showDebugOutput=“Yes”>

: Zend IDEDBG Extension

APD ExtensionXdebug Extension

Page 27: Performing Better and Provisioning Less with Caching

SQL Server Profiler

http://msdn.microsoft.com/en-us/library/ms181091.aspx

Page 28: Performing Better and Provisioning Less with Caching

• Free for up to 25 simultaneous users• Academic discounts available• Easy to use• Produces easy to understand reports

http://loadstorm.com/

Page 30: Performing Better and Provisioning Less with Caching

purdue.edu/studio