Slide 1

Slide 1 text

event-driven programming for the masses High performance for fun and profit.

Slide 2

Slide 2 text

Agenda - Hello! - 101 of event-driven programming - Examples from scratch - Putting into practice - Conclusions 2

Slide 3

Slide 3 text

Hello! 3

Slide 4

Slide 4 text

$ whoami 4

Slide 5

Slide 5 text

$ whoami Christian Lück 5

Slide 6

Slide 6 text

$ whoami Christian Lück 6

Slide 7

Slide 7 text

$ whoami Christian Lueck 7

Slide 8

Slide 8 text

$ whoami Christian Lueck 8

Slide 9

Slide 9 text

$ whoami Christian Lueck @clue 9

Slide 10

Slide 10 text

$ whoami Christian Lueck @another_clue 10

Slide 11

Slide 11 text

$ whoami Christian Lueck @another_clue passionate about pushing the limits 11

Slide 12

Slide 12 text

$ whoami Christian Lueck @another_clue passionate about pushing the limits freelance software engineer 12

Slide 13

Slide 13 text

Who are you? 13 now that you know me…

Slide 14

Slide 14 text

Who are you? 14 now that you know me… - programmers / developers? - architects / engineers?

Slide 15

Slide 15 text

What is event-driven programming? 15

Slide 16

Slide 16 text

What is an event? 16

Slide 17

Slide 17 text

event 17

Slide 18

Slide 18 text

event 18 past action recognized by environment

Slide 19

Slide 19 text

event 19 past action recognized by environment triggered reaction, listening

Slide 20

Slide 20 text

event 20 past action recognized by environment triggered reaction, listening hardware or software

Slide 21

Slide 21 text

event-driven 21

Slide 22

Slide 22 text

event-driven program flow driven by events 22

Slide 23

Slide 23 text

event-driven program flow driven by events react to events (handler) 23

Slide 24

Slide 24 text

event-driven program flow driven by events react to events (handler) event-loop (reactor) 24

Slide 25

Slide 25 text

event-driven programming 25

Slide 26

Slide 26 text

event-driven program? 26

Slide 27

Slide 27 text

event-driven web applications 27

Slide 28

Slide 28 text

frontend 28 backend

Slide 29

Slide 29 text

frontend 29

Slide 30

Slide 30 text

frontend mouse clicks, keyboard input (UI) 30

Slide 31

Slide 31 text

frontend mouse clicks, keyboard input (UI) backend communication 31

Slide 32

Slide 32 text

frontend mouse clicks, keyboard input (UI) backend communication browser APIs 32

Slide 33

Slide 33 text

backend 33

Slide 34

Slide 34 text

backend network protocols (HTTP) 34

Slide 35

Slide 35 text

backend network protocols (HTTP) database APIs 35

Slide 36

Slide 36 text

backend network protocols (HTTP) database APIs filesystem 36

Slide 37

Slide 37 text

backend is all about I/O 37

Slide 38

Slide 38 text

is your backend all about I/O? 38

Slide 39

Slide 39 text

Show me some code! 39

Slide 40

Slide 40 text

Show me some code! Programming language? 40

Slide 41

Slide 41 text

Node.js 41

Slide 42

Slide 42 text

Node.js 42 good fit, huge ecosystem

Slide 43

Slide 43 text

Node.js 43 good fit, huge ecosystem did not invent concept

Slide 44

Slide 44 text

Node.js 44 good fit, huge ecosystem did not invent concept npm install…

Slide 45

Slide 45 text

nodejs? 45

Slide 46

Slide 46 text

no js! 46

Slide 47

Slide 47 text

Everybody’s favorite language… 47

Slide 48

Slide 48 text

PHP 48

Slide 49

Slide 49 text

PHP 49 gets the job done

Slide 50

Slide 50 text

PHP 50 gets the job done widespread usage

Slide 51

Slide 51 text

PHP 51 gets the job done widespread usage if PHP can do it…

Slide 52

Slide 52 text

Examples and demo time 52

Slide 53

Slide 53 text

Putting into practice 53

Slide 54

Slide 54 text

Knowing concepts is good! 54 Building from scratch is not!

Slide 55

Slide 55 text

event-driven programming can get complex 55

Slide 56

Slide 56 text

event-driven programming can get complex use abstractions! 56

Slide 57

Slide 57 text

57

Slide 58

Slide 58 text

58

Slide 59

Slide 59 text

59 related

Slide 60

Slide 60 text

60 related event-driven

Slide 61

Slide 61 text

61 related event-driven asynchronous

Slide 62

Slide 62 text

62 related event-driven asynchronous multi-threaded

Slide 63

Slide 63 text

core concept 63

Slide 64

Slide 64 text

core concept often intertwined 64

Slide 65

Slide 65 text

event-driven, non-blocking I/O for the masses? 65

Slide 66

Slide 66 text

timers 66

Slide 67

Slide 67 text

sockets 67

Slide 68

Slide 68 text

HTTP 68

Slide 69

Slide 69 text

nginx vs. Apache 69

Slide 70

Slide 70 text

Node.js vs. PHP-FPM 70

Slide 71

Slide 71 text

? requests/s 71

Slide 72

Slide 72 text

5k requests/s 72 this is a local single core benchmark! dual core i3 => 10k requests/s 36M requests/h

Slide 73

Slide 73 text

instant real-time updates 73

Slide 74

Slide 74 text

live updates WebSockets 74

Slide 75

Slide 75 text

background worker queues 75

Slide 76

Slide 76 text

no polling 76 jobs instantly picked up thousands of jobs per second concurrently processing hundreds or more

Slide 77

Slide 77 text

700 MiB/s 77 dockerd maxed out PHP not

Slide 78

Slide 78 text

databases 78

Slide 79

Slide 79 text

50k OP/s pure PHP who needs native code anyway? 79

Slide 80

Slide 80 text

event-driven, non-blocking I/O is massively fast 80

Slide 81

Slide 81 text

for the masses? 81

Slide 82

Slide 82 text

when? 82

Slide 83

Slide 83 text

when? 83 app is I/O bound

Slide 84

Slide 84 text

when? 84 app is I/O bound high(er) performance is wanted

Slide 85

Slide 85 text

when? 85 app is I/O bound high(er) performance is wanted blocking and non-blocking can be separated

Slide 86

Slide 86 text

event-driven, non-blocking I/O is massively useful 86

Slide 87

Slide 87 text

Conclusions 87

Slide 88

Slide 88 text

event-driven 88

Slide 89

Slide 89 text

event-driven 89 basic paradigm

Slide 90

Slide 90 text

event-driven 90 basic paradigm very fast & versatile

Slide 91

Slide 91 text

event-driven 91 basic paradigm very fast & versatile consider when app is I/O bound

Slide 92

Slide 92 text

integration 92

Slide 93

Slide 93 text

integration non-blocking and blocking don’t mix well 93

Slide 94

Slide 94 text

integration non-blocking and blocking don’t mix well decide for either approach 94

Slide 95

Slide 95 text

integration non-blocking and blocking don’t mix well decide for either approach isolate & communicate 95

Slide 96

Slide 96 text

ReactPHP 96

Slide 97

Slide 97 text

ReactPHP 97 a real deal and here to stay

Slide 98

Slide 98 text

ReactPHP 98 a real deal and here to stay stable & production ready

Slide 99

Slide 99 text

ReactPHP 99 a real deal and here to stay stable & production ready *awesome*

Slide 100

Slide 100 text

// thank you! $loop->stop(); 100 @another_clue – https://lueck.tv/