Click here to load reader

Sane Sharding with Akka Cluster

  • View
    334

  • Download
    1

Embed Size (px)

Text of Sane Sharding with Akka Cluster

  • Sane Sharding with Akka Cluster

    Micha Pachta

    @miciek

    Live-coding & performance analysis

  • Whats inside?

    Creating a web service using actor model ...analysing its performance ...making it scalable

  • Akka Tutorial

    actor ~= thread actorRef.tell actorRef.ask actors create children actors have mailbox ActorRef

    Sender 1 Sender 2

    ask tell

    enqueue

    MailboxActor

    dequeue

  • Scala Tutorial

    case class pattern matching

    case class Junction(id: Int)

    public class Junction { private final int id;

    public Junction(int id) { this.id = id; }

    public int getId() { return id; }

    // hashCode // equals // copy}

    msg match { case Junction(id) => // this will execute

    // when msg is Junctioncase SomeOtherType =>

    }

  • First example: Sorter

    scan -> HTTP -> push right or not

    See also: http://i.imgur.com/mctb4HC.gifv

    http://i.imgur.com/mctb4HC.gifv

  • Sorter Web Service

    http://localhost:8080/junctions//decisionForContainer/

    returns JSON

    { direction: left | right | straight | ... }

    Assumptions:

    5-10 ms to make a decision business logic already defined - focus on performance

    http://localhost:8080/junctions/2/decisionForContainer/1http://localhost:8080/junctions/2/decisionForContainer/1http://localhost:8080/junctions/2/decisionForContainer/1http://localhost:8080/junctions/2/decisionForContainer/1http://localhost:8080/junctions/2/decisionForContainer/1http://localhost:8080/junctions/2/decisionForContainer/1

  • Lets code it!

  • Step 1: Just REST...

    RestInterface

    HTTP Requests HTTP Responses

    One Actor = One Thread Blocking inside receive method Low throughput...

  • Throughput testing

    /junctions/1/decisionForContainer/1 /junctions/2/decisionForContainer/4/junctions/3/decisionForContainer/5/junctions/4/decisionForContainer/2/junctions/5/decisionForContainer/7

    2000 requests2000 requests2000 requests2000 requests2000 requests

    in parallel

    cat URLs.txt | parallel -j 5 'ab -ql -n 2000 -c 1 -k {}'

    GNU Parallel ApacheBench

  • Lets test it!

  • Step 1: Just REST...

    RestInterface

    HTTP Requests HTTP Responses

    % cat URLs.txt | parallel -j 5 'ab -ql -n 2000 -c 1 -k {}' | grep 'Requests per second'

    Requests per second: 34.78 [#/sec] (mean)

    Requests per second: 34.22 [#/sec] (mean)

    Requests per second: 33.77 [#/sec] (mean)

    Requests per second: 33.82 [#/sec] (mean)

    Requests per second: 33.98 [#/sec] (mean)

  • Lets improve performance!

  • Step 1.5: Logic in another actor

    RestInterface

    HTTP Requests HTTP Responses

    SortingDecider

  • Step 2: One actor per junction

    RestInterface

    HTTP Requests HTTP Responses

    DecidersGuardian

    SortingDeciderSortingDecider

    SortingDecider

    =1 ... =5

  • Step 2: One actor per junction

    % cat URLs.txt | parallel -j 5 'ab -ql -n 2000 -c 1 -k {}' | grep 'Requests per second'

    Requests per second: 67.36 [#/sec] (mean)

    Requests per second: 69.03 [#/sec] (mean)

    Requests per second: 67.75 [#/sec] (mean)

    Requests per second: 66.88 [#/sec] (mean)

    Requests per second: 66.28 [#/sec] (mean)

  • Now what?

    non-blocking concurrent scaling up works scaling out?

    RestInterface

    HTTP Requests HTTP Responses

    DecidersGuardian

    SortingDeciderSortingDecider

    SortingDecider

    =1 ... =5

  • Manual scaling out

    RestInterface

    HTTP Requests HTTP Responses

    DecidersGuardian

    SortingDeciderSortingDecider

    SortingDecider

    =1 ... =3

    RestInterface

    HTTP Requests HTTP Responses

    DecidersGuardian

    SortingDeciderSortingDecider

    SortingDecider

    =4 ... =6

  • Enter Sharding

    RestInterface

    HTTP Requests HTTP Responses

    ShardRegion

    SortingDeciderSortingDecider

    SortingDecider

    =h(m) ... =h(m)

    RestInterface

    HTTP Requests HTTP Responses

    ShardRegion

    SortingDeciderSortingDecider

    SortingDecider

    =h(m) ... =h(m)

    ...

  • Lets shard it!

  • Step 3: Sharded web service

    % cat URLs.txt | parallel -j 5 'ab -ql -n 2000 -c 1 -k {}' | grep 'Requests per second'

    Requests per second: 106.80 [#/sec] (mean)

    Requests per second: 108.15 [#/sec] (mean)

    Requests per second: 100.60 [#/sec] (mean)

    Requests per second: 99.92 [#/sec] (mean)

    Requests per second: 100.07 [#/sec] (mean)

  • Sharding

    automatic distribution no need to know who is where no need to know how many nodes are there rebalancing migration

  • Thank you!Any questions?

    Micha Pachta

    @miciek

Search related