Slide 1

Slide 1 text

SERVERLESS IS UBY FUTURE NIKOLAY SVERCHKOV @ssnickolay

Slide 2

Slide 2 text

No content

Slide 3

Slide 3 text

evilmartians.com New

Slide 4

Slide 4 text

ME Community Speech TWO OPTIONS

Slide 5

Slide 5 text

ME Community Speech VOTE 26 % 74 %

Slide 6

Slide 6 text

SERVERLESS AXIOMS Event-Driven Architecture

Slide 7

Slide 7 text

SERVERLESS AXIOMS Event-Driven Architecture Stateless

Slide 8

Slide 8 text

SERVERLESS AXIOMS Event-Driven Architecture Stateless ♾ Infinite Scaling

Slide 9

Slide 9 text

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

Slide 10

Slide 10 text

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

Slide 11

Slide 11 text

SERVERLESS UNDER THE MICROSCOPE

Slide 12

Slide 12 text

LOG $ serverless invoke -f index -l

Slide 13

Slide 13 text

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

Slide 14

Slide 14 text

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

Slide 15

Slide 15 text

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

Slide 16

Slide 16 text

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

Slide 17

Slide 17 text

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

Slide 18

Slide 18 text

WHAT ABOUT CPU?

Slide 19

Slide 19 text

AWS Lambda allocates CPU power proportional to the memory… (с) Amazon Docs

Slide 20

Slide 20 text

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

Slide 21

Slide 21 text

(CPU, CST) ""<=> MEMORY http://bit.ly/2UZ7xDL Completely Fair Scheduler (CFS)

Slide 22

Slide 22 text

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

Slide 23

Slide 23 text

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

Slide 24

Slide 24 text

COST ""<=> LANGUAGE

Slide 25

Slide 25 text

$ wrk -t10 -c400 -d20s -R40000 $ curl http://endpoint.url/[ruby/go] "=> {“success”: true} VS CHALLENGE:

Slide 26

Slide 26 text

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)

Slide 27

Slide 27 text

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)

Slide 28

Slide 28 text

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)

Slide 29

Slide 29 text

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)

Slide 30

Slide 30 text

BATTLE (128 MB) AVG ~1.8ms AVG ~80ms “Billed Duration: 100 ms” (c) Lambda Docs

Slide 31

Slide 31 text

WHEN YOU REWRITE EVERYTHING ON GO EXPECTATION REALITY

Slide 32

Slide 32 text

No content

Slide 33

Slide 33 text

FREE! Free Enterprise

Slide 34

Slide 34 text

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

Slide 35

Slide 35 text

PREDICTABLY

Slide 36

Slide 36 text

PREDICTABLY

Slide 37

Slide 37 text

PREDICTABLY

Slide 38

Slide 38 text

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

Slide 39

Slide 39 text

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

Slide 40

Slide 40 text

http://rubyonjets.com/

Slide 41

Slide 41 text

RAILS ON SERVERLESS Tung Nguyen

Slide 42

Slide 42 text

PURE RUBY LAMBDA # handler.rb require 'json' def heartbeat(event:, context:) { statusCode: 200, body: JSON.generate(success: true) } end

Slide 43

Slide 43 text

BATTLE (128 MB) AVG ~39ms AVG ~80ms

Slide 44

Slide 44 text

COST ""<=> DEPENDENCIES

Slide 45

Slide 45 text

MINIMIZE THE COMPLEXITY OF YOUR DEPENDENCIES

Slide 46

Slide 46 text

MINIMIZE THE COMPLEXITY OF YOUR DEPENDENCIES

Slide 47

Slide 47 text

MINIMIZE THE COMPLEXITY OF YOUR DEPENDENCIES

Slide 48

Slide 48 text

NO RAILS GOOD!

Slide 49

Slide 49 text

CHEAPLY NICE NO RAILS GOOD!

Slide 50

Slide 50 text

CHEAPLY NICE EVENTS AWESOME NO RAILS GOOD!

Slide 51

Slide 51 text

CHEAPLY NICE EVENTS AWESOME NO RAILS GOOD! SCALING AMAZING

Slide 52

Slide 52 text

TALK ABOUT THE PROBLEMS TELL THE TRUTH Sponsored by @stacey_om

Slide 53

Slide 53 text

IS INFINITE SCALING ALWAYS GOOD?

Slide 54

Slide 54 text

# before $ puma -t 8:32 -w 1 # after $ puma -t 8:32 -w 2 HOW RUBY DEV SCALES APP

Slide 55

Slide 55 text

500

Slide 56

Slide 56 text

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

Slide 57

Slide 57 text

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

Slide 58

Slide 58 text

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

Slide 59

Slide 59 text

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

Slide 60

Slide 60 text

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

Slide 61

Slide 61 text

CONNECTION POOL pool = DB"::ConnectionPool.new() def heartbeat(event:, context:) connection = pool.get() # use connection connection.release() end

Slide 62

Slide 62 text

https://stackoverflow.com/q/54110697

Slide 63

Slide 63 text

SOLUTIONS* CLASSIC ($)

Slide 64

Slide 64 text

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

Slide 65

Slide 65 text

SCALE ⬇ DOWSCALE ⬇ SCALE ⬇ …

Slide 66

Slide 66 text

BURSTY TRAFFIC BURSTY LOAD BURSTY ???

Slide 67

Slide 67 text

EXAMPLE ML

Slide 68

Slide 68 text

EXAMPLE: ETL

Slide 69

Slide 69 text

EXAMPLE: ETL

Slide 70

Slide 70 text

EXAMPLE: BLOG

Slide 71

Slide 71 text

GOTO 0; SERVERLESS IS RUBY FUTURE

Slide 72

Slide 72 text

GOTO 0; SERVERLESS IS RUBY FUTURE

Slide 73

Slide 73 text

DREAMS ABOUT SERVERLESS

Slide 74

Slide 74 text

DREAMS ABOUT SERVERLESS Incredible Processing Power

Slide 75

Slide 75 text

SERVERLESS Massive User Job

Slide 76

Slide 76 text

SERVERLESS Backends Massive User Job DIFFERENT BACKENDS

Slide 77

Slide 77 text

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

Slide 78

Slide 78 text

SERVERLESS Backends Burst-Parallel Job

Slide 79

Slide 79 text

SERVERLESS Burst-Parallel Job Video Encoding: VP8

Slide 80

Slide 80 text

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

Slide 81

Slide 81 text

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

Slide 82

Slide 82 text

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

Slide 83

Slide 83 text

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

Slide 84

Slide 84 text

VIDEO ENCODING: ALFALA http://bit.ly/2lZFrbO

Slide 85

Slide 85 text

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

Slide 86

Slide 86 text

Burst-Parallel Job Software Compilation

Slide 87

Slide 87 text

Burst-Parallel Job Software Compilation Video Encoding

Slide 88

Slide 88 text

DIRECTED ACYCLIC GRAPH BRO NOT A BRO

Slide 89

Slide 89 text

DIRECTED ACYCLIC GRAPH Problem: Different Nodes g f h m k l p r

Slide 90

Slide 90 text

DAG "=> FUNCTIONS preprocessor(compiler (assembler(linker (archiver(indexer (strip(source_file)…)

Slide 91

Slide 91 text

f(g(h(p(…)…)

Slide 92

Slide 92 text

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

Slide 93

Slide 93 text

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: λ

Slide 94

Slide 94 text

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: λ

Slide 95

Slide 95 text

f(g(h(p(…)…) !== λ(f, λ(g, λ(h, λ(p(…)…)

Slide 96

Slide 96 text

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

Slide 97

Slide 97 text

λ(ƒ,arg) !=> arg

Slide 98

Slide 98 text

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

Slide 99

Slide 99 text

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

Slide 100

Slide 100 text

DIRECTED ACYCLIC GRAPH T2 T1 T3 T5 T4 T6 T7 T8 λ(T) "=> T, T{i} "<- T

Slide 101

Slide 101 text

SERVERLESS Backends Burst-Parallel Job

Slide 102

Slide 102 text

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

Slide 103

Slide 103 text

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

Slide 104

Slide 104 text

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

Slide 105

Slide 105 text

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

Slide 106

Slide 106 text

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

Slide 107

Slide 107 text

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

Slide 108

Slide 108 text

Burst-Parallel Job IR Frontends Coordinator HTTP λ

Slide 109

Slide 109 text

SERVERLESS Backend Burst-Parallel Job IR Frontends Coordinator STATELESS HTTP

Slide 110

Slide 110 text

Burst-Parallel Job IR Frontends Coordinator S3 HTTP λ

Slide 111

Slide 111 text

THE FUTURE IS HERE!

Slide 112

Slide 112 text

gg Backends Burst-Parallel Job gg IR Frontends gg Coordinator C++ HTTP ProtoBuf S3 Stanford Systems and Networking Research

Slide 113

Slide 113 text

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

Slide 114

Slide 114 text

Fib(4) fib(4) fib(3) fib(2) fib(2) fib(1) fib(1) fib(0) fib(1) fib(0) + + + + Hash#fib1 Hash#fib2

Slide 115

Slide 115 text

Нихуя не понял Но очень интересно! чего

Slide 116

Slide 116 text

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

Slide 117

Slide 117 text

DEMO

Slide 118

Slide 118 text

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

Slide 119

Slide 119 text

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

Slide 120

Slide 120 text

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

Slide 121

Slide 121 text

RESULTS gg Total: 1m56s Total: 0m38s ~X3 faster

Slide 122

Slide 122 text

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

Slide 123

Slide 123 text

DARK MAGIC!

Slide 124

Slide 124 text

https://github.com/StanfordSNR/gg

Slide 125

Slide 125 text

GOTO 0; SERVERLESS IS RUBY FUTURE

Slide 126

Slide 126 text

“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)

Slide 127

Slide 127 text

GOTO 0; SERVERLESS IS RUBY FUTURE

Slide 128

Slide 128 text

SORBET?

Slide 129

Slide 129 text

IT saṃsāra Java Erlang C C++ "=> Scala "=> Elixir "=> Go "=> Rust

Slide 130

Slide 130 text

RUBY SELF-IDENTIFICATION

Slide 131

Slide 131 text

RUBY IS Fast Coding

Slide 132

Slide 132 text

RUBY IS Startups (Rails) Fast Coding

Slide 133

Slide 133 text

RUBY IS Startups (Rails) GIL Sensitive Fast Coding

Slide 134

Slide 134 text

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

Slide 135

Slide 135 text

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

Slide 136

Slide 136 text

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

Slide 137

Slide 137 text

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

Slide 138

Slide 138 text

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

Slide 139

Slide 139 text

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

Slide 140

Slide 140 text

60 SECNDS OF SUMMARY

Slide 141

Slide 141 text

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