+ All Categories
Home > Documents > Why Events Are A Bad Idea (for high-concurrency servers)€¦ · Why Events Are A Bad Idea (for...

Why Events Are A Bad Idea (for high-concurrency servers)€¦ · Why Events Are A Bad Idea (for...

Date post: 18-Oct-2020
Category:
Upload: others
View: 3 times
Download: 0 times
Share this document with a friend
28
Why Events Are A Bad Idea (for high-concurrency servers) Rob von Behren, Jeremy Condit and Eric Brewer Presenter: Harry Xingzhi Pan Jan 24, 2011 Friday, January 21, 2011
Transcript
Page 1: Why Events Are A Bad Idea (for high-concurrency servers)€¦ · Why Events Are A Bad Idea (for high-concurrency servers) Rob von Behren, Jeremy Condit and Eric Brewer Presenter:

Why Events Are A Bad Idea(for high-concurrency servers)

Rob von Behren, Jeremy Condit and Eric Brewer

Presenter: Harry Xingzhi PanJan 24, 2011

Friday, January 21, 2011

Page 2: Why Events Are A Bad Idea (for high-concurrency servers)€¦ · Why Events Are A Bad Idea (for high-concurrency servers) Rob von Behren, Jeremy Condit and Eric Brewer Presenter:

Goal

• Threads have all the power of events

• Actually even better for high-concurrency servers

• Simpler and more natural programming style

Friday, January 21, 2011

Page 3: Why Events Are A Bad Idea (for high-concurrency servers)€¦ · Why Events Are A Bad Idea (for high-concurrency servers) Rob von Behren, Jeremy Condit and Eric Brewer Presenter:

Ways to the Goal• Threads vs. Events

• Threads are better for high-concurrency servers

• Compiler support

• Current implementations not good enough

• Validation

• Related workFriday, January 21, 2011

Page 4: Why Events Are A Bad Idea (for high-concurrency servers)€¦ · Why Events Are A Bad Idea (for high-concurrency servers) Rob von Behren, Jeremy Condit and Eric Brewer Presenter:

Duality(Lauer and Needham)

• Events

• handlers

• accepted events

• Send/WaitReply

• SendReply

• wait for msgs

• Threads

• monitors

• exported funcs

• call or fork/join

• return

• wait for c.var

Friday, January 21, 2011

Page 5: Why Events Are A Bad Idea (for high-concurrency servers)€¦ · Why Events Are A Bad Idea (for high-concurrency servers) Rob von Behren, Jeremy Condit and Eric Brewer Presenter:

Duality cont.(Lauer and Needham)

• Mapping

• Equivalent performance

• Threads shouldn’t be worse

• Depends on target application

• And threads are better for high-concurrency servers

Friday, January 21, 2011

Page 6: Why Events Are A Bad Idea (for high-concurrency servers)€¦ · Why Events Are A Bad Idea (for high-concurrency servers) Rob von Behren, Jeremy Condit and Eric Brewer Presenter:

“Problems” with ThreadsPerformance

• Bad performance

• Poor implementation

• O(n) in number of threads

• high context switch overhead

• kernel crossing

• Modified GNU Pth performs well

• removed most O(n) operationsFriday, January 21, 2011

Page 7: Why Events Are A Bad Idea (for high-concurrency servers)€¦ · Why Events Are A Bad Idea (for high-concurrency servers) Rob von Behren, Jeremy Condit and Eric Brewer Presenter:

“Problems” with ThreadsPerformance cont.

Friday, January 21, 2011

Page 8: Why Events Are A Bad Idea (for high-concurrency servers)€¦ · Why Events Are A Bad Idea (for high-concurrency servers) Rob von Behren, Jeremy Condit and Eric Brewer Presenter:

“Problems” with ThreadsControl Flow

• Restrictive Control Flow

• linear

• Complicated control flow pattern

• rare

• difficult to use well

• call/return, parallel calls, pipelines

Friday, January 21, 2011

Page 9: Why Events Are A Bad Idea (for high-concurrency servers)€¦ · Why Events Are A Bad Idea (for high-concurrency servers) Rob von Behren, Jeremy Condit and Eric Brewer Presenter:

“Problems” with ThreadsSynchronization

• Heavy weight synchronization

• Free synchronization for event systems

• Really due to cooperative multitasking, not events

• free for uniprocessors only

• like disabling interrupts

• high-concurrency servers have multi processors

Friday, January 21, 2011

Page 10: Why Events Are A Bad Idea (for high-concurrency servers)€¦ · Why Events Are A Bad Idea (for high-concurrency servers) Rob von Behren, Jeremy Condit and Eric Brewer Presenter:

“Problems” with ThreadsState Management

• ineffective to manage live state

• trade-off between risking stack overflow and wasting space

• event systems unwind stack

• Dynamic stack growth (later)

• Event systems require programmers to manage live state by hand

• Thread systems have automatic state management

Friday, January 21, 2011

Page 11: Why Events Are A Bad Idea (for high-concurrency servers)€¦ · Why Events Are A Bad Idea (for high-concurrency servers) Rob von Behren, Jeremy Condit and Eric Brewer Presenter:

“Problems” with ThreadsScheduling

• can’t optimize scheduling decisions

• runtime system too generic

• event systems can schedule at application level

• The same tricks can be applied to thread systems according to duality

Friday, January 21, 2011

Page 12: Why Events Are A Bad Idea (for high-concurrency servers)€¦ · Why Events Are A Bad Idea (for high-concurrency servers) Rob von Behren, Jeremy Condit and Eric Brewer Presenter:

Ways to the Goal• Threads vs. Events

• Threads are better for high-concurrency servers

• Compiler support

• Current implementations not good enough

• Validation

• Related workFriday, January 21, 2011

Page 13: Why Events Are A Bad Idea (for high-concurrency servers)€¦ · Why Events Are A Bad Idea (for high-concurrency servers) Rob von Behren, Jeremy Condit and Eric Brewer Presenter:

Threads are better

• Two observations about servers

• concurrent requests, largely independent

• sequential handling of each request

Friday, January 21, 2011

Page 14: Why Events Are A Bad Idea (for high-concurrency servers)€¦ · Why Events Are A Bad Idea (for high-concurrency servers) Rob von Behren, Jeremy Condit and Eric Brewer Presenter:

Threads are betterControl Flow

• Events obfuscate app control flow

• Send/AwaitReply vs call/return

• manually save/restore live state

• unexpected msg arrivals cause subtle race conditions & logic errors

Friday, January 21, 2011

Page 15: Why Events Are A Bad Idea (for high-concurrency servers)€¦ · Why Events Are A Bad Idea (for high-concurrency servers) Rob von Behren, Jeremy Condit and Eric Brewer Presenter:

Threads are betterControl Flow cont.

• Thread systems group calls with returns

• easier to understand cause/effect

• Run-time call stack encapsulates live state

Friday, January 21, 2011

Page 16: Why Events Are A Bad Idea (for high-concurrency servers)€¦ · Why Events Are A Bad Idea (for high-concurrency servers) Rob von Behren, Jeremy Condit and Eric Brewer Presenter:

Threads are betterException Handling & State Lifetime

• simpler cleaning up task state

• on the contrary task state in event systems is typically in heap

• GC is inappropriate for high performance systems

Friday, January 21, 2011

Page 17: Why Events Are A Bad Idea (for high-concurrency servers)€¦ · Why Events Are A Bad Idea (for high-concurrency servers) Rob von Behren, Jeremy Condit and Eric Brewer Presenter:

Threads are betterExisting systems

• threads in existing event-driven systems

• most complex parts: such as recovery

• also applications that don’t need high concurrency: threads are simpler

Friday, January 21, 2011

Page 18: Why Events Are A Bad Idea (for high-concurrency servers)€¦ · Why Events Are A Bad Idea (for high-concurrency servers) Rob von Behren, Jeremy Condit and Eric Brewer Presenter:

Threads are betterHow about fixing events?

• duplicate threads

• E.g., continuations around blocking calls in Adya et al. [1]

Friday, January 21, 2011

Page 19: Why Events Are A Bad Idea (for high-concurrency servers)€¦ · Why Events Are A Bad Idea (for high-concurrency servers) Rob von Behren, Jeremy Condit and Eric Brewer Presenter:

Ways to the Goal• Threads vs. Events

• Threads are better for high-concurrency servers

• Compiler support

• Current implementations not good enough

• Validation

• Related workFriday, January 21, 2011

Page 20: Why Events Are A Bad Idea (for high-concurrency servers)€¦ · Why Events Are A Bad Idea (for high-concurrency servers) Rob von Behren, Jeremy Condit and Eric Brewer Presenter:

Compiler SupportDynamic Stack Growth

• adjust stack size at runtime

• analyze upper bound of stack size when calling

• determine which call sites may require stack growth

Friday, January 21, 2011

Page 21: Why Events Are A Bad Idea (for high-concurrency servers)€¦ · Why Events Are A Bad Idea (for high-concurrency servers) Rob von Behren, Jeremy Condit and Eric Brewer Presenter:

Compiler SupportLive State Management

• purge unnecessary state from stack

• temp vars before calling subroutines

• tail calls

• warn programmer of large amounts of state across a blocking call

Friday, January 21, 2011

Page 22: Why Events Are A Bad Idea (for high-concurrency servers)€¦ · Why Events Are A Bad Idea (for high-concurrency servers) Rob von Behren, Jeremy Condit and Eric Brewer Presenter:

Compiler SupportSynchronization

• compile-time analysis

• warn programmers

• tractable whole-program analyses

• nesC/TinyOS

• call graph

• calls within an atomic section cannot yield or block

Friday, January 21, 2011

Page 23: Why Events Are A Bad Idea (for high-concurrency servers)€¦ · Why Events Are A Bad Idea (for high-concurrency servers) Rob von Behren, Jeremy Condit and Eric Brewer Presenter:

Ways to the Goal• Threads vs. Events

• Threads are better for high-concurrency servers

• Compiler support

• Current implementations not good enough

• Validation

• Related workFriday, January 21, 2011

Page 24: Why Events Are A Bad Idea (for high-concurrency servers)€¦ · Why Events Are A Bad Idea (for high-concurrency servers) Rob von Behren, Jeremy Condit and Eric Brewer Presenter:

Validation

• simple user-level cooperative threading package

• minimalist context switching

• internal translates blocking I/O to asynchronous requests

Friday, January 21, 2011

Page 25: Why Events Are A Bad Idea (for high-concurrency servers)€¦ · Why Events Are A Bad Idea (for high-concurrency servers) Rob von Behren, Jeremy Condit and Eric Brewer Presenter:

Validation cont.• Knot vs Haboob (SEDA)

Friday, January 21, 2011

Page 26: Why Events Are A Bad Idea (for high-concurrency servers)€¦ · Why Events Are A Bad Idea (for high-concurrency servers) Rob von Behren, Jeremy Condit and Eric Brewer Presenter:

Ways to the Goal• Threads vs. Events

• Threads are better for high-concurrency servers

• Compiler support

• Current implementations not good enough

• Validation

• Related work

Friday, January 21, 2011

Page 27: Why Events Are A Bad Idea (for high-concurrency servers)€¦ · Why Events Are A Bad Idea (for high-concurrency servers) Rob von Behren, Jeremy Condit and Eric Brewer Presenter:

Related work

• Adya et al. [1]

• Ousterhout [11]

• Welsh, Culler and Brewer [17]

• Lauer and Needham [10]

Friday, January 21, 2011

Page 28: Why Events Are A Bad Idea (for high-concurrency servers)€¦ · Why Events Are A Bad Idea (for high-concurrency servers) Rob von Behren, Jeremy Condit and Eric Brewer Presenter:

Questions&

Thank you!

Friday, January 21, 2011


Recommended