Pro Yearly is on sale from $80 to $50! »

Event-driven programming for the masses (WebMeetupCgn)

Event-driven programming for the masses (WebMeetupCgn)

What makes nginx faster than Apache's original design? What makes Node.js applications faster than traditional web applications? How can we achieve the same benefits for our own applications? This talk discusses how event-driven programming can help in building high performance, non-blocking, reactive, concurrent, single-threaded applications (bingo). Don't worry, no need to install Node.js and npm install half the internet. Let's build high-performance applications from scratch with whatever language you're most comfortable with!

---

This talk was presented at WebMeetupCgn (https://www.meetup.com/de-DE/Web-Meetup-Cologne/events/255796092/) as one of two talks this day (~30 min each). This implies that this is only supposed to be a 101 introduction. The talk includes a number of live demos and examples which are not included as part of the slides, so you may be missing some context here. See you at the next event perhaps?

D1b6700884ac0ae368918ad171bb6a75?s=128

Christian Lück

November 14, 2018
Tweet

Transcript

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

    profit.
  2. Agenda - Hello! - 101 of event-driven programming - Examples

    from scratch - Putting into practice - Conclusions 2
  3. Hello! 3

  4. $ whoami 4

  5. $ whoami Christian Lück 5

  6. $ whoami Christian Lück 6

  7. $ whoami Christian Lueck 7

  8. $ whoami Christian Lueck 8

  9. $ whoami Christian Lueck @clue 9

  10. $ whoami Christian Lueck @another_clue 10

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

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

    freelance software engineer 12
  13. Who are you? 13 now that you know me…

  14. Who are you? 14 now that you know me… -

    programmers / developers? - architects / engineers?
  15. What is event-driven programming? 15

  16. What is an event? 16

  17. event 17

  18. event 18 past action recognized by environment

  19. event 19 past action recognized by environment triggered reaction, listening

  20. event 20 past action recognized by environment triggered reaction, listening

    hardware or software
  21. event-driven 21

  22. event-driven program flow driven by events 22

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

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

    event-loop (reactor) 24
  25. event-driven programming 25

  26. event-driven program? 26

  27. event-driven web applications 27

  28. frontend 28 backend

  29. frontend 29

  30. frontend mouse clicks, keyboard input (UI) 30

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

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

    32
  33. backend 33

  34. backend network protocols (HTTP) 34

  35. backend network protocols (HTTP) database APIs 35

  36. backend network protocols (HTTP) database APIs filesystem 36

  37. backend is all about I/O 37

  38. is your backend all about I/O? 38

  39. Show me some code! 39

  40. Show me some code! Programming language? 40

  41. Node.js 41

  42. Node.js 42 good fit, huge ecosystem

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

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

    npm install…
  45. nodejs? 45

  46. no js! 46

  47. Everybody’s favorite language… 47

  48. PHP 48

  49. PHP 49 gets the job done

  50. PHP 50 gets the job done widespread usage

  51. PHP 51 gets the job done widespread usage if PHP

    can do it…
  52. Examples and demo time 52

  53. Putting into practice 53

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

  55. event-driven programming can get complex 55

  56. event-driven programming can get complex use abstractions! 56

  57. 57

  58. 58

  59. 59 related

  60. 60 related event-driven

  61. 61 related event-driven asynchronous

  62. 62 related event-driven asynchronous multi-threaded

  63. core concept 63

  64. core concept often intertwined 64

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

  66. timers 66

  67. sockets 67

  68. HTTP 68

  69. nginx vs. Apache 69

  70. Node.js vs. PHP-FPM 70

  71. ? requests/s 71

  72. 5k requests/s 72 this is a local single core benchmark!

    dual core i3 => 10k requests/s 36M requests/h
  73. instant real-time updates 73

  74. live updates WebSockets 74

  75. background worker queues 75

  76. no polling 76 jobs instantly picked up thousands of jobs

    per second concurrently processing hundreds or more
  77. 700 MiB/s 77 dockerd maxed out PHP not

  78. databases 78

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

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

  81. for the masses? 81

  82. when? 82

  83. when? 83 app is I/O bound

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

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

    blocking and non-blocking can be separated
  86. event-driven, non-blocking I/O is massively useful 86

  87. Conclusions 87

  88. event-driven 88

  89. event-driven 89 basic paradigm

  90. event-driven 90 basic paradigm very fast & versatile

  91. event-driven 91 basic paradigm very fast & versatile consider when

    app is I/O bound
  92. integration 92

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

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

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

    approach isolate & communicate 95
  96. ReactPHP 96

  97. ReactPHP 97 a real deal and here to stay

  98. ReactPHP 98 a real deal and here to stay stable

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

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