Skip to content

Adaptive LIFO mode for the request queue #574

@ipeterov

Description

@ipeterov

I'm using Daphne for both http and ws requests for my project, and I've noticed that if my service gets spammed with a surge of requests, they are executed in the order they came in. This is intuitive and fair, however, this effectively shuts my webserver down if the volume of requests is more than it can handle (instead of letting it process as much as it can and fail the rest).

The fundamental problem is this - every request comes with an external timeout (in my case, from the ALB balancer above it), and with a FIFO queue, we're wasting time processing requests that have already timed out OR are close to timing out externally, instead of responding to stuff that the client is still waiting for.

I've seen multiple articles from big tech companies mentioning this, but to my knowledge, they all build custom tools to get this to work (I can't find this setting in daphne / nginx / uwsgi / ALB):

I've also seen this behavior in multiple production projects I maintain.

I built an interactive visualization to help illustrate the point. You can configure the request flow, and then play with FIFO/LIFO/Adaptive LIFO/Max queue size. Check it out here: https://ipeterov.github.io/queue-demo/

Visualization.mov

Do you guys think this makes sense? Or is this a dumb idea?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions