Do Cheaters Prosper?UNDERSTANDING THE RULESOF APPLICATION DEVELOPMENTScott Tadman (Chief of Research) / Dom Bortolussi (CE...
“The Rules”• These are taught to you in school.• Based on conventions, shaped by tradition.• Supposed to steer you towards...
“The Rules”• These arbitrary rules put you in a box.• They limit your thinking.
“The Box”
“Cheating”• Defies convention.• Thinks “outside the box”.• Breaks “rules”.• Yields an “unfair” advantage.
Cheating?• Isn’t cheating bad?
Bad Cheating• Breaks laws.• Puts people at risk.• Has severe negative consequences.
Good Cheating• Often called “hacks” or “tricks”• Circumvents ritual or tradition.• Cutting corners.
Good Cheating
Good Cheating
Bad Cheating
Bad Cheating• We usually call it “illegal”.• Like get you into jail illegal.
So what are therules?
The Application’s Rules• Don’t crash on me.• Don’t waste my time.• Don’t lie to me.• Don’t forget my things.• Don’t cost m...
Important Rule• Don’t kill me.
Asimov’s Law• “A robot may not harm a human being.”
Developer’s Law?• “An application may not harm a humanbeing.”
“Fatal Error?”
Nuclear Reactor
Nuclear Reactor
Nuclear Reactor
DohNuclear Reactor
Consequences?
We all die.
X-Ray Machine
X-Ray Machine
X-Ray Machine
X-Ray MachineYikes.
Consequences?
Someone dies.
The ApplicationYou’re Building
Most Applications
Typical ApplicationBah.
Consequences?
Nobody dies.
Don’t worry somuch.
Most Applications• Won’t kill people.• Won’t misplace lots of money.• Won’t destroy the universe.• Have a lot of opportuni...
“Cheating”
It’s like a magictrick.
Don’t get caught.
It ruins it.
Successful Cheating• Don’t let me catch you crashing on me.• Don’t let me catch you wasting my time.• Don’t let me catch y...
Successful Cheating• It’s all about not getting caught.
A Magic Trick• Rough definition:• A method to achieve the desired effect.
An Application• Rough definition:• A programmed method to achieve desiredeffects.
Performance Cheats
Performance Cheats• Doing the “wrong” thing.• Getting “dirty”, introducing “hacks”.• Optimized for very specific cases.• A...
ApplicationsDeconstructed• Capture, retrieve and display resources.• Resources have varying costs including:• Cost of tran...
Application Fundamentals• Resources may or may not be requested.• Resources have varying probabilities of beingrequired.• ...
Cost to DeliverProbability of RequestLowHighOptimization RegionsThe BoxExpensiveRareFreeFrequentGeneralized solutionsto ge...
Cost to DeliverProbability of RequestLowHighOptimization RegionsEffortlessExpensiveRareFreeFrequentThese don’t require opt...
Cost to DeliverProbability of RequestLowHighOptimization RegionsEffortless ProcrastinateExpensiveRareFreeFrequentThese are...
Cost to DeliverProbability of RequestExpensiveLowRareHighOptimization RegionsPleasureEffortless ProcrastinateFreeFrequentT...
Cost to DeliverProbability of RequestLowHighOptimization RegionsPainPleasureEffortless ProcrastinateExpensiveRareFreeFrequ...
BandwidthSystem PowerLowHighResourcesMarginalNoneUnlimitedUnlimitedPersonal ComputerMobileSingle ServerServer Cluster
FundamentalStrategies
Perception Matters• Performance is all about perception.• People are oblivious to your best.• People will remember your wo...
“Cheater’s Bag ofTricks”
Goals of “Cheating”Cost to DeliverProbability of RequestLowHighExpensiveRareFreeFrequent Identified ProblemExpensive and f...
Cheating GoalsCost to DeliverProbability of RequestLowHighExpensiveRareFreeFrequentOptimization AMethod to reduce cost of ...
Cheating GoalsCost to DeliverProbability of RequestLowHighExpensiveRareFreeFrequentOptimization BMethod to reducefrequency...
Cheating GoalsCost to DeliverProbability of RequestLowHighExpensiveRareFreeFrequentOptimization A + BCombination reduces c...
Real-WorldExamples
Cost to DeliverProbability of RequestLowHighWeather WidgetExpensiveRareFreeFrequentImplementedFetch from API on demandand ...
Cost to DeliverProbability of RequestLowHighWeather WidgetExpensiveRareFreeFrequentImplementedFetch from API on demandand ...
Cost to DeliverProbability of RequestLowHighWeather WidgetExpensiveRareFreeFrequentImplementedFetch from API on demandand ...
Cost to DeliverProbability of RequestLowHighFinancial BlogExpensiveRareFreeFrequentStock SolutionImages are loaded on dema...
Cost to DeliverProbability of RequestLowHighFinancial BlogExpensiveRareFreeFrequentStock SolutionImages are loaded on dema...
Cost to DeliverProbability of RequestLowHighFinancial BlogExpensiveRareFreeFrequentStock SolutionImages are loaded on dema...
Cost to DeliverProbability of RequestLowHighFinancial BlogExpensiveRareFreeFrequentStock SolutionImages are loaded on dema...
Cost to DeliverProbability of RequestLowHighFinancial BlogExpensiveRareFreeFrequentStock SolutionImages are loaded on dema...
Cost to DeliverProbability of RequestLowHighFinancial BlogExpensiveRareFreeFrequentStock SolutionImages are loaded on dema...
Specific Strategies
Wait Less• Work to minimize perceived wait.• Make things appear instantly.• Don’t block, lock up, or stall.• Flip client s...
Cost to DeliverProbability of RequestLowHighWait LessExpensiveRareFreeFrequentTarget Zone“Add User Comment”Frequent operat...
Cost to DeliverProbability of RequestLowHighWait LessExpensiveRareFreeFrequentClient State Directly AlteredShow result of ...
Wait More• Make things appear important.• Keep user informed: spinners, progress bars.• Keep delay proportional to signifi...
Cost to DeliverProbability of RequestLowHighWait MoreExpensiveRareFreeFrequentTarget Zone“Preview My Book”Requesting too m...
Cost to DeliverProbability of RequestLowHighWait MoreExpensiveRareFreeFrequent“Your Book is Queued”Delayed gratification.M...
Cost to DeliverProbability of RequestLowHighWait MoreExpensiveRareFreeFrequentTarget Zone“Find Best Flight”Might be trivia...
Cost to DeliverProbability of RequestLowHighWait MoreExpensiveRareFreeFrequent“Calculating Results...”Artificial delay mak...
Load Less• Fetching things on demand.• “Lazy loading”• Ideal for resources that might not be seen.• Refrigerator light pri...
Cost to DeliverProbability of RequestLowHighLoad LessExpensiveRareFreeFrequentTarget Zone“Blog Page, Post N”Things that ar...
Cost to DeliverProbability of RequestLowHighLoad LessExpensiveRareFreeFrequentLazy LoadingPuts of loading a resourceuntil ...
Load More• Fetching resources ahead of time.• “Eager loading”• Ideal for resources that will probably be seen.• Boy-scout ...
Cost to DeliverProbability of RequestLowHighLoad MoreExpensiveRareFreeFrequentTarget Zone “Site Icons”Many, many requestsf...
Cost to DeliverProbability of RequestLowHighLoad MoreExpensiveRareFreeFrequentAsset BundlingCreate single asset thatcan be...
Saving Less• Trim, crop, shrink.• Strip out redundant or duplicated content.• Define and enforce limitations.• One size fi...
Cost to DeliverProbability of RequestLowHighSaving LessExpensiveRareFreeFrequentTarget Zone“Upload Photo”Users upload full...
Cost to DeliverProbability of RequestLowHighSaving LessExpensiveRareFreeFrequentReduce Size, CompressShrinking to sizes re...
Saving More• Make copies of things in different formats.• A form of “caching”, “pre-rendering”• De-normalize your data.• O...
Cost to DeliverProbability of RequestLowHighSaving MoreExpensiveRareFreeFrequentTarget Zone“Image Variants by Size”Images ...
Cost to DeliverProbability of RequestLowHighSaving MoreExpensiveRareFreeFrequentPre-RenderingReduces frequency of requests...
Cache More• Fastest database call is the one never made.• Pre-cache when you have the data on hand.• Reuse and recycle exp...
TargetZoneCost to DeliverProbability of RequestLowHighCache MoreExpensiveRareFreeFrequentTarget ZoneHigh Frequency + CostC...
Cost to DeliverProbability of RequestLowHighCache MoreExpensiveRareFreeFrequent“Friends of My Friends” Database QueryResul...
Cost to DeliverProbability of RequestLowHighCache MoreExpensiveRareFreeFrequent“Video Effects Preview”Result of preview sa...
Cache Less• Tuning your database can make cachingredundant.• Caches can make updates take longer.• Cache invalidation can ...
Cost to DeliverProbability of RequestLowHighCache LessExpensiveRareFreeFrequentTarget Zone“Premature Optimization”Hiding r...
Cost to DeliverProbability of RequestLowHighCache LessExpensiveRareFreeFrequent Original ImplementationExpensive and slow....
Distribute More• Content distribution networks.• Clustered databases, data replication.• Client-side storage, content bund...
Cost to DeliverProbability of RequestLowHighDistribute MoreExpensiveRareFreeFrequentTargetZone“Server-Side Content”User pr...
Cost to DeliverProbability of RequestLowHighDistribute MoreExpensiveRareFreeFrequentServer Hosted ResourceStored on server...
Distribute Less• Keep data and content local.• Self-hosted databases instead of cloud-hosted.• “Dumb client, smart server”...
Cost to DeliverProbability of RequestLowHighDistribute LessExpensiveRareFreeFrequentTargetZone“Cloud Hosted Metrics Databa...
Cost to DeliverProbability of RequestLowHighDistribute LessExpensiveRareFreeFrequentRemote Cloud ServiceTakes hundreds of ...
Purge More• Delete data no longer used.• Archive to cheaper storage systems.• Generate on demand.• Less data equals less o...
TargetZoneCost to DeliverProbability of RequestLowHighPurge MoreExpensiveRareFreeFrequent“Outdated, Detailed User Metrics ...
Cost to DeliverProbability of RequestLowHighPurge MoreExpensiveRareFreeFrequentDeletedNobody will miss it.
Purge Less• Dump it on the cloud, forget about it.• Keep things cached longer.• Pre-render instead of render on demand.• L...
Cost to DeliverProbability of RequestLowHighPurge LessExpensiveRareFreeFrequentSave Alternate FormatsAlso store as XML orJ...
Compress More• Lossless or lossy compression.• Use deflate (gzip) for transfers.• Aggressively minify scripts.
Target ZoneCost to DeliverProbability of RequestLowCompress MoreExpensiveRareFreeAlmost AnythingMost resources benefitfrom...
Cost to DeliverProbability of RequestLowCompress MoreExpensiveRareFreeFrequentText ResourceSome things compress really wel...
Compress Less• Keep data in pure, raw form.• Databases can’t interact with compresseddata.• Serialized or compressed data ...
Cost to DeliverProbability of RequestLowHighCompress LessExpensiveRareFreeFrequent“User Profile Data”Hundreds of arbitrary...
Index More• Every query has a cost.• Examine access patterns, index accordingly.• A query without an index: painful.• A qu...
Cost to DeliverProbability of RequestLowIndex MoreExpensiveRareFreeFrequent“Message Board Table”Queried very frequently,in...
Index Less• Every index makes writes more expensive.• Indexes don’t always get used.• Some indexes you might want but not ...
Cost to DeliverProbability of RequestLowIndex LessExpensiveRareFreeFrequentAggressive IndexingWrites aresignificantly more...
Multitask More• Do things in parallel.• Break down dependencies, avoid contention.• Distribute work across many systems.• ...
Cost to DeliverProbability of RequestLowHighMultitask MoreExpensiveRareFreeFrequent“Render Page”Smaller scale task iseasy ...
Multitask Less• Stream things in sequentially.• Keep load on server light.• Keeps more network resources available.• Buffe...
Cost to DeliverProbability of RequestLowHighMultitask LessExpensiveRareFreeFrequent“Sync Calendar Entries”Operation that’s...
Provision More• Server hardware can be scaled up.• Desktop/mobile apps can leverage serverhardware.• On-demand cloud servi...
Cost to DeliverProbability of RequestLowHighProvision MoreExpensiveRareFreeFrequent Relatively ExpensiveUses high percenta...
Provision Less• Keep your application footprint lean.• Don’t burn through CPU and battery.• Don’t use tons of memory.• Sma...
Cost to DeliverProbability of RequestLowHighProvision LessExpensiveRareFreeFrequent“Upload All Photos on Phone”Interrupts ...
Breaking Rules
“Cheating”
Focus on theeffects.
Figure the rest out.
Scott Tadmantwg.ca@ceben @twgTHANK YOUScott Tadman / Dom Bortolussitwg.ca@tadmanter @dombort @twggithub.com/tadmantwg.cahe...
Do cheaters prosper? Understanding the rules of application development
Upcoming SlideShare
Loading in...5
×

Do cheaters prosper? Understanding the rules of application development

961

Published on

From an early age, we are told that cheating is bad. There are rules we’re supposed to follow, and breaking these rules – we’re told – is a big no-no. No ice-cream before dinner, no peeking at your classmate’s test, no cutting in line for lunch… or else. But is cheating always a bad thing?

Bad cheating breaks the law, puts people at risk or has severe negative consequences. If you’re making a program to run a nuclear reactor: don’t cheat. If something goes wrong then there will be very bad consequences.

Good cheating is like a magic trick: it’s a method to achieve a desired effect. Just don’t get caught. Getting caught ruins the magic and gets you in trouble. Do things “wrong”, get dirty, use hacks, and optimize for very specific cases. Do all this in order to deliver the desired effect.

Applications capture, retrieve and display resources. These resources have costs, such as the cost of transmission, processing and storage. Different resources have varying probabilities of being required; some may be requested and others not, some may be requested frequently and others rarely. These are all things to consider when deciding what processes can and need to be optimized, which will in turn help you choose from your magic bag of tricks.

Here’s a quick barometer for deciding when to cheat:
- Requests that are free or cheap to deliver and are rare are not worth optimizing since these are essentially effortless already
- Requests that are expensive but rare aren’t a priority, feel free to procrastinate on these
- Requests that are free or cheap and happen frequently are the fun ones to optimize
- Requests that are frequent and expensive are your big wins… if you can figure out how to optimize them.

Published in: Technology, Business
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
961
On Slideshare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
5
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Transcript of "Do cheaters prosper? Understanding the rules of application development"

  1. 1. Do Cheaters Prosper?UNDERSTANDING THE RULESOF APPLICATION DEVELOPMENTScott Tadman (Chief of Research) / Dom Bortolussi (CEO), TWG@tadmanter @dombort @twg
  2. 2. “The Rules”• These are taught to you in school.• Based on conventions, shaped by tradition.• Supposed to steer you towards bestpractices.• Usually distorted by superstition andparanoia.
  3. 3. “The Rules”• These arbitrary rules put you in a box.• They limit your thinking.
  4. 4. “The Box”
  5. 5. “Cheating”• Defies convention.• Thinks “outside the box”.• Breaks “rules”.• Yields an “unfair” advantage.
  6. 6. Cheating?• Isn’t cheating bad?
  7. 7. Bad Cheating• Breaks laws.• Puts people at risk.• Has severe negative consequences.
  8. 8. Good Cheating• Often called “hacks” or “tricks”• Circumvents ritual or tradition.• Cutting corners.
  9. 9. Good Cheating
  10. 10. Good Cheating
  11. 11. Bad Cheating
  12. 12. Bad Cheating• We usually call it “illegal”.• Like get you into jail illegal.
  13. 13. So what are therules?
  14. 14. The Application’s Rules• Don’t crash on me.• Don’t waste my time.• Don’t lie to me.• Don’t forget my things.• Don’t cost me money/bandwidth.
  15. 15. Important Rule• Don’t kill me.
  16. 16. Asimov’s Law• “A robot may not harm a human being.”
  17. 17. Developer’s Law?• “An application may not harm a humanbeing.”
  18. 18. “Fatal Error?”
  19. 19. Nuclear Reactor
  20. 20. Nuclear Reactor
  21. 21. Nuclear Reactor
  22. 22. DohNuclear Reactor
  23. 23. Consequences?
  24. 24. We all die.
  25. 25. X-Ray Machine
  26. 26. X-Ray Machine
  27. 27. X-Ray Machine
  28. 28. X-Ray MachineYikes.
  29. 29. Consequences?
  30. 30. Someone dies.
  31. 31. The ApplicationYou’re Building
  32. 32. Most Applications
  33. 33. Typical ApplicationBah.
  34. 34. Consequences?
  35. 35. Nobody dies.
  36. 36. Don’t worry somuch.
  37. 37. Most Applications• Won’t kill people.• Won’t misplace lots of money.• Won’t destroy the universe.• Have a lot of opportunities to “cheat”.
  38. 38. “Cheating”
  39. 39. It’s like a magictrick.
  40. 40. Don’t get caught.
  41. 41. It ruins it.
  42. 42. Successful Cheating• Don’t let me catch you crashing on me.• Don’t let me catch you wasting my time.• Don’t let me catch you lying to me.• Don’t let me catch you forgetting my things.• Don’t let me catch you costing me money/bandwidth.
  43. 43. Successful Cheating• It’s all about not getting caught.
  44. 44. A Magic Trick• Rough definition:• A method to achieve the desired effect.
  45. 45. An Application• Rough definition:• A programmed method to achieve desiredeffects.
  46. 46. Performance Cheats
  47. 47. Performance Cheats• Doing the “wrong” thing.• Getting “dirty”, introducing “hacks”.• Optimized for very specific cases.• Are focused on delivering the desired effects.• It’s always about perception.
  48. 48. ApplicationsDeconstructed• Capture, retrieve and display resources.• Resources have varying costs including:• Cost of transmission.• Cost of processing.• Cost of storage.
  49. 49. Application Fundamentals• Resources may or may not be requested.• Resources have varying probabilities of beingrequired.• Some requests are frequent.• Some requests are rare.
  50. 50. Cost to DeliverProbability of RequestLowHighOptimization RegionsThe BoxExpensiveRareFreeFrequentGeneralized solutionsto generalizedproblems.
  51. 51. Cost to DeliverProbability of RequestLowHighOptimization RegionsEffortlessExpensiveRareFreeFrequentThese don’t require optimization.
  52. 52. Cost to DeliverProbability of RequestLowHighOptimization RegionsEffortless ProcrastinateExpensiveRareFreeFrequentThese aren’t a priority.
  53. 53. Cost to DeliverProbability of RequestExpensiveLowRareHighOptimization RegionsPleasureEffortless ProcrastinateFreeFrequentThese are the ones we love to fix.
  54. 54. Cost to DeliverProbability of RequestLowHighOptimization RegionsPainPleasureEffortless ProcrastinateExpensiveRareFreeFrequentBig wins...if you can figure out how.
  55. 55. BandwidthSystem PowerLowHighResourcesMarginalNoneUnlimitedUnlimitedPersonal ComputerMobileSingle ServerServer Cluster
  56. 56. FundamentalStrategies
  57. 57. Perception Matters• Performance is all about perception.• People are oblivious to your best.• People will remember your worst.• Outliers are what people perceive the most.• Remember: If the application “feels” fast, it isfast.
  58. 58. “Cheater’s Bag ofTricks”
  59. 59. Goals of “Cheating”Cost to DeliverProbability of RequestLowHighExpensiveRareFreeFrequent Identified ProblemExpensive and frequent.
  60. 60. Cheating GoalsCost to DeliverProbability of RequestLowHighExpensiveRareFreeFrequentOptimization AMethod to reduce cost of delivery.
  61. 61. Cheating GoalsCost to DeliverProbability of RequestLowHighExpensiveRareFreeFrequentOptimization BMethod to reducefrequency ofrequests.
  62. 62. Cheating GoalsCost to DeliverProbability of RequestLowHighExpensiveRareFreeFrequentOptimization A + BCombination reduces cost and frequency.
  63. 63. Real-WorldExamples
  64. 64. Cost to DeliverProbability of RequestLowHighWeather WidgetExpensiveRareFreeFrequentImplementedFetch from API on demandand reformat into widget.
  65. 65. Cost to DeliverProbability of RequestLowHighWeather WidgetExpensiveRareFreeFrequentImplementedFetch from API on demandand reformat into widget.PopularityWidget used by largepercentage of users.
  66. 66. Cost to DeliverProbability of RequestLowHighWeather WidgetExpensiveRareFreeFrequentImplementedFetch from API on demandand reformat into widget.CachedWidget data cached andre-used for different users.PopularityWidget used by largepercentage of users.
  67. 67. Cost to DeliverProbability of RequestLowHighFinancial BlogExpensiveRareFreeFrequentStock SolutionImages are loaded on demandwithout any processing.
  68. 68. Cost to DeliverProbability of RequestLowHighFinancial BlogExpensiveRareFreeFrequentStock SolutionImages are loaded on demandwithout any processing.PopularityBlog becomes very populardue to publicity.
  69. 69. Cost to DeliverProbability of RequestLowHighFinancial BlogExpensiveRareFreeFrequentStock SolutionImages are loaded on demandwithout any processing.PopularityBlog becomes very populardue to publicity.Content ShiftLarge, detailed charts nowa common feature on blog.
  70. 70. Cost to DeliverProbability of RequestLowHighFinancial BlogExpensiveRareFreeFrequentStock SolutionImages are loaded on demandwithout any processing.PopularityBlog becomes very populardue to publicity.Content ShiftLarge, detailed charts nowa common feature on blog.Solution 1Lazy-load images further downpage.
  71. 71. Cost to DeliverProbability of RequestLowHighFinancial BlogExpensiveRareFreeFrequentStock SolutionImages are loaded on demandwithout any processing.PopularityBlog becomes very populardue to publicity.Content ShiftLarge, detailed charts nowa common feature on blog.Solution 2Host images on cloud.Solution 1Lazy-load images further downpage.
  72. 72. Cost to DeliverProbability of RequestLowHighFinancial BlogExpensiveRareFreeFrequentStock SolutionImages are loaded on demandwithout any processing.PopularityBlog becomes very populardue to publicity.Content ShiftLarge, detailed charts nowa common feature on blog.Solution 1Lazy-load images further downpage.Solution 2Host images on cloud.Solution 3Create smaller inline images.
  73. 73. Specific Strategies
  74. 74. Wait Less• Work to minimize perceived wait.• Make things appear instantly.• Don’t block, lock up, or stall.• Flip client state immediately, handle inbackground.
  75. 75. Cost to DeliverProbability of RequestLowHighWait LessExpensiveRareFreeFrequentTarget Zone“Add User Comment”Frequent operation butrequires some heavyprocessing to apply correctly,complicated by convolutedbusiness logic.
  76. 76. Cost to DeliverProbability of RequestLowHighWait LessExpensiveRareFreeFrequentClient State Directly AlteredShow result of user actionimmediately, actually process inbackground.
  77. 77. Wait More• Make things appear important.• Keep user informed: spinners, progress bars.• Keep delay proportional to significance.• Can avoid really expensive requests by beingannoying.
  78. 78. Cost to DeliverProbability of RequestLowHighWait MoreExpensiveRareFreeFrequentTarget Zone“Preview My Book”Requesting too manypreviews can cause severeserver load issues.
  79. 79. Cost to DeliverProbability of RequestLowHighWait MoreExpensiveRareFreeFrequent“Your Book is Queued”Delayed gratification.More ConsiderationPeople less likely to engagefeature needlessly.
  80. 80. Cost to DeliverProbability of RequestLowHighWait MoreExpensiveRareFreeFrequentTarget Zone“Find Best Flight”Might be trivial tocalculate, but perceivedvalue is very high.
  81. 81. Cost to DeliverProbability of RequestLowHighWait MoreExpensiveRareFreeFrequent“Calculating Results...”Artificial delay makes taskseem significant, systemmore powerful.
  82. 82. Load Less• Fetching things on demand.• “Lazy loading”• Ideal for resources that might not be seen.• Refrigerator light principle: Always seemson.
  83. 83. Cost to DeliverProbability of RequestLowHighLoad LessExpensiveRareFreeFrequentTarget Zone“Blog Page, Post N”Things that are requestedbut not always utilized.
  84. 84. Cost to DeliverProbability of RequestLowHighLoad LessExpensiveRareFreeFrequentLazy LoadingPuts of loading a resourceuntil actually required.
  85. 85. Load More• Fetching resources ahead of time.• “Eager loading”• Ideal for resources that will probably be seen.• Boy-scout principle: Be prepared.
  86. 86. Cost to DeliverProbability of RequestLowHighLoad MoreExpensiveRareFreeFrequentTarget Zone “Site Icons”Many, many requestsfor tiny, inexpensiveresources can add up.
  87. 87. Cost to DeliverProbability of RequestLowHighLoad MoreExpensiveRareFreeFrequentAsset BundlingCreate single asset thatcan be used to renderall icons.High Aggregate CostRequesting many tiny resourcescan be expensive.Site IconsVery large number of small files.
  88. 88. Saving Less• Trim, crop, shrink.• Strip out redundant or duplicated content.• Define and enforce limitations.• One size fits all instead of uncertainty.• Consider rendering on demand.
  89. 89. Cost to DeliverProbability of RequestLowHighSaving LessExpensiveRareFreeFrequentTarget Zone“Upload Photo”Users upload full-sizedphotos when only smallerversions are ever actuallydisplayed.
  90. 90. Cost to DeliverProbability of RequestLowHighSaving LessExpensiveRareFreeFrequentReduce Size, CompressShrinking to sizes requiredby actual use cases,compressed to anacceptable level of quality.
  91. 91. Saving More• Make copies of things in different formats.• A form of “caching”, “pre-rendering”• De-normalize your data.• Optimize structure around retrieval patterns.• Try and have everything important readyinstantly.
  92. 92. Cost to DeliverProbability of RequestLowHighSaving MoreExpensiveRareFreeFrequentTarget Zone“Image Variants by Size”Images are used at various fixedsizes, each needing someprocessing to render.
  93. 93. Cost to DeliverProbability of RequestLowHighSaving MoreExpensiveRareFreeFrequentPre-RenderingReduces frequency of requestsrequiring heavy processing.
  94. 94. Cache More• Fastest database call is the one never made.• Pre-cache when you have the data on hand.• Reuse and recycle expensive results.• Let your client cache images, scripts, pages.• Learn to love the “expires” feature.
  95. 95. TargetZoneCost to DeliverProbability of RequestLowHighCache MoreExpensiveRareFreeFrequentTarget ZoneHigh Frequency + CostCache anything you can.Target ZoneHigh FrequencyCache if you can.High CostCache if likely tobe used morethan once.
  96. 96. Cost to DeliverProbability of RequestLowHighCache MoreExpensiveRareFreeFrequent“Friends of My Friends” Database QueryResult unlikely to change except in specificcircumstances. Tricky to compute, easy tocache.
  97. 97. Cost to DeliverProbability of RequestLowHighCache MoreExpensiveRareFreeFrequent“Video Effects Preview”Result of preview saved temporarily.First RequestSecond Request
  98. 98. Cache Less• Tuning your database can make cachingredundant.• Caches can make updates take longer.• Cache invalidation can be really hard.• Cache mistakes can be really embarrassing.• Running without a cache leaves you withheadroom.
  99. 99. Cost to DeliverProbability of RequestLowHighCache LessExpensiveRareFreeFrequentTarget Zone“Premature Optimization”Hiding real costs, creating hiddenliabilities.
  100. 100. Cost to DeliverProbability of RequestLowHighCache LessExpensiveRareFreeFrequent Original ImplementationExpensive and slow.Caching OpportunityPotential performancegain.Cached ResultQuick and easy fix.Refactoring Without CacheSolves actual performanceproblem.
  101. 101. Distribute More• Content distribution networks.• Clustered databases, data replication.• Client-side storage, content bundles.• Push data closer to users.• “Edge caching”
  102. 102. Cost to DeliverProbability of RequestLowHighDistribute MoreExpensiveRareFreeFrequentTargetZone“Server-Side Content”User provided content is storedon your application servers,storage and retrieval is gettingoverwhelming.
  103. 103. Cost to DeliverProbability of RequestLowHighDistribute MoreExpensiveRareFreeFrequentServer Hosted ResourceStored on server, transmissionimpedes other server operations.CDN Hosted ResourceNo effort required to retainand deliver to client.
  104. 104. Distribute Less• Keep data and content local.• Self-hosted databases instead of cloud-hosted.• “Dumb client, smart server” applications.• Way more control over structure, strategy,technology.
  105. 105. Cost to DeliverProbability of RequestLowHighDistribute LessExpensiveRareFreeFrequentTargetZone“Cloud Hosted Metrics Database”Slow, unresponsive API, charged perquery.
  106. 106. Cost to DeliverProbability of RequestLowHighDistribute LessExpensiveRareFreeFrequentRemote Cloud ServiceTakes hundreds of API calls.Local Data WarehouseTakes a few SQL queries.
  107. 107. Purge More• Delete data no longer used.• Archive to cheaper storage systems.• Generate on demand.• Less data equals less overhead.• Minimalist principle.
  108. 108. TargetZoneCost to DeliverProbability of RequestLowHighPurge MoreExpensiveRareFreeFrequent“Outdated, Detailed User Metrics Data”Expensive to retain, not likely to get used.
  109. 109. Cost to DeliverProbability of RequestLowHighPurge MoreExpensiveRareFreeFrequentDeletedNobody will miss it.
  110. 110. Purge Less• Dump it on the cloud, forget about it.• Keep things cached longer.• Pre-render instead of render on demand.• Long-tail: Sometimes unpopular thingsmatter.
  111. 111. Cost to DeliverProbability of RequestLowHighPurge LessExpensiveRareFreeFrequentSave Alternate FormatsAlso store as XML orJSON, exactly sent by API. High Aggregate CostRequests for unrelatedresources can add up.“Movie Actors”Extensive library ofmovies, but queries aren’tpredictable.
  112. 112. Compress More• Lossless or lossy compression.• Use deflate (gzip) for transfers.• Aggressively minify scripts.
  113. 113. Target ZoneCost to DeliverProbability of RequestLowCompress MoreExpensiveRareFreeAlmost AnythingMost resources benefitfrom some form ofcompression.Frequent
  114. 114. Cost to DeliverProbability of RequestLowCompress MoreExpensiveRareFreeFrequentText ResourceSome things compress really well.JPEG Image ResourceSome things can’t becompressed much morewithout damage.
  115. 115. Compress Less• Keep data in pure, raw form.• Databases can’t interact with compresseddata.• Serialized or compressed data can’t bequeried.• Some databases love JSON or key-valuetypes.
  116. 116. Cost to DeliverProbability of RequestLowHighCompress LessExpensiveRareFreeFrequent“User Profile Data”Hundreds of arbitrary fields, stored as JSON.Store as Raw JSONSlightly higher write and retrieval cost.Query JSON in DBMuch lower query cost.
  117. 117. Index More• Every query has a cost.• Examine access patterns, index accordingly.• A query without an index: painful.• A query with a tuned index: bliss.• Indexes massively reduce retrieval time.
  118. 118. Cost to DeliverProbability of RequestLowIndex MoreExpensiveRareFreeFrequent“Message Board Table”Queried very frequently,indexing is vital.Aggressive IndexingUse index to reduce readcost.
  119. 119. Index Less• Every index makes writes more expensive.• Indexes don’t always get used.• Some indexes you might want but not need.• Awkward but fast can be better than easybut slow.
  120. 120. Cost to DeliverProbability of RequestLowIndex LessExpensiveRareFreeFrequentAggressive IndexingWrites aresignificantly moreexpensive.“User Activity Table”More writes thanreads.
  121. 121. Multitask More• Do things in parallel.• Break down dependencies, avoid contention.• Distribute work across many systems.• Map-reduce doesn’t have to be hard.
  122. 122. Cost to DeliverProbability of RequestLowHighMultitask MoreExpensiveRareFreeFrequent“Render Page”Smaller scale task iseasy todelegate to manyworkers.“Render Album Preview”Each page is an independent,but the final book needs to beone file.Perceived ResultProcessing timemassively reduced.
  123. 123. Multitask Less• Stream things in sequentially.• Keep load on server light.• Keeps more network resources available.• Buffer requests and process casually.
  124. 124. Cost to DeliverProbability of RequestLowHighMultitask LessExpensiveRareFreeFrequent“Sync Calendar Entries”Operation that’s expected totake considerable time canbe delayed.Background TasksCreate a simple workqueue to minimizenumber of paralleloperations.
  125. 125. Provision More• Server hardware can be scaled up.• Desktop/mobile apps can leverage serverhardware.• On-demand cloud services can be awesome.• No inherent limit on server capability.• If you can throw hardware at it, maybe dothat.
  126. 126. Cost to DeliverProbability of RequestLowHighProvision MoreExpensiveRareFreeFrequent Relatively ExpensiveUses high percentage of CPU.Relatively InexpensiveSame operation ondistributed server clusteris no big deal.
  127. 127. Provision Less• Keep your application footprint lean.• Don’t burn through CPU and battery.• Don’t use tons of memory.• Smaller apps load faster, don’t get kicked outas often.• Smaller server clusters easier to tune andmanage.
  128. 128. Cost to DeliverProbability of RequestLowHighProvision LessExpensiveRareFreeFrequent“Upload All Photos on Phone”Interrupts application flow, stalls,heavy CPU usage.Batched OperationsSplit up task intosmaller, low-impacttasks.
  129. 129. Breaking Rules
  130. 130. “Cheating”
  131. 131. Focus on theeffects.
  132. 132. Figure the rest out.
  133. 133. Scott Tadmantwg.ca@ceben @twgTHANK YOUScott Tadman / Dom Bortolussitwg.ca@tadmanter @dombort @twggithub.com/tadmantwg.cahello@twg.ca
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×