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

Serverless Is Ruby Future

Serverless Is Ruby Future

#rubyrussia 2019

Ee8543e8f5554aaeabb6d140fa07b919?s=128

Nikolay Sverchkov

September 28, 2019
Tweet

Transcript

  1. SERVERLESS IS UBY FUTURE NIKOLAY SVERCHKOV @ssnickolay

  2. None
  3. evilmartians.com New

  4. ME Community Speech TWO OPTIONS

  5. ME Community Speech VOTE 26 % 74 %

  6. SERVERLESS AXIOMS Event-Driven Architecture

  7. SERVERLESS AXIOMS Event-Driven Architecture Stateless

  8. SERVERLESS AXIOMS Event-Driven Architecture Stateless ♾ Infinite Scaling

  9. SERVERLESS AXIOMS Event-Driven Architecture Stateless ♾ Infinite Scaling Pay when

    the code is running
  10. SERVERLESS AXIOMS Event-Driven Architecture Stateless ♾ Infinite Scaling Pay when

    the code is running
  11. SERVERLESS UNDER THE MICROSCOPE

  12. LOG $ serverless invoke -f index -l

  13. LOG $ serverless invoke -f index -l START RequestId: <UUID>

    Version: $LATEST END RequestId: <UUID> REPORT RequestId: <UUID> Duration: 1.48 ms Billed Duration: 100 ms Memory Size: 1024 MB Max Memory Used: 31 MB
  14. LOG $ serverless invoke -f index -l START RequestId: <UUID>

    Version: $LATEST END RequestId: <UUID> REPORT RequestId: <UUID> Duration: 1.48 ms Billed Duration: 100 ms Memory Size: 1024 MB Max Memory Used: 31 MB
  15. SERVERLESS AXIOMS Event-Driven Architecture Stateless ♾ Infinite Scaling Pay when

    the code is running
  16. LOG $ serverless invoke -f index -l START RequestId: <UUID>

    Version: $LATEST END RequestId: <UUID> REPORT RequestId: <UUID> Duration: 1.48 ms Billed Duration: 100 ms Memory Size: 1024 MB Max Memory Used: 31 MB
  17. LOG $ serverless invoke -f index -l START RequestId: <UUID>

    Version: $LATEST END RequestId: <UUID> REPORT RequestId: <UUID> Duration: 1.48 ms Billed Duration: 100 ms Memory Size: 1024 MB Max Memory Used: 31 MB
  18. WHAT ABOUT CPU?

  19. AWS Lambda allocates CPU power proportional to the memory… (с)

    Amazon Docs
  20. AWS Lambda allocates CPU power proportional to the memory… For

    example, if you allocate 256 MB memory, your Lambda function will receive twice the CPU share than if you allocated only 128 MB. (с) Amazon Docs
  21. (CPU, CST) ""<=> MEMORY http://bit.ly/2UZ7xDL Completely Fair Scheduler (CFS)

  22. https://aws.amazon.com/lambda/pricing/ 6$ "=> 28.8M/128mb!

  23. COST SPEED ⏫ https://amzn.to/2Ix2t2O

  24. COST ""<=> LANGUAGE

  25. $ wrk -t10 -c400 -d20s -R40000 $ curl http://endpoint.url/[ruby/go] "=>

    {“success”: true} VS CHALLENGE:
  26. 0 250 500 750 1000 0 1 2 4 5

    MAX AVG AVG ~80ms 31712 requests in 20.01s Requests/sec: 1584.83 BATTLE (128 MB)
  27. 0 250 500 750 1000 0 1 2 4 5

    0 250 500 750 1000 0 1 2 4 5 MAX AVG AVG ~1.8ms AVG ~80ms 31712 requests in 20.01s Requests/sec: 1584.83 50347 requests in 20.00s Requests/sec: 2517.30 BATTLE (128 MB)
  28. 0 250 500 750 1000 0 1 2 4 5

    0 250 500 750 1000 0 1 2 4 5 MAX AVG AVG ~1.8ms AVG ~80ms 31712 requests in 20.01s Requests/sec: 1584.83 50347 requests in 20.00s Requests/sec: 2517.30 W IN BATTLE (128 MB)
  29. 0 250 500 750 1000 0 1 2 4 5

    0 250 500 750 1000 0 1 2 4 5 MAX AVG AVG ~1.8ms AVG ~80ms 31712 requests in 20.01s Requests/sec: 1584.83 50347 requests in 20.00s Requests/sec: 2517.30 W IN * BATTLE (128 MB)
  30. BATTLE (128 MB) AVG ~1.8ms AVG ~80ms “Billed Duration: 100

    ms” (c) Lambda Docs
  31. WHEN YOU REWRITE EVERYTHING ON GO EXPECTATION REALITY

  32. None
  33. FREE! Free Enterprise

  34. FREE! Free Enterprise LYING http://bit.ly/2lCt2dA

  35. PREDICTABLY

  36. PREDICTABLY

  37. PREDICTABLY

  38. http://serverlesscalc.com/ $2400 450M!! $918 1GB

  39. BATTLE (128 MB) AVG ~1.8ms AVG ~80ms ❓❓❓❓❓❓❓❓❓ ❓❓❓❓❓❓❓❓❓❓ ❓

    ❓ ❓ ❓ ❓
  40. http://rubyonjets.com/

  41. RAILS ON SERVERLESS Tung Nguyen

  42. PURE RUBY LAMBDA # handler.rb require 'json' def heartbeat(event:, context:)

    { statusCode: 200, body: JSON.generate(success: true) } end
  43. BATTLE (128 MB) AVG ~39ms AVG ~80ms

  44. COST ""<=> DEPENDENCIES

  45. MINIMIZE THE COMPLEXITY OF YOUR DEPENDENCIES

  46. MINIMIZE THE COMPLEXITY OF YOUR DEPENDENCIES

  47. MINIMIZE THE COMPLEXITY OF YOUR DEPENDENCIES

  48. NO RAILS GOOD!

  49. CHEAPLY NICE NO RAILS GOOD!

  50. CHEAPLY NICE EVENTS AWESOME NO RAILS GOOD!

  51. CHEAPLY NICE EVENTS AWESOME NO RAILS GOOD! SCALING AMAZING

  52. TALK ABOUT THE PROBLEMS TELL THE TRUTH Sponsored by @stacey_om

  53. IS INFINITE SCALING ALWAYS GOOD?

  54. # before $ puma -t 8:32 -w 1 # after

    $ puma -t 8:32 -w 2 HOW RUBY DEV SCALES APP
  55. 500

  56. SERVERLESS AXIOMS Event-Driven Architecture Stateless ♾ Infinite Scaling Pay when

    the code is running
  57. When you write your Lambda function code, do not assume

    that AWS Lambda automatically reuses the execution context for subsequent function invocations…. (c) AWS Docs AWS LAMBDA EXECUTION CONTEXT
  58. EXECUTION CONTEXT # 1M symbols work = proc { 123_456_789

    "** 123_456 } def heartbeat(event:, context:) { statusCode: 200, body: … } end
  59. EXECUTION CONTEXT # 1M symbols work = proc { 123_456_789

    !** 123_456 } def heartbeat(event:, context:) value = work.() # not cached { statusCode: 200, body: JSON.generate(value: value) } end
  60. EXECUTION CONTEXT # 1M symbols work = proc { 123_456_789

    !** 123_456 } value = work.() # cached def heartbeat(event:, context:) { statusCode: 200, body: JSON.generate(value: value) } end
  61. CONNECTION POOL pool = DB"::ConnectionPool.new() def heartbeat(event:, context:) connection =

    pool.get() # use connection connection.release() end
  62. https://stackoverflow.com/q/54110697

  63. SOLUTIONS* CLASSIC ($)

  64. SOLUTIONS* CLASSIC ($) MODERN ($$) Serverless

  65. SCALE ⬇ DOWSCALE ⬇ SCALE ⬇ …

  66. BURSTY TRAFFIC BURSTY LOAD BURSTY ???

  67. EXAMPLE ML

  68. EXAMPLE: ETL

  69. EXAMPLE: ETL

  70. EXAMPLE: BLOG

  71. GOTO 0; SERVERLESS IS RUBY FUTURE

  72. GOTO 0; SERVERLESS IS RUBY FUTURE

  73. DREAMS ABOUT SERVERLESS

  74. DREAMS ABOUT SERVERLESS Incredible Processing Power

  75. SERVERLESS Massive User Job

  76. SERVERLESS Backends Massive User Job DIFFERENT BACKENDS

  77. SERVERLESS Backends Massive User Job 10_000.times do Thread.new(job) end

  78. SERVERLESS Backends Burst-Parallel Job

  79. SERVERLESS Burst-Parallel Job Video Encoding: VP8

  80. Burst-Parallel Job Video Encoding: Classic encode([, , …, ]) "->

    keyframe + interframe(2:n)
  81. Burst-Parallel Job Video Encoding: Existing encode([, , …, ]) "->

    keyframe + interframe(2:n) 1MB +25kb * n
  82. Burst-Parallel Job Video Encoding: Existing encode([, , …, ]) "->

    keyframe + interframe(2:n) decode(keyframe + interframe[2:n]) "-> [, , …, ] 1MB +25kb * n
  83. Burst-Parallel Job Video Encoding: Existing encode(i[1:10]) "-> keyframe1 + interframe(2:10)

    encode(i[11:20]) "-> keyframe2 + interframe(12:20) encode(i[21:30]) "-> keyframe3 + interframe(22:30) 1MB * N
  84. VIDEO ENCODING: ALFALA http://bit.ly/2lZFrbO

  85. Burst-Parallel Job preprocessor(compiler (assembler(linker (archiver(indexer (strip(source_file)…) Software Compilation: 7 Steps

  86. Burst-Parallel Job Software Compilation

  87. Burst-Parallel Job Software Compilation Video Encoding

  88. DIRECTED ACYCLIC GRAPH BRO NOT A BRO

  89. DIRECTED ACYCLIC GRAPH Problem: Different Nodes g f h m

    k l p r
  90. DAG "=> FUNCTIONS preprocessor(compiler (assembler(linker (archiver(indexer (strip(source_file)…)

  91. f(g(h(p(…)…)

  92. f(g(i)) !== λ(f, λ(g, i)) THE NEW ABSTRACTION: λ

  93. f(g(i)) !== λ(f, λ(g, i)) f = proc { |a|

    a + 1 } g = proc { |a| a + 2 } f.call(g.call(0)) # "=> 3 THE NEW ABSTRACTION: λ
  94. f(g(i)) !== λ(f, λ(g, i)) f = proc { |a|

    a + 1 } g = proc { |a| a + 2 } f.call(g.call(0)) # !=> 3 λ = proc { |f, i| f.(i) } λ.call(f, λ.call(g, 0)) # "=> 3 THE NEW ABSTRACTION: λ
  95. f(g(h(p(…)…) !== λ(f, λ(g, λ(h, λ(p(…)…)

  96. f(g(h(p(…)…) !== λ(f, λ(g, λ(h, λ(p(…)…) λ(ƒ,arg) !=> arg WHERE

  97. λ(ƒ,arg) !=> arg

  98. λ(ƒ,arg) !=> arg λ(ƒ,arg) "=> Θ,arg

  99. λ(ƒ,arg) !=> arg λ(ƒ,arg) !=> Θ,arg λ(T) "=> T

  100. DIRECTED ACYCLIC GRAPH T2 T1 T3 T5 T4 T6 T7

    T8 λ(T) "=> T, T{i} "<- T
  101. SERVERLESS Backends Burst-Parallel Job

  102. SERVERLESS Backends Burst-Parallel Job λ(T) "=> T

  103. SERVERLESS Backends Burst-Parallel Job λ(T) "=> T λ

  104. SERVERLESS Backends Burst-Parallel Job λ(T) "=> T λ IR T

  105. SERVERLESS Backends Burst-Parallel Job IR λ(T) "=> T T λ

    STATIC
  106. SERVERLESS Backends Burst-Parallel Job λ IR T Frontends T generator

    λ(T) "=> T
  107. SERVERLESS Backends Burst-Parallel Job λ IR T Frontends T generator

    λ(T) "=> T
  108. Burst-Parallel Job IR Frontends Coordinator HTTP λ

  109. SERVERLESS Backend Burst-Parallel Job IR Frontends Coordinator STATELESS HTTP

  110. Burst-Parallel Job IR Frontends Coordinator S3 HTTP λ

  111. THE FUTURE IS HERE!

  112. gg Backends Burst-Parallel Job gg IR Frontends gg Coordinator C++

    HTTP ProtoBuf S3 Stanford Systems and Networking Research
  113. Fib(4) fib(4) fib(3) fib(2) fib(2) fib(1) fib(1) fib(0) fib(1) fib(0)

    + + + +
  114. Fib(4) fib(4) fib(3) fib(2) fib(2) fib(1) fib(1) fib(0) fib(1) fib(0)

    + + + + Hash#fib1 Hash#fib2
  115. Нихуя не понял Но очень интересно! чего

  116. gg FRAMEWORK https://stanford.io/2mtmiiH

  117. DEMO

  118. DEMO http://bit.ly/2m0G3Oo https://asciinema.org/a/270154

  119. RESULTS gg real user sys 1m17.670s 1m49.040s 0m7.820s real user

    sys 0m43.354s 0m3.830s 0m5.490s real user sys 0m29.376s 0m0.950s 0m1.400s
  120. RESULTS gg real user sys 1m17.670s 1m49.040s 0m7.820s real user

    sys 0m43.354s 0m3.830s 0m5.490s real user sys 0m29.376s 0m0.950s 0m1.400s
  121. RESULTS gg Total: 1m56s Total: 0m38s ~X3 faster

  122. COMPARISON OF COLD-CACHE BUILD TIMES https://cs.stanford.edu/~matei/papers/2019/usenix_atc_gg.pdf

  123. DARK MAGIC!

  124. https://github.com/StanfordSNR/gg

  125. GOTO 0; SERVERLESS IS RUBY FUTURE

  126. “As a computing substrate, we suspect cloud functions are in

    a similar position to Graphics Processing Units in the 2000s. At the time, GPUs were designed solely for 3D graphics, but the community gradually recognized that they had become programmable enough to execute some parallel algorithms unrelated to graphics.” (c)
  127. GOTO 0; SERVERLESS IS RUBY FUTURE

  128. SORBET?

  129. IT saṃsāra Java Erlang C C++ "=> Scala "=> Elixir

    "=> Go "=> Rust
  130. RUBY SELF-IDENTIFICATION

  131. RUBY IS Fast Coding

  132. RUBY IS Startups (Rails) Fast Coding

  133. RUBY IS Startups (Rails) GIL Sensitive Fast Coding

  134. RUBY IS Startups (Rails) オブジェクト指向スクリプト⾔言語 Ruby GIL Sensitive Fast Coding

  135. RUBY IS Startups (Rails) GIL Sensitive The Object-oriented Scripting Language

    Ruby Fast Coding
  136. RUBY IS Startups (Rails) GIL Sensitive The Object-oriented Scripting Language

    Ruby Fast Coding
  137. RUBY IS Startups (Rails) GIL Sensitive The Object-oriented Scripting Language

    Ruby Fast Coding
  138. RUBY IS Startups (Rails) GIL Sensitive The Object-oriented Scripting Language

    Ruby Fast Coding
  139. RUBY IS Startups (Rails) GIL Sensitive The Object-oriented Scripting Language

    Ruby Fast Coding
  140. 60 SECNDS OF SUMMARY

  141. @ssnickolay Nikolay Sverchkov @ssnickolay THANK YOU! @evilmartians http://evl.ms/blog http://evl.ms/telegram