Top Banner
Copyright 2012 & 2015 – Noah Mendelsohn Scalability, Performance & Caching Noah Mendelsohn Tufts University Email: [email protected] Web: http://www.cs.tufts.edu/~noah COMP 150-IDS: Internet Scale Distributed Systems (Spring 2015)
42

Copyright 2012 & 2015 – Noah Mendelsohn Scalability, Performance & Caching Noah Mendelsohn Tufts University Email: [email protected]@cs.tufts.edu Web:

Dec 31, 2015

Download

Documents

Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Copyright 2012 & 2015 – Noah Mendelsohn Scalability, Performance & Caching Noah Mendelsohn Tufts University Email: noah@cs.tufts.edunoah@cs.tufts.edu Web:

Copyright 2012 & 2015 – Noah Mendelsohn

Scalability, Performance&

Caching

Noah MendelsohnTufts UniversityEmail: [email protected]: http://www.cs.tufts.edu/~noah

COMP 150-IDS: Internet Scale Distributed Systems (Spring 2015)

Page 2: Copyright 2012 & 2015 – Noah Mendelsohn Scalability, Performance & Caching Noah Mendelsohn Tufts University Email: noah@cs.tufts.edunoah@cs.tufts.edu Web:

© 2010 Noah Mendelsohn2

Goals

Explore some general principles of performance, scalability and caching

Explore key issues relating to performance and scalability of the Web

Page 3: Copyright 2012 & 2015 – Noah Mendelsohn Scalability, Performance & Caching Noah Mendelsohn Tufts University Email: noah@cs.tufts.edunoah@cs.tufts.edu Web:

© 2010 Noah Mendelsohn3

Performance Concepts and Terminology

Page 4: Copyright 2012 & 2015 – Noah Mendelsohn Scalability, Performance & Caching Noah Mendelsohn Tufts University Email: noah@cs.tufts.edunoah@cs.tufts.edu Web:

© 2010 Noah Mendelsohn

Performance, Scalability, Availability, Reliability

Performance– Get a lot done quickly– Preferably a low cost

Scalability– Low barriers to growth– A scalable system isn’t necessarily fast…– …but it can grow without slowing down

Availability– Always there when you need it

Reliability– Never does the wrong thing, never loses or corrupts data

4

Page 5: Copyright 2012 & 2015 – Noah Mendelsohn Scalability, Performance & Caching Noah Mendelsohn Tufts University Email: noah@cs.tufts.edunoah@cs.tufts.edu Web:

© 2010 Noah Mendelsohn

Throughput vs. Response Time vs. Latency

Throughput: the aggregate rate at which a system does work

Response time: the time to get a response to a request

Latency: time spent waiting (e.g. for disk or network)

We can improve throughput by:– Minimizing work done per request– Doing enough work at once to keep all hardware resources busy…– …and when some work is delayed (latency) find other work to do

We can improve response time by:– Minimizing total work and delay (latency) on critical path to a response– Applying parallel resources to an individual response…including streaming– Precomputing response values

5

Page 6: Copyright 2012 & 2015 – Noah Mendelsohn Scalability, Performance & Caching Noah Mendelsohn Tufts University Email: noah@cs.tufts.edunoah@cs.tufts.edu Web:

© 2010 Noah Mendelsohn6

Know How Fast Things Are

Page 7: Copyright 2012 & 2015 – Noah Mendelsohn Scalability, Performance & Caching Noah Mendelsohn Tufts University Email: noah@cs.tufts.edunoah@cs.tufts.edu Web:

© 2010 Noah Mendelsohn7

Typical “speeds n feeds”

CPU (e.g. Intel Core I7): – A few billions instructions / second per core– Memory: 20GB/sec (20 bytes/instruction executed)

Long distance network– Latency (ping time): 10-100ms– Bandwidth: 5 – 100 Mb/sec

Local area network (Gbit Ethernet)– Latency: 50-100usec (note microseconds)– Bandwidth: 1 Gb/sec (100mbytes/sec)

Hard disk– Rotational delay: 5ms– Seek time: 5 – 10 ms– Bandwidth from magenetic media: 1Gbit/sec

SSD – Setup time: 100usec– Bandwidth: 2Gbit/sec (typical) note: SSD wins big on latency, some on bandwidth

Page 8: Copyright 2012 & 2015 – Noah Mendelsohn Scalability, Performance & Caching Noah Mendelsohn Tufts University Email: noah@cs.tufts.edunoah@cs.tufts.edu Web:

© 2010 Noah Mendelsohn8

Making Systems FasterHiding Latency

Page 9: Copyright 2012 & 2015 – Noah Mendelsohn Scalability, Performance & Caching Noah Mendelsohn Tufts University Email: noah@cs.tufts.edunoah@cs.tufts.edu Web:

© 2010 Noah Mendelsohn

Hard disks are slow

Platter

Sector

Page 10: Copyright 2012 & 2015 – Noah Mendelsohn Scalability, Performance & Caching Noah Mendelsohn Tufts University Email: noah@cs.tufts.edunoah@cs.tufts.edu Web:

© 2010 Noah Mendelsohn

Handling disk data the slow way

Sector

The Slow Way

• Read a block• Compute on block• Read another block• Compute on other block• Rinse and repeat

Computer waits msec while reading disk 1000s of instruction times!

Page 11: Copyright 2012 & 2015 – Noah Mendelsohn Scalability, Performance & Caching Noah Mendelsohn Tufts University Email: noah@cs.tufts.edunoah@cs.tufts.edu Web:

© 2010 Noah Mendelsohn

Faster way: overlap to hide latency

The Faster Way

• Read a block• Start reading another block• Compute on 1st block• Start reading 3rd block• Compute on 2nd block• Rinse and repeat

Buffering: we’re reading ahead…computing while reading!

Sector

Page 12: Copyright 2012 & 2015 – Noah Mendelsohn Scalability, Performance & Caching Noah Mendelsohn Tufts University Email: noah@cs.tufts.edunoah@cs.tufts.edu Web:

© 2010 Noah Mendelsohn12

Making Systems FasterBottlenecks and Parallelism

Page 13: Copyright 2012 & 2015 – Noah Mendelsohn Scalability, Performance & Caching Noah Mendelsohn Tufts University Email: noah@cs.tufts.edunoah@cs.tufts.edu Web:

© 2010 Noah Mendelsohn

Amdahl’s claim: parallel processing won’t scale

13

1967: Major controversy …will parallel computers work?

“Demonstration is made of the continued validity of the single processor approach and of the weaknesses of the multiple processor approach in terms of application to real problems and their attendant irregularities. Gene Amdahl*”

* Gene Amdahl, Validity of the single processor approach to achieving large scale computing capabilities, AFIPS spring joint computer conference, 1967 http://www-inst.eecs.berkeley.edu/~n252/paper/Amdahl.pdf

Page 14: Copyright 2012 & 2015 – Noah Mendelsohn Scalability, Performance & Caching Noah Mendelsohn Tufts University Email: noah@cs.tufts.edunoah@cs.tufts.edu Web:

© 2010 Noah Mendelsohn

Amdahl: why no parallel scaling?

14

“The first characteristic of interest is the fraction of the computational load which is associated with data management housekeeping. This fraction […might eventually be reduced to 20%...]. The nature of this overhead appears to be sequential so that it is unlikely to be amenable to parallel processing techniques. Overhead alone would then place an upper limit on throughput of five to seven times the sequential processing rate. Gene Amdahl (Ibid)

In short: even if the part you’re optimizing went to zero time, the speedup would be only 5x.

Speedup = 1/(rs +(rp/n))where rs and rp are sequential/parallel fractions of computation

As rp/n 0, Speedup -> 1/rs

Page 15: Copyright 2012 & 2015 – Noah Mendelsohn Scalability, Performance & Caching Noah Mendelsohn Tufts University Email: noah@cs.tufts.edunoah@cs.tufts.edu Web:

© 2010 Noah Mendelsohn15

Web Performance and Scaling

Page 16: Copyright 2012 & 2015 – Noah Mendelsohn Scalability, Performance & Caching Noah Mendelsohn Tufts University Email: noah@cs.tufts.edunoah@cs.tufts.edu Web:

© 2010 Noah Mendelsohn

Web Performance & Scalability Goals

Overall Web Goals:– Extraordinary scalability, with good performance– Therefore…very high aggregate throughput (think of all the accesses being

made this second)– Economical to deploy (modest cost/user)– Be a good citizen on the Internet

Web servers:– Decent performance, high throughput and scalability

Web clients (browsers):– Low latency (quick response for users)– Reasonable burden on PC– Minimize memory and CPU on small devices

16

Page 17: Copyright 2012 & 2015 – Noah Mendelsohn Scalability, Performance & Caching Noah Mendelsohn Tufts University Email: noah@cs.tufts.edunoah@cs.tufts.edu Web:

© 2010 Noah Mendelsohn

What we’ve already studied about Web scalability…

Web Builds on scalable hi-perf. Internet infrastructure:– IP– DNS– TCP

Decentralized administration & deployment– The only thing resembling a global, central Web server is the DNS root– URI generation

Stateless protocols– Relatively easy to add servers

17

Page 18: Copyright 2012 & 2015 – Noah Mendelsohn Scalability, Performance & Caching Noah Mendelsohn Tufts University Email: noah@cs.tufts.edunoah@cs.tufts.edu Web:

© 2010 Noah Mendelsohn

Web server scaling

Web-ServerApplication - logic

Browser

Data store

ReservationRecords

Page 19: Copyright 2012 & 2015 – Noah Mendelsohn Scalability, Performance & Caching Noah Mendelsohn Tufts University Email: noah@cs.tufts.edunoah@cs.tufts.edu Web:

© 2010 Noah Mendelsohn

Stateless HTTP protocol helps scalability

Web-ServerApplication - logic

Browser

Data store

Web-ServerApplication - logic

Browser

Web-ServerApplication - logic

Browser

Page 20: Copyright 2012 & 2015 – Noah Mendelsohn Scalability, Performance & Caching Noah Mendelsohn Tufts University Email: noah@cs.tufts.edunoah@cs.tufts.edu Web:

© 2010 Noah Mendelsohn20

Caching

Page 21: Copyright 2012 & 2015 – Noah Mendelsohn Scalability, Performance & Caching Noah Mendelsohn Tufts University Email: noah@cs.tufts.edunoah@cs.tufts.edu Web:

© 2010 Noah Mendelsohn21

There are only two hard things in Computer Science: cache invalidation and naming things.

-- Phil Karlton

Page 22: Copyright 2012 & 2015 – Noah Mendelsohn Scalability, Performance & Caching Noah Mendelsohn Tufts University Email: noah@cs.tufts.edunoah@cs.tufts.edu Web:

© 2010 Noah Mendelsohn

Why does caching work at all?

Locality:– In many computer systems, a small fraction of data gets most of the accesses– In other systems, a slowly changing set of data is accessed repeatedly

History: use of memory by typical programs– Denning’s Working Set Theory*– Early demonstration of locality in program access to memory– Justified paged virtual memory with LRU replacement algorithm– Also indirectly explains why CPU caches work

But…not all data-intensive programs follow the theory:– Video processing!– Many simulations– Hennessy and Patterson: running vector (think MMX/SIMD) data through the

CPU cache was a big mistake in IBM mainframe vector implementations

22

* Peter J. Denning, The Working Set Model for Program Behavior, 1968http://cs.gmu.edu/cne/pjd/PUBS/WSModel_1968.pdf

Also 2008 overview on locality from Denning:http://denninginstitute.com/pjd/PUBS/ENC/locality08.pdf

Page 23: Copyright 2012 & 2015 – Noah Mendelsohn Scalability, Performance & Caching Noah Mendelsohn Tufts University Email: noah@cs.tufts.edunoah@cs.tufts.edu Web:

© 2010 Noah Mendelsohn

Why is caching hard?

23

Things change

Telling everyone when things change adds overhead

So, we’re tempted to cheat……caches out of sync with reality

Page 24: Copyright 2012 & 2015 – Noah Mendelsohn Scalability, Performance & Caching Noah Mendelsohn Tufts University Email: noah@cs.tufts.edunoah@cs.tufts.edu Web:

© 2010 Noah Mendelsohn

CPU Caching – Simple System

24

CPU

Memory

CACHE

Read data

Read data

Read dataRead request

Read request

Page 25: Copyright 2012 & 2015 – Noah Mendelsohn Scalability, Performance & Caching Noah Mendelsohn Tufts University Email: noah@cs.tufts.edunoah@cs.tufts.edu Web:

© 2010 Noah Mendelsohn

CPU Caching – Simple System

25

CPU

Memory

CACHERead data

Read dataRepeated readrequest

Life is GoodNo Traffic to Slow Memory

Page 26: Copyright 2012 & 2015 – Noah Mendelsohn Scalability, Performance & Caching Noah Mendelsohn Tufts University Email: noah@cs.tufts.edunoah@cs.tufts.edu Web:

© 2010 Noah Mendelsohn

CPU Caching – Store Through Writing

26

CPU

Memory

CACHEWrite data

Write request

Write request

Everything is up-to-date……but every write waits for slow memory!

Page 27: Copyright 2012 & 2015 – Noah Mendelsohn Scalability, Performance & Caching Noah Mendelsohn Tufts University Email: noah@cs.tufts.edunoah@cs.tufts.edu Web:

© 2010 Noah Mendelsohn

CPU Caching – Store In Writing

27

CPU

Memory

CACHEWrite data

Write request

The write is fast, but memory is out of date!

Page 28: Copyright 2012 & 2015 – Noah Mendelsohn Scalability, Performance & Caching Noah Mendelsohn Tufts University Email: noah@cs.tufts.edunoah@cs.tufts.edu Web:

© 2010 Noah Mendelsohn

CPU Caching – Store In Writing

28

CPU

Memory

CACHEWrite data

If we try to write data from memory to disk, the wrong data will go out!

Page 29: Copyright 2012 & 2015 – Noah Mendelsohn Scalability, Performance & Caching Noah Mendelsohn Tufts University Email: noah@cs.tufts.edunoah@cs.tufts.edu Web:

© 2010 Noah Mendelsohn

Cache invalidation is hard!

29

CPU

Memory

CACHEWrite dataWe can start to see why cache

invalidation is hard!

Page 30: Copyright 2012 & 2015 – Noah Mendelsohn Scalability, Performance & Caching Noah Mendelsohn Tufts University Email: noah@cs.tufts.edunoah@cs.tufts.edu Web:

© 2010 Noah Mendelsohn

Multi-core CPU caching

30

CPU

Memory

CACHE

Write request

CPU

CACHE

CACHE

CoherenceProtocol

Page 31: Copyright 2012 & 2015 – Noah Mendelsohn Scalability, Performance & Caching Noah Mendelsohn Tufts University Email: noah@cs.tufts.edunoah@cs.tufts.edu Web:

© 2010 Noah Mendelsohn

Data

Multi-core CPU caching

31

CPU

Memory

CACHE

Write request

CPU

CACHE

Read request

CACHE

CoherenceProtocol

Data

Data

Page 32: Copyright 2012 & 2015 – Noah Mendelsohn Scalability, Performance & Caching Noah Mendelsohn Tufts University Email: noah@cs.tufts.edunoah@cs.tufts.edu Web:

© 2010 Noah Mendelsohn

Data

Multi-core CPU caching

32

CPU

Memory

CACHE

Write request

CPU

CACHE

Disk read request

CACHE

CoherenceProtocol

Data

Disk Data

A read from disk must flush all caches

Data

Data

Page 33: Copyright 2012 & 2015 – Noah Mendelsohn Scalability, Performance & Caching Noah Mendelsohn Tufts University Email: noah@cs.tufts.edunoah@cs.tufts.edu Web:

© 2010 Noah Mendelsohn

Consistency vs. performance

Caching involves difficult tradeoffs

Coherence is the enemy of performance!– This proves true over and over in lots of systems– There’s a ton of research on weak-consistency models…

Weak consistency: let things get out of sync sometimes– Programming: compilers and libraries can hide or even exploit weak

consistency

Yet another example of leaky abstractions!

33

Page 34: Copyright 2012 & 2015 – Noah Mendelsohn Scalability, Performance & Caching Noah Mendelsohn Tufts University Email: noah@cs.tufts.edunoah@cs.tufts.edu Web:

© 2010 Noah Mendelsohn34

What about Web Caching?

Note: update rate on Web is mostly low – makes things easier!

Page 35: Copyright 2012 & 2015 – Noah Mendelsohn Scalability, Performance & Caching Noah Mendelsohn Tufts University Email: noah@cs.tufts.edunoah@cs.tufts.edu Web:

© 2010 Noah Mendelsohn

Browsers have caches

E.g. Firefox E.g. Apache

BrowserUsually includes a cache!

Web Server

Browser cache prevents repeated requestsfor same representations

Page 36: Copyright 2012 & 2015 – Noah Mendelsohn Scalability, Performance & Caching Noah Mendelsohn Tufts University Email: noah@cs.tufts.edunoah@cs.tufts.edu Web:

© 2010 Noah Mendelsohn

Browsers have caches

E.g. Firefox E.g. Apache

BrowserUsually includes a cache!

Web Server

Browser cache prevents repeated requestsfor same representations…even different pages share images stylesheets, etc.

Page 37: Copyright 2012 & 2015 – Noah Mendelsohn Scalability, Performance & Caching Noah Mendelsohn Tufts University Email: noah@cs.tufts.edunoah@cs.tufts.edu Web:

© 2010 Noah Mendelsohn

Web Reservation System

Web ServerApplication - logic

Browser or Phone App Data Store

iPhone or AndroidReservation Application

Flight ReservationLogic

ReservationRecords

Many commercial applications work this way

E.g. Squid

Proxy Cache(optional!)

HTTPHTTP RPC? ODBC? Proprietary?

Page 38: Copyright 2012 & 2015 – Noah Mendelsohn Scalability, Performance & Caching Noah Mendelsohn Tufts University Email: noah@cs.tufts.edunoah@cs.tufts.edu Web:

© 2010 Noah Mendelsohn

HTTP Caches Help Web to Scale

Browser

Browser

Browser

Data store

Web-ServerApplication -

logic

Web-ServerApplication -

logic

Web-ServerApplication -

logic

Web ProxyCache

Web ProxyCache

Web ProxyCache

Page 39: Copyright 2012 & 2015 – Noah Mendelsohn Scalability, Performance & Caching Noah Mendelsohn Tufts University Email: noah@cs.tufts.edunoah@cs.tufts.edu Web:

© 2010 Noah Mendelsohn39

Web Caching Details

Page 40: Copyright 2012 & 2015 – Noah Mendelsohn Scalability, Performance & Caching Noah Mendelsohn Tufts University Email: noah@cs.tufts.edunoah@cs.tufts.edu Web:

© 2010 Noah Mendelsohn

HTTP Headers for Caching Cache-control: max-age:

– Server indicates how long response is good Heuristics:

– If no explicit times, cache can guess Caches check with server when content has expired

– Sends ordinary GET w/validator headers– Validators: Modified time (1 sec resolution); Etag (opaque code)– Server returns “304 Not Modified” or new content

Cache-control: override default caching rules– E.g. client forces check for fresh copy– E.g. client explicitly allows stale data (for performance, availability)

Caches inform downstream clients/proxies of response age PUT/POST/DELETE clear caches, but…

– No guarantee that updates go through same proxies as all reads!– Don’t mark as cacheable things you expect to update through parallel proxies!

40

Page 41: Copyright 2012 & 2015 – Noah Mendelsohn Scalability, Performance & Caching Noah Mendelsohn Tufts University Email: noah@cs.tufts.edunoah@cs.tufts.edu Web:

© 2010 Noah Mendelsohn41

Summary

Page 42: Copyright 2012 & 2015 – Noah Mendelsohn Scalability, Performance & Caching Noah Mendelsohn Tufts University Email: noah@cs.tufts.edunoah@cs.tufts.edu Web:

© 2010 Noah Mendelsohn42

Summary

We have studied some key principles and techniques relating to peformance and scalability– Amdahl’s law– Buffering and caching – Stateless protocols, etc.

The Web is a highly scalable system w/most OK performance

Web approaches to scalability– Built on scalable Internet infrastructure– Few single points of control (DNS root changes slowly and available in parallel)– Administrative scalability: no central Web site registry

Web performance and scalability– Very high parallelism (browsers, servers all run in parallel)– Stateless protocols support scale out– Caching