Erlang and the Cloud

C20f7f4a8aa455aa6e0c2a0092883cd0?s=47 Roberto Aloi
November 17, 2012

Erlang and the Cloud

In the era of multicore and cloud computing, the only limit for your application is the sky. But for your application to be able to exploit all of this potential, it needs to be designed in a manner that scales. In this talk we discuss the suitability of the Erlang programming language for scenarios such as cloud computing and multicore, explaining how the concurrency model of Erlang maps to multicore architectures and what principles should be kept in mind when designing a scalable application.

C20f7f4a8aa455aa6e0c2a0092883cd0?s=128

Roberto Aloi

November 17, 2012
Tweet

Transcript

  1. Erlang and the Cloud Roberto Aloi Erlang Solutions Ltd.

  2. WHERE TO START @ r o b e r t

    o a l o i
  3. None
  4. IT’S ALL about SCALABILITY

  5. WHAT IS SCALABILITY?

  6. None
  7. Definitions of Scalability “Property of a system that can accommodate

    changes in transaction volume without major changes to the system [...] A scalable system can be downsized as easily as it can grow” Barron's Marketing Dictionary “The ability of a system, network, or process, to handle a growing amount of work in a capable manner” André B. Bondi, 2000
  8. WHY SCALABILITY IS SO IMPORTANT?

  9. “The ability for a business or technology to accept increased

    volume without impacting the contribution margin” Wikipedia Alternative definition of Scalability Contribution Margin = Marginal Profit per Unit Sale
  10. SCALABILITY = REVENUE

  11. IT’S ALL about SCALABILITY

  12. IT’S ALL about R E V E N U E

  13. TWO KINDS OF SCALABILITY

  14. HORIZONTAL (SCALE OUT) VERTICAL (SCALE UP)

  15. CLOUD COMPUTING MULTI-CORE

  16. HAVING INFINITE RESOURCES IS NOT ENOUGH. YOUR APPLICATION HAS TO

    BE DESIGNED TO SCALE.
  17. SCALING PRINCIPLE #1: CONCURRENCY

  18. - TONS OF PROCESSES - EXECUTING SIMULTANEOUSLY - REACTING TO

    EVENTS - PERFORMING SMALL COMPUTATIONS
  19. Processes need to be easy to create and destroy. Context

    switch needs to be a cheap operation.
  20. SCALING PRINCIPLE #2: HANDLING FAILURES

  21. - FAIL IS UNAVOIDABLE - FAIL FAST - AVOID PROPAGATION

    OF FAILURES - RECOVER FROM FAILURE
  22. SCALING PRINCIPLE #3: ISOLATION

  23. - ISOLATE PROCESSES - SHARE NOTHING - NO RACE CONDITIONS

    - AVOID LOCKS
  24. SCALING PRINCIPLE #4: IMMUTABILITY

  25. - HAVE IMMUTABLE DATA - USE PURE FUNCTIONS - NO

    SIDE EFFECTS - REFERENTIAL TRANSPARENCY
  26. SCALING PRINCIPLE #5: THINKING ASYNCHRONOUSLY

  27. - ASYNCHRONOUS COMMUNICATION - MESSAGE PASSING - NO GUARANTEES

  28. SCALING PRINCIPLE #6: DISTRIBUTION

  29. - DECOUPLE COMPONENTS - DECENTRALIZE DATA - AVOID BOTTLENECKS -

    PREFER AVAILABILITY TO CONSISTENCY
  30. IMMUTABILITY SCALABILITY 101 LARGE SCALE CONCURRENCY ASYNCHRONOUS COMMUNICATION RELIABILITY PREDICTABILITY

    DECOUPLING PROCESS ISOLATION FAULT ISOLATION NO SHARED MEMORY SYNCHRONIZATION RACE CONDITIONS EVENTUAL CONSISTENCY CAP THEOREM SMP MULTICORE CLOUD COMPUTING DECENTRALIZATION OF DATA MAINTENANCE NO DOWN TIME
  31. SCALABILITY IS A COMPLICATED MATTER.

  32. TO THE RESCUE

  33. • OPEN SOURCE • CONCURRENCY-ORIENTED • LIGHTWEIGHT PROCESSES (10.000 PER

    CORE) • ASYNCHRONOUS MESSAGE PASSING • SHARE-NOTHING MODEL • PROCESS LINKING / MONITORING • SUPERVISION TREES AND RECOVERY STRATEGIES • TRANSPARENT DISTRIBUTION MODEL • SOFT-REAL TIME • LET-IT-FAIL PHILOSOPHY • HOT-CODE UPGRADES WHAT IS ERLANG DOES IT SOUND FAMILIAR?
  34. SCALING IN PRACTICE #1: CONCURRENCY

  35. CREATE (SPAWN) A PROCESS spawn(math, fact, [5]) Pid1 Processes

  36. CREATE (SPAWN) A PROCESS spawn(math, fact, [5]) math:fact(5) Pid2 Pid1

    Processes
  37. SCALING IN PRACTICE #2: HANDLING FAILURES

  38. CREATE A BI-DIRECTIONAL LINK BETWEEN PROCESSES Links PidB PidA link(PidB)

  39. CREATE A BI-DIRECTIONAL LINK BETWEEN PROCESSES Links PidB PidA link(PidB)

  40. Let It Crash convert(Day) -> case Day of monday ->

    1; tuesday -> 2; wednesday -> 3; thursday -> 4; friday -> 5; saturday -> 6; sunday -> 7; Other -> {error, unknown_day} end.
  41. Let It Crash convert(Day) -> case Day of monday ->

    1; tuesday -> 2; wednesday -> 3; thursday -> 4; friday -> 5; saturday -> 6; sunday -> 7; end.
  42. Supervisors PidA PidC PidB

  43. Supervisors PidA PidC PidB

  44. Supervisors PidA PidC PidB Supervisor

  45. Supervisors PidA PidC PidB Supervisor Workers

  46. SCALING IN PRACTICE #3: ISOLATION

  47. Corrupted Pid1 Pid2 Sane Pid1 Pid2 Corrupted

  48. SCALING PRINCIPLE #4: IMMUTABILITY

  49. X = 1 X = X + 1

  50. X = 1 X = X + 1

  51. SCALING PRINCIPLE #5: THINKING ASYNCHRONOUSLY

  52. SEND A MESSAGE TO A PROCESS Pid2 Pid1 Pid2 !

    {self(), msg} Message Passing
  53. SEND A MESSAGE TO A PROCESS Pid2 Pid1 Pid2 !

    {self(), msg} {Pid1, msg} Message Passing
  54. SCALING IN PRACTICE #6: DISTRIBUTION

  55. None
  56. ERLANG IS A VERY GOOD STARTING POINT BUT THERE ARE

    SOME LIMITATIONS
  57. TO THE RESCUE

  58. RELEASE STATEMENT OF AIMS “To scale the radical concurrency-oriented programming

    paradigm to build reliable general-purpose software, such as server- based systems, on massively parallel machines (10^5 cores).”
  59. WP4 Scalable Infrastructure WP3 SD Erlang Language WP2 Virtual Machine

    WP5 Tools WP6 Case Studies LIMITATIONS ARE PRESENT AT THREE LEVELS
  60. • PUSH THE RESPONSIBILITY FOR SCALABILITY FROM THE PROGRAMMER TO

    THE VM • ANALYZE PERFORMANCE AND SCALABILITY • IDENTIFY BOTTLENECKS AND PRIORITIZE CHANGES AND EXTENSIONS • TACKLE WELL-KNOWN SCALABILITY ISSUES • ETS TABLES (SHARED GLOBAL DATA STRUCTURE) • MESSAGE PASSING, COPYING AND FREQUENTLY COMMUNICATING PROCESSES VM LANGUAGE INFRASTRUCTURE
  61. VM LANGUAGE INFRASTRUCTURE • TWO MAJOR ISSUES • FULLY CONNECTED

    CLUSTERS • EXPLICIT PROCESS PLACEMENT • SCALABLE DISTRIBUTED (SD) ERLANG • NODES GROUPING • NON-TRANSITIVE CONNECTIONS • IMPLICIT PROCESS PLACEMENT • PART OF THE STANDARD ERLANG/OTP PACKAGE • NEW CONCEPTS INTRODUCED • LOCALITY, AFFINITY AND DISTANCE
  62. • MIDDLEWARE LAYER • SET OF ERLANG APPLICATIONS • CREATE

    AND MANAGE CLUSTERS OF (HETEROGENEOUS) ERLANG NODES • API TO MONITOR AND CONTROL ERLANG DISTRIBUTED SYSTEMS • EXISTING TRACING/LOGGING/DEBUGGING TOOLS PLUGGABLE • BROKER LAYER BETWEEN USERS AND CLOUD PROVIDERS • AUTO-SCALING VM LANGUAGE INFRASTRUCTURE CCL /sɪˈsɪlɪ/ ... AND MUCH MORE
  63. BENCHERL

  64. PERCEPT 2

  65. LESSON OF THE DAY

  66. IF I WRITE MY APPLICATION IN ERLANG, IT WILL SCALE

  67. IF I WRITE MY APPLICATION IN ERLANG, IT WILL SCALE

    NOT.
  68. IF I WRITE MY APPLICATION IN ERLANG, IT WILL SCALE

    NOT. Well, not automagically!
  69. SHIPPED WITH BLACK MAGIC INSIDE

  70. WHERE TO START WITH ERLANG

  71. erlang.org github.com/erlang/otp erlang-solutions.com www.learnyousomeerlang.org elearning.erlang-solutions.com Erlang Programming Erlang and OTP

    in Action Official Home Page Sources Binary Packages, News, Events Best Online Tutorial Commercial e-learning solution Best book about Erlang Best book about OTP
  72. QUESTIONS? @robertoaloi https://speakerdeck.com/robertoaloi