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

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

Christian Lück
PRO

July 12, 2018
Tweet

More Decks by Christian Lück

Other Decks in Programming

Transcript

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

    View Slide

  2. Agenda
    - Hello!
    - 101 of non-blocking I/O
    - Examples from scratch
    - Putting into practice
    - Conclusions
    2

    View Slide

  3. Hello!
    3

    View Slide

  4. $ whoami
    4

    View Slide

  5. $ whoami
    Christian Lück
    5

    View Slide

  6. $ whoami
    Christian Lück
    6

    View Slide

  7. $ whoami
    Christian Lueck
    7

    View Slide

  8. $ whoami
    Christian Lueck
    8

    View Slide

  9. $ whoami
    Christian Lueck
    @clue
    9

    View Slide

  10. $ whoami
    Christian Lueck
    @another_clue
    10

    View Slide

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

    View Slide

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

    View Slide

  13. Who are you?
    13
    now that you know me…

    View Slide

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

    View Slide

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

    View Slide

  16. What is I/O?
    16

    View Slide

  17. input / output
    17

    View Slide

  18. IPO
    18

    View Slide

  19. IPO
    19
    input = read()

    View Slide

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

    View Slide

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

    View Slide

  22. I/O is everywhere
    22

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

  27. I/O is everywhere!
    27

    View Slide

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

    View Slide

  29. I/O is slow!
    29

    View Slide

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

    View Slide

  31. the idea
    31

    View Slide

  32. the idea
    calculations are fast
    32

    View Slide

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

    View Slide

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

    View Slide

  35. Show me some code!
    Programming language?
    35

    View Slide

  36. Node.js
    36

    View Slide

  37. Node.js
    37
    good fit, huge ecosystem

    View Slide

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

    View Slide

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

    View Slide

  40. nodejs?
    40

    View Slide

  41. no js!
    41

    View Slide

  42. Everybody’s favorite language…
    42

    View Slide

  43. PHP
    43

    View Slide

  44. PHP
    44
    gets the job done

    View Slide

  45. PHP
    45
    gets the job done
    widespread usage

    View Slide

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

    View Slide

  47. Examples and demo time
    47

    View Slide

  48. 48

    View Slide

  49. Putting into practice
    49

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

  53. 53

    View Slide

  54. 54

    View Slide

  55. 55
    related

    View Slide

  56. 56
    related
    event-driven

    View Slide

  57. 57
    related
    event-driven
    asynchronous

    View Slide

  58. 58
    related
    event-driven
    asynchronous
    multi-threaded

    View Slide

  59. core concept
    59

    View Slide

  60. core concept
    often intertwined
    60

    View Slide

  61. 61

    View Slide

  62. for the masses?
    62

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

  67. for the masses?
    67

    View Slide

  68. when?
    68

    View Slide

  69. when?
    69
    app is I/O bound

    View Slide

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

    View Slide

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

    View Slide

  72. non-blocking I/O is
    massively useful
    72

    View Slide

  73. Conclusions
    73

    View Slide

  74. nbio
    74

    View Slide

  75. nbio
    75
    basic paradigm

    View Slide

  76. nbio
    76
    basic paradigm
    very fast & versatile

    View Slide

  77. nbio
    77
    basic paradigm
    very fast & versatile
    consider when app is I/O bound

    View Slide

  78. integration
    78

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

  82. ReactPHP
    82

    View Slide

  83. ReactPHP
    83
    a real deal and here to stay

    View Slide

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

    View Slide

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

    View Slide

  86. 86

    View Slide

  87. 87

    View Slide

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

    View Slide