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

Serverless Is Ruby Future

Serverless Is Ruby Future

#rubyrussia 2019

Nikolay Sverchkov

September 28, 2019
Tweet

More Decks by Nikolay Sverchkov

Other Decks in Programming

Transcript

  1. 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
  2. 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
  3. 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
  4. 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
  5. 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
  6. 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)
  7. 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)
  8. 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)
  9. 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)
  10. PURE RUBY LAMBDA # handler.rb require 'json' def heartbeat(event:, context:)

    { statusCode: 200, body: JSON.generate(success: true) } end
  11. # before $ puma -t 8:32 -w 1 # after

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

  13. 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
  14. EXECUTION CONTEXT # 1M symbols work = proc { 123_456_789

    "** 123_456 } def heartbeat(event:, context:) { statusCode: 200, body: … } end
  15. 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
  16. 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
  17. Burst-Parallel Job Video Encoding: Existing encode([, , …, ]) "->

    keyframe + interframe(2:n) decode(keyframe + interframe[2:n]) "-> [, , …, ] 1MB +25kb * n
  18. 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
  19. 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: λ
  20. 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: λ
  21. DIRECTED ACYCLIC GRAPH T2 T1 T3 T5 T4 T6 T7

    T8 λ(T) "=> T, T{i} "<- T
  22. gg Backends Burst-Parallel Job gg IR Frontends gg Coordinator C++

    HTTP ProtoBuf S3 Stanford Systems and Networking Research
  23. 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
  24. 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
  25. “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)