98
Skeuomorphs, Databases, and Mobile Performance Architecting for performance with devices & APIs Sam Ramji @sramji Apigee groups.google.com/group/ api-craft

Skeuomorphs, Databases, and Mobile Performance

  • Upload
    apigee

  • View
    9.467

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Skeuomorphs, Databases, and Mobile Performance

Skeuomorphs, Databases, and Mobile PerformanceArchitecting for performance with devices & APIs

Sam Ramji @sramjiApigee

groups.google.com/group/api-craft

Page 2: Skeuomorphs, Databases, and Mobile Performance

SKEUOMORPHS

Page 3: Skeuomorphs, Databases, and Mobile Performance

A brief history of architecture

Page 4: Skeuomorphs, Databases, and Mobile Performance

Banister FletcherA History of Architecture

Page 5: Skeuomorphs, Databases, and Mobile Performance
Page 6: Skeuomorphs, Databases, and Mobile Performance
Page 7: Skeuomorphs, Databases, and Mobile Performance

“ Greek columns and their entablatures were at first entirely of timber, with terra-cotta decorations in the upper trabeation, but were converted into stone quite early in the [Hellenic] period, about 600 BC. The translation was quite direct, timber forms being imitated in stonework with remarkable exactness. For this reason, Greek architecture sometimes has been called a ‘carpentry in marble’…

Banister FletcherA History of Architecture

Page 8: Skeuomorphs, Databases, and Mobile Performance
Page 9: Skeuomorphs, Databases, and Mobile Performance
Page 10: Skeuomorphs, Databases, and Mobile Performance
Page 11: Skeuomorphs, Databases, and Mobile Performance
Page 12: Skeuomorphs, Databases, and Mobile Performance
Page 13: Skeuomorphs, Databases, and Mobile Performance

Skeuomorphs and metaphors

Page 14: Skeuomorphs, Databases, and Mobile Performance

Skeuomorph

A skeuomorph is a design feature found on an imitation, pastiche or homage that was necessary only to the original. Often used for the sake of familiarity, they are details that have moved from function to form.

Tom Pettyhipstercheerleaders.com

Page 15: Skeuomorphs, Databases, and Mobile Performance

Metaphor

In cognitive linguistics, conceptual metaphor, or cognitive metaphor, refers to the understanding of one idea, or conceptual domain, in terms of another, for example, understanding quantity in terms of directionality (e.g. "prices are rising").

Wikipedia.orgConceptual Metaphors

Page 16: Skeuomorphs, Databases, and Mobile Performance

“ The concepts that govern our thought are not just matters of the intellect. They also govern our everyday functioning, down to the most mundane details. Our concepts structure what we perceive, how we get around in the world, and how we relate to other people. Our conceptual system thus plays a central role in defining our everyday realities. If we are right in suggesting that our conceptual system is largely metaphorical, then the way we thinks what we experience, and what we do every day is very much a matter of metaphor.

George Lakoff and Mark JohnsonMetaphors We Live By

Page 17: Skeuomorphs, Databases, and Mobile Performance

DATABASES

Page 18: Skeuomorphs, Databases, and Mobile Performance

A brief history of architectureapplication

^

Page 19: Skeuomorphs, Databases, and Mobile Performance

Mainframe

Minicomputer

Integrated

PersonalComputer

Smartphone

Connected Devices

Website

Client/Server

Web App

DCOM

Distributed

CORBA

N-tier

Computing Architectures

Page 20: Skeuomorphs, Databases, and Mobile Performance

Data Architectures

Flat file

Mainframe

Silos

Caching DBs

Domain-specificData APIs

RDBMS

Data APIData

Warehousing

Shared

Private Cloud DBs

Page 21: Skeuomorphs, Databases, and Mobile Performance
Page 22: Skeuomorphs, Databases, and Mobile Performance
Page 23: Skeuomorphs, Databases, and Mobile Performance
Page 24: Skeuomorphs, Databases, and Mobile Performance
Page 25: Skeuomorphs, Databases, and Mobile Performance
Page 26: Skeuomorphs, Databases, and Mobile Performance
Page 27: Skeuomorphs, Databases, and Mobile Performance
Page 28: Skeuomorphs, Databases, and Mobile Performance
Page 29: Skeuomorphs, Databases, and Mobile Performance
Page 30: Skeuomorphs, Databases, and Mobile Performance
Page 31: Skeuomorphs, Databases, and Mobile Performance
Page 32: Skeuomorphs, Databases, and Mobile Performance
Page 33: Skeuomorphs, Databases, and Mobile Performance
Page 34: Skeuomorphs, Databases, and Mobile Performance
Page 35: Skeuomorphs, Databases, and Mobile Performance
Page 36: Skeuomorphs, Databases, and Mobile Performance

API

Page 37: Skeuomorphs, Databases, and Mobile Performance

API

Page 38: Skeuomorphs, Databases, and Mobile Performance

We’ve come back to client-server computing

Page 39: Skeuomorphs, Databases, and Mobile Performance

From the perspective of the mobile client,the Internet is a database.

Page 40: Skeuomorphs, Databases, and Mobile Performance

Is that a skeuomorph or a metaphor?

Page 41: Skeuomorphs, Databases, and Mobile Performance

If the Internet is a database, what have we learned from prior eras aboutarchitecting for performance?

Page 42: Skeuomorphs, Databases, and Mobile Performance

MOBILE PERFORMANCE

Page 43: Skeuomorphs, Databases, and Mobile Performance

The classic client-server problem returns

Page 44: Skeuomorphs, Databases, and Mobile Performance

If the database is slow, the app is slow.

Page 45: Skeuomorphs, Databases, and Mobile Performance

Research shows that people will put up with about 1.5 seconds between interactions.

Page 46: Skeuomorphs, Databases, and Mobile Performance

More than 3 seconds on average and they’ll stop using the app.

Page 47: Skeuomorphs, Databases, and Mobile Performance

This is a problem.

Page 48: Skeuomorphs, Databases, and Mobile Performance

Let’s dig into our client-server history to break it down.

Page 49: Skeuomorphs, Databases, and Mobile Performance

Make the application smarter

Use the network intelligently

Optimize the database aggressively

Page 50: Skeuomorphs, Databases, and Mobile Performance

MAKE THE APPLICATIONSMARTER

Page 51: Skeuomorphs, Databases, and Mobile Performance

What makes the app feel fast to the user?

application

Page 52: Skeuomorphs, Databases, and Mobile Performance

Time to first render

Time to first interaction

Time between interactions

application

Page 53: Skeuomorphs, Databases, and Mobile Performance

Three mutually reinforcing techniques:

Code profiling for performance optimization

Threading/concurrency for user interactions

Client-side caching for everything else

application

Page 54: Skeuomorphs, Databases, and Mobile Performance

Use the profiler to see where you’re slow

Write faster code where you see big gains

Run long operations in parallel

Keep local copies of everything you need

application

Page 55: Skeuomorphs, Databases, and Mobile Performance

Concurrency

application

Page 56: Skeuomorphs, Databases, and Mobile Performance
Page 57: Skeuomorphs, Databases, and Mobile Performance

Anticipation

application

Page 58: Skeuomorphs, Databases, and Mobile Performance
Page 59: Skeuomorphs, Databases, and Mobile Performance
Page 60: Skeuomorphs, Databases, and Mobile Performance

Caching

application

Page 61: Skeuomorphs, Databases, and Mobile Performance
Page 62: Skeuomorphs, Databases, and Mobile Performance
Page 63: Skeuomorphs, Databases, and Mobile Performance

What should you be caching locally?

Security credentials or tokensLast user session dataMRU (Most recently used)MFU (Most frequently used)LFC (Least frequently changed)API write operationsGraceful fallbacks for failed API calls

application

Page 64: Skeuomorphs, Databases, and Mobile Performance

Issues do remain

Can’t hit local cache on first use of appReceiving the right shape of data

application

Page 65: Skeuomorphs, Databases, and Mobile Performance

USE THE NETWORKINTELLIGENTLY

Page 66: Skeuomorphs, Databases, and Mobile Performance

The radio network is a high-latency,

limited-resource environment.

network

Page 67: Skeuomorphs, Databases, and Mobile Performance
Page 68: Skeuomorphs, Databases, and Mobile Performance

Speed and battery usage are both important dimensions of mobile performance

network

Page 69: Skeuomorphs, Databases, and Mobile Performance
Page 70: Skeuomorphs, Databases, and Mobile Performance

Intermittent usage of the radio for

pingbackskeep-alivesanalyticsscreen rotations

will slow you down and burn battery.

network

Page 71: Skeuomorphs, Databases, and Mobile Performance
Page 72: Skeuomorphs, Databases, and Mobile Performance

A better approach:

Bundling, piggybacking, and pipelining

network

Page 73: Skeuomorphs, Databases, and Mobile Performance

Battery cost of a series of small API requests

network

Bundling a set of API requests

Idle

Connectionsetup

Datatransfer

Tailtime

2 sec n sec 15 sec

90 sec of radio use and battery burn

19 sec

Page 74: Skeuomorphs, Databases, and Mobile Performance

Intermittent analytics and keep-alives

network

Piggybacking on a set of user API requests

90 sec of radio use and battery burn

19 sec

Page 75: Skeuomorphs, Databases, and Mobile Performance

API calls in series

network

API pipelining

200 ms 200 ms 200 ms 200 ms 200 ms

1000 ms

Page 76: Skeuomorphs, Databases, and Mobile Performance

Bundling loosely-related requests together

Piggybacking secondary intermittent traffic

Pipelining requests to maximize throughput

Page 77: Skeuomorphs, Databases, and Mobile Performance

OPTIMIZE THE DATABASEAGGRESSIVELY

Page 78: Skeuomorphs, Databases, and Mobile Performance

What were our old database optimization tricksthat we can apply to Internet data?

database

Page 79: Skeuomorphs, Databases, and Mobile Performance

database

Stored Procedures

Queueing

Denormalization

Result Sets

Page 80: Skeuomorphs, Databases, and Mobile Performance

database

What is a Stored Procedure in this world?

Server-side code that executes complex operations

Ones that should happen right next to the data

Where you need high compute and low latency

Could be written in node.js, ruby, java, python, c#

Page 81: Skeuomorphs, Databases, and Mobile Performance

database

Where does a Stored Procedure run in this world?

Page 82: Skeuomorphs, Databases, and Mobile Performance

database

Where does a Stored Procedure run in this world?

Probably in a cloud

Page 83: Skeuomorphs, Databases, and Mobile Performance

Once you’ve built this architectural layeryou gain a lot of control

database

Page 84: Skeuomorphs, Databases, and Mobile Performance

You can deal with queueing, denormalization, and manage result sets properly.

database

Page 85: Skeuomorphs, Databases, and Mobile Performance

Queueing enables you to break the request/response pair into separate pieces

You may even be able to tell the client when to call you back for the result

Making your requests to this queueing layer also lets you serve from a cloud-side cache if you have one

database

Page 86: Skeuomorphs, Databases, and Mobile Performance

Denormalization refers to writing multiple indexes in order to optimize query performance

Where your app relies on your own data, don’t make it wait for slow queries

Remember, in the cloud, storage is cheap and easy to obtain – write data as often as needed to improve query speeds.

database

Page 87: Skeuomorphs, Databases, and Mobile Performance

Managing result sets to save bandwidth and response time means limiting cursor size by default

This can be complementary to the caches you keep around, since a massive API result is cheap to manage in the cloud

and can be trickled back to the app in bite-size chunks.

database

Page 88: Skeuomorphs, Databases, and Mobile Performance

Managing result sets to save processor time for the client is an option as well.

What would happen if you could focus onapp-shaped data?

database

Page 89: Skeuomorphs, Databases, and Mobile Performance

var parseXml; if (typeof window.DOMParser != "undefined") { parseXml = function(xmlStr) {

return (new window.DOMParser()).parseFromString(xmlStr,"text/xml"); }; } else if (typeof window.ActiveXObject != "undefined" && new window.ActiveXObject("Microsoft.XMLDOM")) { parseXml = function(xmlStr) { var xmlDoc = new window.ActiveXObject("Microsoft.XMLDOM"); xmlDoc.async = "false"; xmlDoc.loadXML(xmlStr); return xmlDoc; }; } else { throw new Error("No XML parser found"); }

var xml = parseXml("<result>true</result><count>1</count>"); alert(xml.documentElement.nodeName);

XML in Javascript

Page 90: Skeuomorphs, Databases, and Mobile Performance

JSON in Javascript

var json = '{"result":true,"count":1}', obj = JSON.parse(json);

alert(obj.count);

Page 91: Skeuomorphs, Databases, and Mobile Performance

INCLOSING

Page 92: Skeuomorphs, Databases, and Mobile Performance

There are a few things we can borrow from the pastto help us right now

Page 93: Skeuomorphs, Databases, and Mobile Performance

Make the application smarter

Use the network intelligently

Optimize the database aggressively

Page 94: Skeuomorphs, Databases, and Mobile Performance

What did you decide about the statement

“The internet is a database”?

Page 95: Skeuomorphs, Databases, and Mobile Performance

Carpentry in marble?

or cognitive tool?

Page 96: Skeuomorphs, Databases, and Mobile Performance

Skeuomorph?

or metaphor?

Page 97: Skeuomorphs, Databases, and Mobile Performance

groups.google.com/group/api-craft

Page 98: Skeuomorphs, Databases, and Mobile Performance

THANK YOUQuestions and ideas to:

@sramji

groups.google.com/group/api-craft