failure comes in flavors 1: stability...

70
Michael Nygard [email protected] www.michaelnygard.com Failure Comes in Flavors 1: Stability Antipatterns © Michael Nygard, 2009

Upload: others

Post on 18-Aug-2020

1 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Failure Comes in Flavors 1: Stability Antipatternsgotocon.com/dl/jaoo-sydney-2009/slides/MichaelT... · Less obvious: Multiple connection pools, cross-tier deadlock Thread A holds

Michael [email protected]

Failure Comes in Flavors 1:Stability Antipatterns

© Michael Nygard, 2009

Page 2: Failure Comes in Flavors 1: Stability Antipatternsgotocon.com/dl/jaoo-sydney-2009/slides/MichaelT... · Less obvious: Multiple connection pools, cross-tier deadlock Thread A holds

About the Speaker

Michael Nygard

Application Developer/Architect – 20 yearsWeb Developer – 14 yearsIT Operations – 6 Years

2

Page 3: Failure Comes in Flavors 1: Stability Antipatternsgotocon.com/dl/jaoo-sydney-2009/slides/MichaelT... · Less obvious: Multiple connection pools, cross-tier deadlock Thread A holds

Consequences of Failure

3

Page 4: Failure Comes in Flavors 1: Stability Antipatternsgotocon.com/dl/jaoo-sydney-2009/slides/MichaelT... · Less obvious: Multiple connection pools, cross-tier deadlock Thread A holds

High-Consequence Environments

Users in the thousands and tens of thousands24 hours a day, 365 days a yearMillions in hardware and softwareMillions (or billions) in revenueHighly interdependent systems

4

Page 5: Failure Comes in Flavors 1: Stability Antipatternsgotocon.com/dl/jaoo-sydney-2009/slides/MichaelT... · Less obvious: Multiple connection pools, cross-tier deadlock Thread A holds

Business At Scale

Manufacturer500,000 products10,000,000 media itemsDozens of channel partnersThousands of distributors

Page 6: Failure Comes in Flavors 1: Stability Antipatternsgotocon.com/dl/jaoo-sydney-2009/slides/MichaelT... · Less obvious: Multiple connection pools, cross-tier deadlock Thread A holds

Business At Scale

Financial Services HubUS$10,000,000 per transaction13x1012 annual volume

Page 7: Failure Comes in Flavors 1: Stability Antipatternsgotocon.com/dl/jaoo-sydney-2009/slides/MichaelT... · Less obvious: Multiple connection pools, cross-tier deadlock Thread A holds

Business At Scale

Peak hour for a top 10 retailer40,000 orders per hour10,000,000 page views1,000,000,000 HTTP requestsUS$1,000,000 sales

Page 8: Failure Comes in Flavors 1: Stability Antipatternsgotocon.com/dl/jaoo-sydney-2009/slides/MichaelT... · Less obvious: Multiple connection pools, cross-tier deadlock Thread A holds

Downtime Costs

Availability

Downtime per month

Cost permonth (USD)

88% 98% 99.9% 99.999%

3.6 days 14.4 hours 43 minutes 25 seconds

$8,640,000 $1,440,000 $72,000 $720

Sources: mValent Inc survey of IT Executives at Fortune 1000 companies. One third stated that application downtime costs $300,000 per hour or more.

Wily Technology (now part of Computer Associates) benchmark report on J2EE Application Performance and Availability shows typical JEE availability of 88%.

8

Page 9: Failure Comes in Flavors 1: Stability Antipatternsgotocon.com/dl/jaoo-sydney-2009/slides/MichaelT... · Less obvious: Multiple connection pools, cross-tier deadlock Thread A holds

Free Floating Hostility

In 2004, an unpatched Windows box would be compromised in an average of 16 minutes.

Things have improved, though...

... it’s now down to 4 minutes.

9

Page 10: Failure Comes in Flavors 1: Stability Antipatternsgotocon.com/dl/jaoo-sydney-2009/slides/MichaelT... · Less obvious: Multiple connection pools, cross-tier deadlock Thread A holds

Limits of QA

We don’t “allow” these things to happen.

They happen when we cannot prevent them.

QA and testing are valuable, but limited.

Testing only verifies functional behaviours.

It’s costly to test non-functional ones.

Systems in QA run for a few hours or days, under minimal load. In production, they runs for weeks and months under heavy load.

Real users are always less predictable than test scripts. Even randomized inputs are still well-behaved.

Page 11: Failure Comes in Flavors 1: Stability Antipatternsgotocon.com/dl/jaoo-sydney-2009/slides/MichaelT... · Less obvious: Multiple connection pools, cross-tier deadlock Thread A holds

Limits of QA

We don’t “allow” these things to happen.

They happen when we cannot prevent them.

QA and testing are valuable, but limited.

Testing only verifies functional behaviours.

It’s costly to test non-functional ones.

Systems in QA run for a few hours or days, under minimal load. In production, they runs for weeks and months under heavy load.

Real users are always less predictable than test scripts. Even randomized inputs are still well-behaved.

Page 12: Failure Comes in Flavors 1: Stability Antipatternsgotocon.com/dl/jaoo-sydney-2009/slides/MichaelT... · Less obvious: Multiple connection pools, cross-tier deadlock Thread A holds

Limits of QA

We don’t “allow” these things to happen.

They happen when we cannot prevent them.

QA and testing are valuable, but limited.

Testing only verifies functional behaviours.

It’s costly to test non-functional ones.

Systems in QA run for a few hours or days, under minimal load. In production, they runs for weeks and months under heavy load.

Real users are always less predictable than test scripts. Even randomized inputs are still well-behaved.

Page 13: Failure Comes in Flavors 1: Stability Antipatternsgotocon.com/dl/jaoo-sydney-2009/slides/MichaelT... · Less obvious: Multiple connection pools, cross-tier deadlock Thread A holds

Limits of QA

We don’t “allow” these things to happen.

They happen when we cannot prevent them.

QA and testing are valuable, but limited.

Testing only verifies functional behaviours.

It’s costly to test non-functional ones.

Systems in QA run for a few hours or days, under minimal load. In production, they runs for weeks and months under heavy load.

Real users are always less predictable than test scripts. Even randomized inputs are still well-behaved.

Page 14: Failure Comes in Flavors 1: Stability Antipatternsgotocon.com/dl/jaoo-sydney-2009/slides/MichaelT... · Less obvious: Multiple connection pools, cross-tier deadlock Thread A holds

No amount of testing will suffice.

Some problems can only be engineered out.

11

Page 15: Failure Comes in Flavors 1: Stability Antipatternsgotocon.com/dl/jaoo-sydney-2009/slides/MichaelT... · Less obvious: Multiple connection pools, cross-tier deadlock Thread A holds

Introducing Stability

© Michael Nygard, 2009 12

Page 16: Failure Comes in Flavors 1: Stability Antipatternsgotocon.com/dl/jaoo-sydney-2009/slides/MichaelT... · Less obvious: Multiple connection pools, cross-tier deadlock Thread A holds

Stability Under Stress

Stability under stress is resilience to transient problems

User load

Back-end outages

Network slowdowns

Other “exogenous impulses”

There is no such thing as perfect stability; you are buying timeHow long is your shortest fuse?

Page 17: Failure Comes in Flavors 1: Stability Antipatternsgotocon.com/dl/jaoo-sydney-2009/slides/MichaelT... · Less obvious: Multiple connection pools, cross-tier deadlock Thread A holds

Stability Over Time

How long can a process or server run before it needs to be restarted? Is data produced and purged at the same rate?Usually not tested in development or QA. Too many rapid restarts.

x

y

h

Page 18: Failure Comes in Flavors 1: Stability Antipatternsgotocon.com/dl/jaoo-sydney-2009/slides/MichaelT... · Less obvious: Multiple connection pools, cross-tier deadlock Thread A holds

© Michael Nygard, 2009

System-Wide Stability

15

SeverabilityLimit functionality instead of crashing completely.

ToleranceAbsorb shocks, but do not transmit them.

RecoverabilityAllow component restarts, don’t reboot the world.

ResilienceRecover from transient effects automatically.

Page 19: Failure Comes in Flavors 1: Stability Antipatternsgotocon.com/dl/jaoo-sydney-2009/slides/MichaelT... · Less obvious: Multiple connection pools, cross-tier deadlock Thread A holds

Stability Antipatterns

© Michael Nygard, 2009 16

Page 20: Failure Comes in Flavors 1: Stability Antipatternsgotocon.com/dl/jaoo-sydney-2009/slides/MichaelT... · Less obvious: Multiple connection pools, cross-tier deadlock Thread A holds

Integration Points Attacks of Self-Denial

Resource Leaks Scaling Effects

Chain Reactions Unbalanced Capacities

Cascading Failures Slow Responses

Users SLA Inversion

Blocked Threads Unbounded Result Sets

Page 21: Failure Comes in Flavors 1: Stability Antipatternsgotocon.com/dl/jaoo-sydney-2009/slides/MichaelT... · Less obvious: Multiple connection pools, cross-tier deadlock Thread A holds

Integration Points

Integrations are the #1 risk to stability.

Your first job is to protectagainst integration points.Every socket, process, pipe, or remote procedure call can and will eventually kill your system.Even database calls can hang, in obvious and not-so-obvious ways.

Page 22: Failure Comes in Flavors 1: Stability Antipatternsgotocon.com/dl/jaoo-sydney-2009/slides/MichaelT... · Less obvious: Multiple connection pools, cross-tier deadlock Thread A holds

Example: Database hang

Obvious version: Deadly EmbraceTextbook solution: Uniform transaction orderingPragmatic solution: Use a database server that can detect deadlocks and break them.

Your application logic must be prepared for commit failures!

Less obvious: Multiple connection pools, cross-tier deadlock Thread A holds last connection from pool A; needs to lock rows in table T.Thread B holds rows locks in T; cannot commit until it gets a connection from pool A. Simple solution: Use one connection pool

Page 23: Failure Comes in Flavors 1: Stability Antipatternsgotocon.com/dl/jaoo-sydney-2009/slides/MichaelT... · Less obvious: Multiple connection pools, cross-tier deadlock Thread A holds

Example: Database hang

Obvious version: Deadly EmbraceTextbook solution: Uniform transaction orderingPragmatic solution: Use a database server that can detect deadlocks and break them.

Your application logic must be prepared for commit failures!

Less obvious: Multiple connection pools, cross-tier deadlock Thread A holds last connection from pool A; needs to lock rows in table T.Thread B holds rows locks in T; cannot commit until it gets a connection from pool A. Simple solution: Use one connection pool

Page 24: Failure Comes in Flavors 1: Stability Antipatternsgotocon.com/dl/jaoo-sydney-2009/slides/MichaelT... · Less obvious: Multiple connection pools, cross-tier deadlock Thread A holds

Example: Wicked database hang

Not at all obvious: Firewall idle connection timeout“Connection” is an abstraction.

The firewall only sees packets.

It keeps a table of “live” connections.

When the firewall sees a TCP teardown sequence, itremoves that connection from the table.

To avoid resource leaks, it will drop entries from table after idle period timeout.

Causes broken database connections after long idle period, like 2 a.m. to 5 a.m.

Simple solution: Enable “dead connection detection” (Oracle) or similar feature to keep connection alive.Alternative solution: timed job to periodically issue trivial query.

What about prevention?

Page 25: Failure Comes in Flavors 1: Stability Antipatternsgotocon.com/dl/jaoo-sydney-2009/slides/MichaelT... · Less obvious: Multiple connection pools, cross-tier deadlock Thread A holds

“In Spec” vs. “Out of Spec”

“In Spec” failuresTCP connection refusedHTTP response code 500Error message in XML response

Example: Request-Reply using XML over HTTP

Well-Behaved Errors Wicked Errors

“Out of Spec” failures

TCP connection accepted, but no data sent

TCP window full, never cleared

Server never ACKs TCP, causing very long delays as client retransmits

Connection made, server replies with SMTP hello string

Server sends HTML “link-farm” page

Server sends one byte per second

Server sends Weird Al catalog in MP3

Page 26: Failure Comes in Flavors 1: Stability Antipatternsgotocon.com/dl/jaoo-sydney-2009/slides/MichaelT... · Less obvious: Multiple connection pools, cross-tier deadlock Thread A holds

Integration Points

Be defensive. Assume every integration point can hang.Use timeouts everywhere.Time out on the whole communication, not just the connection.Beware vendor libraries.

Page 27: Failure Comes in Flavors 1: Stability Antipatternsgotocon.com/dl/jaoo-sydney-2009/slides/MichaelT... · Less obvious: Multiple connection pools, cross-tier deadlock Thread A holds

Remember This

Beware this necessary evil.

Prepare for the many forms of failure.

Know when to open up abstractions.

Failures propagate quickly.

Large systems fail faster than small ones.

Apply “Circuit Breaker”, “Use Timeouts”, “Use Decoupling Middleware”, and “Handshaking” to contain and isolate failures.

Use “Test Harness” to find problems in development.

Page 28: Failure Comes in Flavors 1: Stability Antipatternsgotocon.com/dl/jaoo-sydney-2009/slides/MichaelT... · Less obvious: Multiple connection pools, cross-tier deadlock Thread A holds

Chain Reaction

Example:Suppose S4 goes down

S1 - S3 go from 25% of totalto 33% of total

That’s 33% more load

Each one dies fasterFailure moves horizontallyacross tierCommon in search enginesand application servers

Failure in one component raises probability of failure in its peers

Page 29: Failure Comes in Flavors 1: Stability Antipatternsgotocon.com/dl/jaoo-sydney-2009/slides/MichaelT... · Less obvious: Multiple connection pools, cross-tier deadlock Thread A holds

Remember This

One server down jeopardizes the rest.Hunt for Resource Leaks.Defend with “Bulkheads”.

Page 30: Failure Comes in Flavors 1: Stability Antipatternsgotocon.com/dl/jaoo-sydney-2009/slides/MichaelT... · Less obvious: Multiple connection pools, cross-tier deadlock Thread A holds

Failure moves vertically across tiers

Common in enterprise services and SOAs

Failure in one system causes calling systems to be jeopardized

Example:System S goes down, causing calling system A to get slow or go down.

Cascading Failure

Page 31: Failure Comes in Flavors 1: Stability Antipatternsgotocon.com/dl/jaoo-sydney-2009/slides/MichaelT... · Less obvious: Multiple connection pools, cross-tier deadlock Thread A holds

Remember This

Prevent Cascading Failure to stop cracks from jumping the gap.Think “Damage Containment”Scrutinize resource pools, they get exhausted when the lower layer fails.Defend with “Use Timeouts” and “Circuit Breaker”.

Page 32: Failure Comes in Flavors 1: Stability Antipatternsgotocon.com/dl/jaoo-sydney-2009/slides/MichaelT... · Less obvious: Multiple connection pools, cross-tier deadlock Thread A holds

Users

Ways that users cause instabilitySheer traffic

Flash mobs

Click-happy

Malicious usersScreen-scrapers

Badly configured proxy servers

Can’t live with them...

Page 33: Failure Comes in Flavors 1: Stability Antipatternsgotocon.com/dl/jaoo-sydney-2009/slides/MichaelT... · Less obvious: Multiple connection pools, cross-tier deadlock Thread A holds

Two types of “bad” user

Front-page viewer

Creates useless sessions

Ties up memory for no reason

Application servers are all fragile to sessions

Users can always create session floods, deliberately or inadvertently, killing memory

DDoS attacks usually break app servers

Page 34: Failure Comes in Flavors 1: Stability Antipatternsgotocon.com/dl/jaoo-sydney-2009/slides/MichaelT... · Less obvious: Multiple connection pools, cross-tier deadlock Thread A holds

Two types of “bad” user

BuyersMost expensive type of user to service

Secure pages, requires more CPU cycles

More pages (10 – 12 per session)

External integrations: redit card processor, address verification, inventory management, shipping and fulfillment

High conversion rate is bad for the systems.Your sponsors may disagree.

Page 35: Failure Comes in Flavors 1: Stability Antipatternsgotocon.com/dl/jaoo-sydney-2009/slides/MichaelT... · Less obvious: Multiple connection pools, cross-tier deadlock Thread A holds

Handle Traffic Surges Gracefully

Turn off expensive features when the system is busy.

Divert or throttle users. Preserve a good experience for some when you can’t serve all.

Reduce the burden of serving each user. Be especially frugal with memory.

Hold IDs, not object graphs.

Hold query parameters, not result sets.

Differentiate people from bots. Don’t keep sessions for bots.

Page 36: Failure Comes in Flavors 1: Stability Antipatternsgotocon.com/dl/jaoo-sydney-2009/slides/MichaelT... · Less obvious: Multiple connection pools, cross-tier deadlock Thread A holds

Remember This

Minimize the memory you devote to each user.Malicious users are out there.But, so are weird random ones.Users come in clumps: one, a few, or way too many.

Page 37: Failure Comes in Flavors 1: Stability Antipatternsgotocon.com/dl/jaoo-sydney-2009/slides/MichaelT... · Less obvious: Multiple connection pools, cross-tier deadlock Thread A holds

Blocked Threads

Most common form of “crash”: all request threads blockedVery difficult to test for

Combinatoric permutation of code pathways.Safe code can be extended in unsafe ways.Errors are sensitive to timing and difficult to reproduceDev & QA servers never get hit with 10,000 concurrent requests.

Best bet: keep threads isolated. Use well-tested, high-level constructs for cross-thread communication.

Learn to use java.util.concurrent or System.Threading

Request handling threads are precious. Protect them.

Page 38: Failure Comes in Flavors 1: Stability Antipatternsgotocon.com/dl/jaoo-sydney-2009/slides/MichaelT... · Less obvious: Multiple connection pools, cross-tier deadlock Thread A holds

Pernicious and Cumulative

Hung request handlers reduce the server’s capacity.Eventually, a restart will be required.Each hung request handler indicates a frustrated user or waiting callerThe effect is non-linear and accelerating

Each remaining thread serves 1/N-1 extra requests

Page 39: Failure Comes in Flavors 1: Stability Antipatternsgotocon.com/dl/jaoo-sydney-2009/slides/MichaelT... · Less obvious: Multiple connection pools, cross-tier deadlock Thread A holds

Example: Blocking calls

Page 40: Failure Comes in Flavors 1: Stability Antipatternsgotocon.com/dl/jaoo-sydney-2009/slides/MichaelT... · Less obvious: Multiple connection pools, cross-tier deadlock Thread A holds

Example: Blocking calls

Example:In a request-processing method:

String key = (String)request.getParameter(PARAM_ITEM_SKU);Availability avl = globalObjectCache.get(key);

Page 41: Failure Comes in Flavors 1: Stability Antipatternsgotocon.com/dl/jaoo-sydney-2009/slides/MichaelT... · Less obvious: Multiple connection pools, cross-tier deadlock Thread A holds

Example: Blocking calls

Example:In a request-processing method:

String key = (String)request.getParameter(PARAM_ITEM_SKU);Availability avl = globalObjectCache.get(key);

In GlobalObjectCache.get(String id), a synchronized method:Object obj = items.get(id);if(obj == null) { obj = remoteSystem.lookup(id);}…

Page 42: Failure Comes in Flavors 1: Stability Antipatternsgotocon.com/dl/jaoo-sydney-2009/slides/MichaelT... · Less obvious: Multiple connection pools, cross-tier deadlock Thread A holds

Example: Blocking calls

Example:In a request-processing method:

String key = (String)request.getParameter(PARAM_ITEM_SKU);Availability avl = globalObjectCache.get(key);

In GlobalObjectCache.get(String id), a synchronized method:Object obj = items.get(id);if(obj == null) { obj = remoteSystem.lookup(id);}…

Remote system stopped responding due to “Unbalanced Capacities”

Page 43: Failure Comes in Flavors 1: Stability Antipatternsgotocon.com/dl/jaoo-sydney-2009/slides/MichaelT... · Less obvious: Multiple connection pools, cross-tier deadlock Thread A holds

Example: Blocking calls

Example:In a request-processing method:

String key = (String)request.getParameter(PARAM_ITEM_SKU);Availability avl = globalObjectCache.get(key);

In GlobalObjectCache.get(String id), a synchronized method:Object obj = items.get(id);if(obj == null) { obj = remoteSystem.lookup(id);}…

Remote system stopped responding due to “Unbalanced Capacities”Threads piled up like cars on a foggy freeway.

Page 44: Failure Comes in Flavors 1: Stability Antipatternsgotocon.com/dl/jaoo-sydney-2009/slides/MichaelT... · Less obvious: Multiple connection pools, cross-tier deadlock Thread A holds

Remember This

Scrutinize resource pools. Don’t wait forever.Use proven constructs.Beware the code you cannot see.Defend with “Use Timeouts”.

Page 45: Failure Comes in Flavors 1: Stability Antipatternsgotocon.com/dl/jaoo-sydney-2009/slides/MichaelT... · Less obvious: Multiple connection pools, cross-tier deadlock Thread A holds

Attacks of Self-Denial

Ever heard this one?A retailer offered a great promotion to a “select group of customers”.Approximately a bazillion times the expected customers show up for the offer.The retailer gets crushed, disappointing the avaricious and legitimate.

It’s a self-induced Slashdot effect.

Good marketing can kill your system at any time.

Page 46: Failure Comes in Flavors 1: Stability Antipatternsgotocon.com/dl/jaoo-sydney-2009/slides/MichaelT... · Less obvious: Multiple connection pools, cross-tier deadlock Thread A holds

Attacks of Self-Denial

Ever heard this one?A retailer offered a great promotion to a “select group of customers”.Approximately a bazillion times the expected customers show up for the offer.The retailer gets crushed, disappointing the avaricious and legitimate.

It’s a self-induced Slashdot effect.

Good marketing can kill your system at any time.

Victoria’s Secret: Online Fashion Show

BestBuy: XBox 360 Preorder

Amazon: XBox 360 Discount

Anything on FatWallet.com

Page 47: Failure Comes in Flavors 1: Stability Antipatternsgotocon.com/dl/jaoo-sydney-2009/slides/MichaelT... · Less obvious: Multiple connection pools, cross-tier deadlock Thread A holds

Defending the Ramparts

Avoid deep linksSet up static landing pagesOnly allow the user’s second click to reach application serversAllow throttling of incoming usersSet up lightweight versions of dynamic pages.Use your CDN to divert usersUse shared-nothing architecture

One email I saw went out with a deep link that

bypassed Akamai. Worse, it encoded a specific server and included a session ID.

Another time, an email went out with a promo code. It

could be used an unlimited number of times.

Once a vulnerability is found, it will be flooded

within seconds.

Page 48: Failure Comes in Flavors 1: Stability Antipatternsgotocon.com/dl/jaoo-sydney-2009/slides/MichaelT... · Less obvious: Multiple connection pools, cross-tier deadlock Thread A holds

Remember This

Keep lines of communication openSupport the marketers. If you don’t, they’ll invent their way around you, and might jeopardize the systems.

Protect shared resourcesExpect instantaneous distribution of exploits

Page 49: Failure Comes in Flavors 1: Stability Antipatternsgotocon.com/dl/jaoo-sydney-2009/slides/MichaelT... · Less obvious: Multiple connection pools, cross-tier deadlock Thread A holds

Scaling Effects

Ratios in dev and QA tend to be 1:1Web server to app server

Front end to back end

They differ wildly in production, so designs and architectures may not be appropriate

Understand which end of the lever you are sitting on.

Page 50: Failure Comes in Flavors 1: Stability Antipatternsgotocon.com/dl/jaoo-sydney-2009/slides/MichaelT... · Less obvious: Multiple connection pools, cross-tier deadlock Thread A holds

Example: Point to Point Cache Invalidation

DevelopmentDev Server

App 1

1 server1 local call

No TCP connections

QA

2 servers1 local call

1 TCP connection

Production

8 servers1 local call

7 TCP connection

QA Server 1

App 1

QA Server 2

App 2

App Server

App 1

App Server

App 2

App Server

App 3

App Server

App 4

App Server

App 5

App Server

App 6

App Server

App 7

App Server

App 8

Page 51: Failure Comes in Flavors 1: Stability Antipatternsgotocon.com/dl/jaoo-sydney-2009/slides/MichaelT... · Less obvious: Multiple connection pools, cross-tier deadlock Thread A holds

Example: Point to Point Cache Invalidation

DevelopmentDev Server

App 1

1 server1 local call

No TCP connections

QA

2 servers1 local call

1 TCP connection

Production

8 servers1 local call

7 TCP connection

QA Server 1

App 1

QA Server 2

App 2

App Server

App 1

App Server

App 2

App Server

App 3

App Server

App 4

App Server

App 5

App Server

App 6

App Server

App 7

App Server

App 8

Page 52: Failure Comes in Flavors 1: Stability Antipatternsgotocon.com/dl/jaoo-sydney-2009/slides/MichaelT... · Less obvious: Multiple connection pools, cross-tier deadlock Thread A holds

Example: Point to Point Cache Invalidation

DevelopmentDev Server

App 1

1 server1 local call

No TCP connections

QA

2 servers1 local call

1 TCP connection

Production

8 servers1 local call

7 TCP connection

QA Server 1

App 1

QA Server 2

App 2

App Server

App 1

App Server

App 2

App Server

App 3

App Server

App 4

App Server

App 5

App Server

App 6

App Server

App 7

App Server

App 8

Page 53: Failure Comes in Flavors 1: Stability Antipatternsgotocon.com/dl/jaoo-sydney-2009/slides/MichaelT... · Less obvious: Multiple connection pools, cross-tier deadlock Thread A holds

Example: Point to Point Cache Invalidation

DevelopmentDev Server

App 1

1 server1 local call

No TCP connections

QA

2 servers1 local call

1 TCP connection

Production

8 servers1 local call

7 TCP connection

QA Server 1

App 1

QA Server 2

App 2

App Server

App 1

App Server

App 2

App Server

App 3

App Server

App 4

App Server

App 5

App Server

App 6

App Server

App 7

App Server

App 8

Page 54: Failure Comes in Flavors 1: Stability Antipatternsgotocon.com/dl/jaoo-sydney-2009/slides/MichaelT... · Less obvious: Multiple connection pools, cross-tier deadlock Thread A holds

Example: Point to Point Cache Invalidation

DevelopmentDev Server

App 1

1 server1 local call

No TCP connections

QA

2 servers1 local call

1 TCP connection

Production

8 servers1 local call

7 TCP connection

QA Server 1

App 1

QA Server 2

App 2

App Server

App 1

App Server

App 2

App Server

App 3

App Server

App 4

App Server

App 5

App Server

App 6

App Server

App 7

App Server

App 8

Page 55: Failure Comes in Flavors 1: Stability Antipatternsgotocon.com/dl/jaoo-sydney-2009/slides/MichaelT... · Less obvious: Multiple connection pools, cross-tier deadlock Thread A holds

Example: Point to Point Cache Invalidation

DevelopmentDev Server

App 1

1 server1 local call

No TCP connections

QA

2 servers1 local call

1 TCP connection

Production

8 servers1 local call

7 TCP connection

QA Server 1

App 1

QA Server 2

App 2

App Server

App 1

App Server

App 2

App Server

App 3

App Server

App 4

App Server

App 5

App Server

App 6

App Server

App 7

App Server

App 8

Page 56: Failure Comes in Flavors 1: Stability Antipatternsgotocon.com/dl/jaoo-sydney-2009/slides/MichaelT... · Less obvious: Multiple connection pools, cross-tier deadlock Thread A holds

App 1 App 2

Common

Service

App 3 App 4 App 5 App 6 App 7 App 8

Example: Shared Resources

Shared resources commonly appear as lock managers, load managers, query distributors, cluster managers, and message

gateways. They’re all vulnerable to scaling effects.

Page 57: Failure Comes in Flavors 1: Stability Antipatternsgotocon.com/dl/jaoo-sydney-2009/slides/MichaelT... · Less obvious: Multiple connection pools, cross-tier deadlock Thread A holds

Remember This

Examine production versus QA environments to spot scaling effects.Watch out for point-to-point communications. It rarely belongs in production.Watch out for shared resources.

Page 58: Failure Comes in Flavors 1: Stability Antipatternsgotocon.com/dl/jaoo-sydney-2009/slides/MichaelT... · Less obvious: Multiple connection pools, cross-tier deadlock Thread A holds

Unbalanced Capacities

OnlineStore

SiteScopeNYC

Customers

SiteScopeSan Francisco

20 Hosts

75 Instances

3,000 Threads

OrderManagement

6 Hosts

6 Instances

450 Threads

Scheduling

1 Host

1 Instance

25 Threads

Traffic floods sometimes start inside the data center walls.

Page 59: Failure Comes in Flavors 1: Stability Antipatternsgotocon.com/dl/jaoo-sydney-2009/slides/MichaelT... · Less obvious: Multiple connection pools, cross-tier deadlock Thread A holds

Unbalanced Capacities

Unbalanced capacities is a type of scaling effect that occurs between systems in an enterprise.It happens because

All dev systems are one server

Almost all QA environments are two servers

Production environments may be 10:1 or 100:1

May be induced by changes in traffic or behavior patterns

Page 60: Failure Comes in Flavors 1: Stability Antipatternsgotocon.com/dl/jaoo-sydney-2009/slides/MichaelT... · Less obvious: Multiple connection pools, cross-tier deadlock Thread A holds

Remember This

Examine server and thread countsWatch out for changes in traffic patternsStress both sides of the interface in QASimulate back end failures during testing

Page 61: Failure Comes in Flavors 1: Stability Antipatternsgotocon.com/dl/jaoo-sydney-2009/slides/MichaelT... · Less obvious: Multiple connection pools, cross-tier deadlock Thread A holds

Slow Responses

What does your server do when it’s overloaded?

“Connection refused” is a fast failure, the caller’s thread is released right awayA slow response ties up the caller’s thread, makes the user wait

It uses capacity on caller and receiver

If the caller times out, then the work was wasted

Slow response is worse than no response

Page 62: Failure Comes in Flavors 1: Stability Antipatternsgotocon.com/dl/jaoo-sydney-2009/slides/MichaelT... · Less obvious: Multiple connection pools, cross-tier deadlock Thread A holds

Slow Responses

Look at the latency:TCP connection refused comes back in ~10 msTCP packets not acknowledged, sender retransmits for 1 – 10 min

Causes of slow responses:Too much load on systemTransient network saturationFirewall overloadedProtocol with retries built in (NFS, DNS)Chatty remote protocols

Page 63: Failure Comes in Flavors 1: Stability Antipatternsgotocon.com/dl/jaoo-sydney-2009/slides/MichaelT... · Less obvious: Multiple connection pools, cross-tier deadlock Thread A holds

Remember This

Slow responses trigger cascading failuresFor websites, slow responses invite more traffic as the users pound “reload”Don’t send a slow response; fail fastHunt for memory leaks or resource contention

Page 64: Failure Comes in Flavors 1: Stability Antipatternsgotocon.com/dl/jaoo-sydney-2009/slides/MichaelT... · Less obvious: Multiple connection pools, cross-tier deadlock Thread A holds

SLA InversionSurviving by luck alone.

Frammitz

99.99%

Corporate MTA

99.999%

SpamCannon's

DNS

98.5%

SpamCannon's

Applications

99%

Corporate DNS

99.9%

Inventory

99.9%

Message

Broker

99%

Partner 1's

Application

No SLA

Partner 1's

DNS

99%

Message

Queues

99.99%

Pricing and

Promotions

No SLA

What SLA can Frammitz really guarantee?Do your web servers have

to ask DNS to find the application server’s IP

address?

Absent other protections, the best SLA you can offer is the worst SLA

provided by your dependencies.

The dreaded SPOF is a special case of SLA

Inversion.

Page 65: Failure Comes in Flavors 1: Stability Antipatternsgotocon.com/dl/jaoo-sydney-2009/slides/MichaelT... · Less obvious: Multiple connection pools, cross-tier deadlock Thread A holds

Remember This

Don’t make empty promises. Be sure you can deliver the SLA you commit to.Examine every dependency. Verify that they can deliver on their promises.Decouple your SLAs from your dependencies’.Measure availability by feature, not by server.Be wary of “enterprise” services such as DNS, SMTP, and LDAP.

Page 66: Failure Comes in Flavors 1: Stability Antipatternsgotocon.com/dl/jaoo-sydney-2009/slides/MichaelT... · Less obvious: Multiple connection pools, cross-tier deadlock Thread A holds

Unbounded Result Sets

Development and testing is done with small data setsTest databases get reloaded frequentlyQueries that perform acceptably in development and test bonk badly with production data volume.

Bad access patterns can make them very slow

Too many results can use up all your server’s RAM or take too long to process

You never know when somebody else will mess with your data

Limited resources, unlimited data volume

Page 67: Failure Comes in Flavors 1: Stability Antipatternsgotocon.com/dl/jaoo-sydney-2009/slides/MichaelT... · Less obvious: Multiple connection pools, cross-tier deadlock Thread A holds

Unbounded Result Sets: Databases

SQL queries have no inherent limitsORM tools are bad about thisIt starts as a degenerating performance problem, but can tip the system over.For example:

Application server using database table to pass message between servers.

Normal volume 10 – 20 events at a time.

Time-based trigger on every user generated 10,000,000+ events at midnight.

Each server trying to receive all events at startup.

Out of memory errors at startup.

Page 68: Failure Comes in Flavors 1: Stability Antipatternsgotocon.com/dl/jaoo-sydney-2009/slides/MichaelT... · Less obvious: Multiple connection pools, cross-tier deadlock Thread A holds

Unbounded Result Sets: SOA

Often found in chatty remote protocols, together with the N+1 query problemCauses problems on the client and the server

On server: constructing results, marshalling XML

On client: parsing XML, iterating over results.

This is a breakdown in handshaking. The client knows how much it can handle, not the server.

Page 69: Failure Comes in Flavors 1: Stability Antipatternsgotocon.com/dl/jaoo-sydney-2009/slides/MichaelT... · Less obvious: Multiple connection pools, cross-tier deadlock Thread A holds

Remember This

Test with realistic data volumesScrubbed production data is the best.

Generated data also works.

Don’t rely on the data producers. Their behavior can change overnight.Put limits in your application-level protocols:

WS, RMI, DCOM, XML-RPC, etc.

Page 70: Failure Comes in Flavors 1: Stability Antipatternsgotocon.com/dl/jaoo-sydney-2009/slides/MichaelT... · Less obvious: Multiple connection pools, cross-tier deadlock Thread A holds

Integration Points

Cascading Failures

Users

Blocked Threads

Attacks ofSelf-Denial

Scaling Effects

UnbalancedCapacities

Slow Responses

SLA Inversion

UnboundedResult Sets Use Timeouts

Circuit Breaker

Bulkheads

Steady State

Fail Fast

Handshaking

Test Harness

DecouplingMiddleware

counters

prevents

counters

counters

reduces impact

mitigates

finds problems in

damage

mutual

aggravation

found

nearleads to

leads toleads to

results from

violating

counters

counters

counters can avoid

leads to

avoids

counters

counters

exacerbates

lead to

works with

counters

leads to

Chain Reactions