Slide 1

Slide 1 text

the thundering herd and other concurrency programming challenges Pycon JP 2014 - Tokyo By Benoit Chesneau

Slide 2

Slide 2 text

GUNICORN DESIGN

Slide 3

Slide 3 text

prefork-worker model share sockets between OS processes workers are monitored allows different kind of workers gunicorn design

Slide 4

Slide 4 text

arbiter worker spawn & share sockets share socket

Slide 5

Slide 5 text

each worker waits (accepts) for a connection the OS balance connections in the backlog sync worker accept only 1 connection at a time async workers accept many connections competition to accept

Slide 6

Slide 6 text

arbiter worker notify monitor workers kill

Slide 7

Slide 7 text

the arbiter workflow Signal check the 
 signal queue Put in signal queue handle the signal not empty empty murder workers sleep manage workers

Slide 8

Slide 8 text

different concurrency strategy different platforms support don’t want to handle WSGI only more… why different workers?

Slide 9

Slide 9 text

THE THUNDERING HERD
 PROBLEM

Slide 10

Slide 10 text

All process can be awoken on accept for the same connection can trigger EAGAIN increase the CPU usage for nothing. not true with modern OSes for 1 socket the thundering herd problem

Slide 11

Slide 11 text

ticket Gunicorn#792 Introduce signaling between workers and the arbiter using a Pipe Use our own internal messaging implementation the arbiter checks if the a socket can read Workers asks for more work or notify they are alive fixing thundering herd: how to solve it

Slide 12

Slide 12 text

arbiter worker new signaling send message

Slide 13

Slide 13 text

Messages Arbiter Worker ACCEPT:SOCKET ALIVE:TIMESTAMP ACCEPT

Slide 14

Slide 14 text

the arbiter has a new job All workers need to be updated new signaling API to be handled by the worker: an helper module will be provided introduce complexity

Slide 15

Slide 15 text

with one socket, let all workers accepting if wanted depending on the load, bypass the signaling possible optimisations

Slide 16

Slide 16 text

ONE COMMAND TO RULE THEM ALL

Slide 17

Slide 17 text

no more gunicorn_django, gunicorn_paster fix preloading issue offer the same experience for all WSGI applications new settings: —paste, —pythonpath, —env Only one command in 20.0 (deprecations are removed) gunicorn - the only command

Slide 18

Slide 18 text

Enhance the user experience

Slide 19

Slide 19 text

ticket Gunicorn#837 plugins everywhere: logging, workers more embeddable: the gunicorn engine A new organization: 
 http:/ /github.com/gunicorn WIP: Deadline 2014/12 Enhance the user experience.

Slide 20

Slide 20 text

? @benoitc Support me https:/ /gratipay.com/benoitc/