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

Type uWSGI; Press Enter; What Happens?

Type uWSGI; Press Enter; What Happens?

Talk given at PyTN 2018

Philip James

February 11, 2018
Tweet

More Decks by Philip James

Other Decks in Technology

Transcript

  1. #typeuwsgi
    Type uWSGI;
    Press Enter;
    What Happens?
    Philip James — @phildini
    PyTN 2018

    View full-size slide

  2. #typeuwsgi
    uWSGI…?

    View full-size slide

  3. #typeuwsgi
    • How does uWSGI handle processes?
    • How does uWSGI handle networking?
    • Why use uWSGI?

    View full-size slide

  4. #typeuwsgi
    pythonista@conf:~ $ python
    Python 3.5.2 (default, Oct 11 2016, 05:05:28)
    [GCC 4.2.1 Compatible Apple LLVM 8.0.0
    (clang-800.0.38)] on darwin
    Type "help", "copyright", "credits" or "license"
    for more information.
    >>>

    View full-size slide

  5. #typeuwsgi
    python
    pid: 1222
    argv = [‘python’]
    0: [terminal]
    1: [terminal]
    2: [terminal]
    bash
    pid: 1221

    View full-size slide

  6. #typeuwsgi
    • How does uWSGI handle processes?
    • How does uWSGI handle networking?
    • Why use uWSGI?

    View full-size slide

  7. #typeuwsgi
    Catserve: Cats as a Service
    https://github.com/phildini/catserve

    View full-size slide

  8. #typeuwsgi
    me@conf:~ $ uwsgi --master --http :8000 --module catserve.wsgi -p 2
    *** Starting uWSGI 2.0.15 (64bit) on [Thu May 11 10:09:35 2017] ***
    . . .
    uWSGI http bound on :8000 fd 4
    spawned uWSGI http 1 (pid: 1220)
    uwsgi socket 0 bound to TCP address 127.0.0.1:52891
    (port auto-assigned) fd 3
    Python version: 3.5.2 (default, Oct 11 2016, 05:05:28) [GCC 4.2.1
    Compatible Apple LLVM 8.0.0 (clang-800.0.38)]
    . . .
    spawned uWSGI worker 1 (and the only) (pid: 1221, cores: 1)
    Processes

    View full-size slide

  9. #typeuwsgi
    *** Starting uWSGI 2.0.15 (64bit) on [Thu May 11 10:09:35 2017] ***
    . . .
    uWSGI http bound on :8000 fd 4
    spawned uWSGI http 1 (pid: 1220)
    uwsgi socket 0 bound to TCP address 127.0.0.1:52891
    (port auto-assigned) fd 3
    Python version: 3.5.2 (default, Oct 11 2016, 05:05:28) [GCC 4.2.1
    Compatible Apple LLVM 8.0.0 (clang-800.0.38)]
    . . .
    spawned uWSGI worker 1 (and the only) (pid: 1221, cores: 1)
    Processes
    me@conf:~ $ uwsgi --master --http :8000 --module catserve.wsgi -p 2

    View full-size slide

  10. #typeuwsgi
    uwsgi
    pid: 1220
    python
    pid: 1221

    View full-size slide

  11. #typeuwsgi
    *** Starting uWSGI 2.0.15 (64bit) on [Thu May 11 10:09:35 2017] ***
    . . .
    uWSGI http bound on :8000 fd 4
    spawned uWSGI http 1 (pid: 1220)
    uwsgi socket 0 bound to TCP address 127.0.0.1:52891
    (port auto-assigned) fd 3
    Python version: 3.5.2 (default, Oct 11 2016, 05:05:28) [GCC 4.2.1
    Compatible Apple LLVM 8.0.0 (clang-800.0.38)]
    . . .
    spawned uWSGI worker 1 (pid: 1221, cores: 1)
    spawned uWSGI worker 2 (pid: 1222, cores: 1)
    Processes
    me@conf:~ $ uwsgi --master --http :8000 --module catserve.wsgi -p 2

    View full-size slide

  12. #typeuwsgi
    uwsgi
    pid: 1220
    python
    pid: 1221
    python
    pid: 1222

    View full-size slide

  13. #typeuwsgi
    • How does uWSGI handle processes?
    • How does uWSGI handle networking?
    • Why use uWSGI?

    View full-size slide

  14. #typeuwsgi
    Networking
    *** Starting uWSGI 2.0.15 (64bit) on [Thu May 11 10:09:35 2017] ***
    . . .
    uWSGI http bound on :8000 fd 4
    spawned uWSGI http 1 (pid: 1220)
    uwsgi socket 0 bound to TCP address 127.0.0.1:52891
    (port auto-assigned) fd 3
    Python version: 3.5.2 (default, Oct 11 2016, 05:05:28) [GCC 4.2.1
    Compatible Apple LLVM 8.0.0 (clang-800.0.38)]
    . . .
    spawned uWSGI worker 1 (pid: 1221, cores: 1)
    spawned uWSGI worker 2 (pid: 1222, cores: 1)
    me@conf:~ $ uwsgi --master --http :8000 --module catserve.wsgi -p 2

    View full-size slide

  15. #typeuwsgi
    22
    sshd
    8000
    uwsgi
    Kernel
    Userland
    syscall
    syscall

    View full-size slide

  16. #typeuwsgi
    uwsgi
    Kernel
    8000

    View full-size slide

  17. #typeuwsgi
    uwsgi
    Kernel
    socket()
    8000

    View full-size slide

  18. #typeuwsgi
    uwsgi
    Kernel
    4 -> socket:[…]
    8000

    View full-size slide

  19. #typeuwsgi
    uwsgi
    Kernel
    4 -> socket:[…]
    bind()
    8000

    View full-size slide

  20. #typeuwsgi
    uwsgi
    Kernel
    4 -> socket:[…]
    bind()
    8000

    View full-size slide

  21. #typeuwsgi
    uwsgi
    Kernel
    4 -> socket:[…]
    listen()
    8000

    View full-size slide

  22. #typeuwsgi
    uwsgi
    Kernel
    4 -> socket:[…]
    8000
    python
    python
    4 -> socket:[…]
    4 -> socket:[…]

    View full-size slide

  23. #typeuwsgi
    uwsgi
    Kernel
    4 -> socket:[…]
    8000
    python
    python
    4 -> socket:[…]
    4 -> socket:[…]
    epoll_wait()
    epoll_wait()

    View full-size slide

  24. #typeuwsgi
    uwsgi
    Kernel
    4 -> socket:[…]
    8000
    python
    python
    4 -> socket:[…]
    4 -> socket:[…]
    accept()
    epoll_wait()
    5 -> socket:[…]
    epoll_wait()
    accept()

    View full-size slide

  25. #typeuwsgi
    • How does uWSGI handle processes?
    • How does uWSGI handle networking?
    • Why use uWSGI?

    View full-size slide

  26. #typeuwsgi
    Code Reloading
    uwsgi
    pid: 1220
    python
    pid: 1221
    python
    pid: 1222
    sighup sighup
    4 -> socket:[…]

    View full-size slide

  27. #typeuwsgi
    Tunability
    uwsgi
    pid: 1220
    python
    pid: 1221
    python
    pid: 1222
    me@conf:~ $ uwsgi --master --http :8000 --module catserve.wsgi -p 2

    View full-size slide

  28. #typeuwsgi
    Security
    GET / HTTP/1.1
    Host: catserve.io
    GET / HTTP/1.1
    Host: catserve.io
    Host: catserve.biz
    "[runserver] has not gone through security audits…
    and that’s how it’s gonna stay.”

    View full-size slide

  29. #typeuwsgi
    Config Files
    [uwsgi]
    master = 1
    http = 8000
    module = catserve.wsgi
    processes = 2
    me@conf:~ $ uwsgi --master --http :8000 --module catserve.wsgi -p 2

    View full-size slide

  30. #typeuwsgi
    Features
    • Static file serving
    • Max requests per worker
    • Queuing systems
    • HTTPS support, HTTP2 support
    • Harakiri
    • uwsgitop
    • memory-report
    • async

    View full-size slide

  31. #typeuwsgi
    Why uWSGI?
    • Code Reloading
    • Tunability
    • Security
    • Config Files
    • Features

    View full-size slide

  32. #typeuwsgi
    • How does uWSGI handle processes?
    • How does uWSGI handle networking?
    • Why use uWSGI?
    Thanks!
    @unbit Questions?
    Patreon!
    Philip
    James
    @[email protected]
    [email protected]

    View full-size slide