Upgrade to Pro — share decks privately, control downloads, hide ads and more …

From 1000 to 10k users per server - Concurrency rediscovered with Akka.

From 1000 to 10k users per server - Concurrency rediscovered with Akka.

Concurrency is hard, asynchronous programming is hard. This is why we still design systems using thread-safe mentality. The consequences are harsh. We are blocking threads. Our services spend most of the time waiting for IO. We are wasting resources and generating unnecessary costs.

Not anymore! With introduction of Akka we get a very powerful toolkit which makes asynchronous programming much easier.

I am going to give you an introduction to Akka by showing how we've managed to improve our services at Zeebox. We increased the capacity from 1000 users per server to 10k users by using Akka and embracing the reactive programming.

The source code for this presentation is available at github:
https://github.com/piotrga/asyncer

Piotr Gabryanczyk

February 28, 2014
Tweet

More Decks by Piotr Gabryanczyk

Other Decks in Technology

Transcript

  1. Common operations CPU instruction 1 nanosecond reading 1MB from RAM

    250 000 nanoseconds TCP roundtrip US <-> EU 150 000 000 nanosecods Peter Norvig - norvig.org
  2. 1 nano => 1 second Erik Meijer - coursera.org CPU

    instruction 1 second reading 1MB from RAM 3 days TCP roundtrip US <-> EU 5 years
  3. map

  4. flatMap Future flatMap( ) Future Future Future{ fetchUser() } flatMap

    ( u => Future{ getAccountBalance(u.account) }) : Future[Double]
  5. flatMap Future flatMap( ) Future Future Future{ fetchUser() } flatMap

    ( u => Future{ getAccountBalance(u.account) }) : Future[Double]
  6. flatMap Future flatMap( ) Future Future Future{ fetchUser() } flatMap

    ( u => Future{ getAccountBalance(u.account) }) : Future[Double]
  7. Zip

  8. M! E! R! G! E Thread Thread Thread 500! threads

    500! requests Twitter Thread Thread Thread 500! threads Thread Thread Thread 500! threads Thread Thread Thread 500! threads Thread Thread Thread 500! threads fetchFriends fetchFriends added removed
  9. M! E! R! G! E Thread Thread Thread 500! threads

    500! requests Twitter Thread Thread Thread 500! threads Thread Thread Thread 500! threads Thread Thread Thread 500! threads Thread Thread Thread 500! threads fetchFriends fetchFriends added removed
  10. M! E! R! G! E Thread Thread Thread 500! threads

    500! requests Twitter Thread Thread Thread 500! threads Thread Thread Thread 500! threads Thread Thread Thread 500! threads Thread Thread Thread 500! threads fetchFriends fetchFriends added removed
  11. M! E! R! G! E Thread Thread Thread 500! threads

    500! requests Twitter Thread Thread Thread 500! threads Thread Thread Thread 500! threads Thread Thread Thread 500! threads Thread Thread Thread 500! threads fetchFriends fetchFriends added removed
  12. M! E! R! G! E Thread Thread Thread 500! threads

    500! requests Twitter Thread Thread Thread 500! threads Thread Thread Thread 500! threads Thread Thread Thread 500! threads Thread Thread Thread 500! threads fetchFriends fetchFriends added removed 500 req/3 sec =>166 req/sec
  13. Sync IO Serialize request 3 hours De-serialize request 3 hours

    Wait for IO 55 years time ! human terms
  14. Async IO Serialize request 3 hours De-serialize request 3 hours

    Handle 100 000! other requests! time ! human terms request async write and read response received!
  15. Fully Async! 6 hours Total: 14 days ~> 1.2 ms

    => 830 req/sec ! or 1660 req/sec on 2 cores was 170y, then 85y 166 req/seq 3x6 hours = 18h 51x6 hours ! ~= 13 days
  16. Actors are NOT threads! Phone Connection Actor Speaker Actor Microphone

    Actor Radio Actor Keyboard Actor Dispatcher Thread Thread Thread
  17. Connection Actor Async DB Connection Actor Connection Actor Facade! Actor

    Router Load! Balancer Supervisor Monitor! Actor
  18. Connection Actor Async DB Connection Actor Connection Actor Facade! Actor

    Router Load! Balancer Supervisor Monitor! Actor
  19. Connection Actor Async DB Connection Actor Connection Actor Facade! Actor

    Router Load! Balancer Supervisor Monitor! Actor
  20. Connection Actor Async DB Connection Actor Connection Actor Facade! Actor

    Router Load! Balancer Supervisor Monitor! Actor
  21. Connection Actor Async DB Connection Actor Connection Actor Facade! Actor

    Router Load! Balancer Supervisor Monitor! Actor
  22. Connection Actor Async DB Connection Actor Connection Actor Facade! Actor

    Router Load! Balancer Supervisor Monitor! Actor
  23. Connection Actor Async DB Connection Actor Connection Actor Facade! Actor

    Router Load! Balancer Supervisor Monitor! Actor
  24. Connection Actor Async DB Connection Actor Connection Actor Facade! Actor

    Router Load! Balancer Supervisor Monitor! Actor
  25. Connection Actor Async DB Connection Actor Facade! Actor Router Load!

    Balancer Supervisor Monitor! Actor Connection Actor
  26. Connection Actor Async DB Connection Actor Facade! Actor Router Load!

    Balancer Supervisor Monitor! Actor Connection Actor
  27. Monitor Actor Inactive Active(k) Inactive for long time Facade! Actor

    ConnectionUp ConnectionDown ConnectionUp InactiveForLong ResourceDown ResourceUp ConnectionUp Connection Actor Connection Actor Connection Actor ConnectionUp ConnectionDown ConnectionUp ConnectionDown