Non-blocking IO for the masses (WebEngDUS)

Non-blocking IO for the masses (WebEngDUS)

I/O is everywhere. I/O is slow. There's no denying it. Using traditional blocking I/O calls can thus be seen as a huge contributor to slow applications. This talk discusses how non-blocking I/O can help in building high performance, event-driven, 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 WebEngDUS (https://www.meetup.com/de-DE/Web-Engineering-Duesseldorf/events/252097938/) as one of three talks this day (~20 min each). This implies that this is only supposed to be a 101 introduction.

You can find the examples (source code) here: https://gist.github.com/clue/e0425c34c0ab13e8496716aae0219245

D1b6700884ac0ae368918ad171bb6a75?s=128

Christian Lück

July 12, 2018
Tweet

Transcript

  1. non-blocking I/O for the masses High performance for fun and

    profit.
  2. Agenda - Hello! - 101 of non-blocking I/O - 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 non-blocking I/O? 15

  16. What is I/O? 16

  17. input / output 17

  18. IPO 18

  19. IPO 19 input = read()

  20. IPO 20 input = read() result = process(input)

  21. IPO 21 input = read() result = process(input) output(result)

  22. I/O is everywhere 22

  23. I/O is everywhere third party HTTP APIs (RESTful, SOAP, you

    name it…) 23
  24. I/O is everywhere third party HTTP APIs (RESTful, SOAP, you

    name it…) mysql, postgres 24
  25. I/O is everywhere third party HTTP APIs (RESTful, SOAP, you

    name it…) mysql, postgres filesystem I/O (session files) 25
  26. I/O is everywhere third party HTTP APIs (RESTful, SOAP, you

    name it…) mysql, postgres filesystem I/O (session files) redis, memcache 26
  27. I/O is everywhere! 27

  28. 28 Source: Latency Numbers Every Programmer Should Know: https://gist.github.com/jboner/2841832 CPU

    vs I/O
  29. I/O is slow! 29

  30. What is non-blocking I/O? 30

  31. the idea 31

  32. the idea calculations are fast 32

  33. the idea calculations are fast I/O is slow 33

  34. the idea calculations are fast I/O is slow why wait?

    34
  35. Show me some code! Programming language? 35

  36. Node.js 36

  37. Node.js 37 good fit, huge ecosystem

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

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

    npm install…
  40. nodejs? 40

  41. no js! 41

  42. Everybody’s favorite language… 42

  43. PHP 43

  44. PHP 44 gets the job done

  45. PHP 45 gets the job done widespread usage

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

    can do it…
  47. Examples and demo time 47

  48. 48

  49. Putting into practice 49

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

  51. Non-blocking I/O can get complex 51

  52. Non-blocking I/O can get complex use abstractions! 52

  53. 53

  54. 54

  55. 55 related

  56. 56 related event-driven

  57. 57 related event-driven asynchronous

  58. 58 related event-driven asynchronous multi-threaded

  59. core concept 59

  60. core concept often intertwined 60

  61. 61

  62. for the masses? 62

  63. 700 MiB/s 63 dockerd maxed out PHP not

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

    dual core i3 => 10k requests/s 36M requests/h
  65. 50k OP/s pure PHP who needs native code anyway? 65

  66. non-blocking I/O is massively fast 66

  67. for the masses? 67

  68. when? 68

  69. when? 69 app is I/O bound

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

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

    blocking and non-blocking can be separated
  72. non-blocking I/O is massively useful 72

  73. Conclusions 73

  74. nbio 74

  75. nbio 75 basic paradigm

  76. nbio 76 basic paradigm very fast & versatile

  77. nbio 77 basic paradigm very fast & versatile consider when

    app is I/O bound
  78. integration 78

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

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

    approach 80
  81. integration non-blocking and blocking don’t mix well decide for either

    approach isolate & communicate 81
  82. ReactPHP 82

  83. ReactPHP 83 a real deal and here to stay

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

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

    & production ready *awesome*
  86. 86

  87. 87

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