Erlang and Scalability - Percona Introduction Course Title @ Course Author 2007 Erlang and Scalability Jan Henry Nystrom henry@erlang- Percona Performance 2009

Embed Size (px)

Text of Erlang and Scalability - Percona Introduction Course Title @ Course Author 2007 Erlang and...

  • Course Introduction Course Title @ Course Author 2007

    Erlang andScalability

    Jan Henry Nystromhenry@erlang-consulting.com

    Percona Performance 2009

  • Percona Performance Conference 2009 -2009, Erlang Training and ConsultingErlang and Scalability 2

    Introduction Scalability Killers Design Decisions Language and Yours Thinking Scalable/Parallel Code for the correct case Rules of Thumb Scalability in the small: SMP

  • Percona Performance Conference 2009 -2009, Erlang Training and ConsultingErlang and Scalability 3

    Scalability Killers Synchronization Resource contention

  • Percona Performance Conference 2009 -2009, Erlang Training and ConsultingErlang and Scalability 3

    Scalability Killers

    Synchronization

  • Percona Performance Conference 2009 -2009, Erlang Training and ConsultingErlang and Scalability 4

    Design DecisionsNo sharing

    Processes Encapsulation No implicit synchronization

  • Percona Performance Conference 2009 -2009, Erlang Training and ConsultingErlang and Scalability 5

    Design DecisionsNo implicit synchronization

    Spawn always succeed Sending always succeed Random access message buffer Fire and forget unless you need the synchronization

  • Percona Performance Conference 2009 -2009, Erlang Training and ConsultingErlang and Scalability 6

    Design Decisions

  • Percona Performance Conference 2009 -2009, Erlang Training and ConsultingErlang and Scalability 6

    Design DecisionsConcurrency oriented programming

  • Percona Performance Conference 2009 -2009, Erlang Training and ConsultingErlang and Scalability 6

    Design DecisionsConcurrency oriented programming

    Concurrency support an integral part of the language

  • Percona Performance Conference 2009 -2009, Erlang Training and ConsultingErlang and Scalability 6

    Design DecisionsConcurrency oriented programming

    Concurrency support an integral part of the language Distribution support

  • Percona Performance Conference 2009 -2009, Erlang Training and ConsultingErlang and Scalability 6

    Design DecisionsConcurrency oriented programming

    Concurrency support an integral part of the language Distribution support Sets the focus firmly on the concurrent tasks

  • Percona Performance Conference 2009 -2009, Erlang Training and ConsultingErlang and Scalability 6

    Design DecisionsConcurrency oriented programming

    Concurrency support an integral part of the language Distribution support Sets the focus firmly on the concurrent tasks Code for the correct case

  • Percona Performance Conference 2009 -2009, Erlang Training and ConsultingErlang and Scalability 6

    Design DecisionsConcurrency oriented programming

    Concurrency support an integral part of the language Distribution support Sets the focus firmly on the concurrent tasks Code for the correct case Clear Code

  • Percona Performance Conference 2009 -2009, Erlang Training and ConsultingErlang and Scalability 6

    Design DecisionsConcurrency oriented programming

    Concurrency support an integral part of the language Distribution support Sets the focus firmly on the concurrent tasks Code for the correct case Clear Code

  • Percona Performance Conference 2009 -2009, Erlang Training and ConsultingErlang and Scalability 6

    Design DecisionsConcurrency oriented programming

    Concurrency support an integral part of the language Distribution support Sets the focus firmly on the concurrent tasks Code for the correct case Clear Code

    Clarity is King!

  • Percona Performance Conference 2009 -2009, Erlang Training and ConsultingErlang and Scalability 6

    Design DecisionsConcurrency oriented programming

    Concurrency support an integral part of the language Distribution support Sets the focus firmly on the concurrent tasks Code for the correct case Clear Code

    Clarity is King!

  • Percona Performance Conference 2009 -2009, Erlang Training and ConsultingErlang and Scalability 6

    Design DecisionsConcurrency oriented programming

    Concurrency support an integral part of the language Distribution support Sets the focus firmly on the concurrent tasks Code for the correct case Clear Code

    Clarity is King!

    I rather try to get clear code correct than correct code clear

  • Percona Performance Conference 2009 -2009, Erlang Training and ConsultingErlang and Scalability 7

    0

    Thinking Scalable/Parallel

  • Percona Performance Conference 2009 -2009, Erlang Training and ConsultingErlang and Scalability 7

    List length: Obviously Linear

    :

    But not when you have n processors?

    Thinking Scalable/Parallel

    4

  • Percona Performance Conference 2009 -2009, Erlang Training and ConsultingErlang and Scalability 8

    List length: O(logN) with sufficient processors

    Thinking Scalable/Parallel

  • Percona Performance Conference 2009 -2009, Erlang Training and ConsultingErlang and Scalability 8

    List length: O(logN) with sufficient processors

    Thinking Scalable/Parallel

    2

    4

    1 111

    2

  • Percona Performance Conference 2009 -2009, Erlang Training and ConsultingErlang and Scalability 9

    Thinking Scalable/ParallelIn the Erlang setting

    Do not introduce unneeded synchronization Remember processes are cheap Do not introduce unneeded synchronization A terminated process is all garbage Do not introduce unneeded synchronization

  • Percona Performance Conference 2009 -2009, Erlang Training and ConsultingErlang and Scalability 10

    Code for the Correct Case

  • Percona Performance Conference 2009 -2009, Erlang Training and ConsultingErlang and Scalability 10

    Code for the Correct Case

    set timer

    set timer

    set timer

    request

    request

    request

  • Percona Performance Conference 2009 -2009, Erlang Training and ConsultingErlang and Scalability 10

    Code for the Correct Case

    set timer

    set timer

    set timer

    release timercheck

    release timercheck

    release timercheck

    request

    request

    request

    answer

    answer

    answer

  • Percona Performance Conference 2009 -2009, Erlang Training and ConsultingErlang and Scalability 10

    Code for the Correct Case

    set timer

    set timer

    set timer

    release timercheck

    release timercheck

    release timercheck

    request

    request

    request

    answer

    answer

    answer

  • Percona Performance Conference 2009 -2009, Erlang Training and ConsultingErlang and Scalability 11

    Code for the Correct Case

  • Percona Performance Conference 2009 -2009, Erlang Training and ConsultingErlang and Scalability 11

    Code for the Correct Case

    set timer request

    request

    request

  • Percona Performance Conference 2009 -2009, Erlang Training and ConsultingErlang and Scalability 11

    Code for the Correct Case

    set timer request

    request

    request

    answer

  • Percona Performance Conference 2009 -2009, Erlang Training and ConsultingErlang and Scalability 12

    Rules of Thumb Rule 1 - All independent tasks should be processes Rule 2 - Do not invent concurrency that is not there!

    f()

    g()

    h()

  • Percona Performance Conference 2009 -2009, Erlang Training and ConsultingErlang and Scalability 12

    Rules of Thumb Rule 1 - All independent tasks should be processes Rule 2 - Do not invent concurrency that is not there!

    f()

    g()

    h()

  • Percona Performance Conference 2009 -2009, Erlang Training and ConsultingErlang and Scalability 12

    Rules of Thumb Rule 1 - All independent tasks should be processes Rule 2 - Do not invent concurrency that is not there!

    f()

    g()

    h()

    h(g(f()))

  • Percona Performance Conference 2009 -2009, Erlang Training and ConsultingErlang and Scalability 12

    Rules of Thumb Rule 1 - All independent tasks should be processes Rule 2 - Do not invent concurrency that is not there!

    f()

    g()

    h()

    h(g(f()))h(g(f()))

    h(g(f()))h(g(f()))

  • Percona Performance Conference 2009 -2009, Erlang Training and ConsultingErlang and Scalability 13

    Scalability in the small: SMPErlang SMP Credo

    SMP should be transparent to the programmer inmuch the same way as Erlang Distribution

    You shouldnt have to think about it ...but sometimes you must

    Use SMP mainly for stuff that youd make concurrent anyway Erlang uses concurrency as a structuring principle

    Model for the natural concurrency in your problem

  • Percona Performance Conference 2009 -2009, Erlang Training and ConsultingErlang and Scalability 14

    Scalability in the small: SMP Erlang on multicore

    SMP prototype 97, First OTP release May 06.

    Mid -06 benchmark mimicking call handling (axdmark) on the (experimental) SMP emulator. Observed speedup/core: 0.95

    First Ericsson product (TGC) released on SMP Erlang in Q207.

    Big bang benchmark on Sunfire T2000

    Simultaneous processes16 schedulers

    1 scheduler

  • Percona Performance Conference 2009 -2009, Erlang Training and ConsultingErlang and Scalability 15

    Scalability in the small: SMPCase Study: Telephony Gateway Controller

    Mediates between legacy telephony and multimedia networks.

    Hugely complex state machines + massive concurrency. Developed in Erlang. Multicore version shipped to customer Q207. Porting from 1-core PPC to 2-core Intel took