Skip to content
This repository has been archived by the owner on Jan 14, 2022. It is now read-only.

Improve handling of large Redis input #143

Merged
merged 2 commits into from
Apr 27, 2020
Merged

Improve handling of large Redis input #143

merged 2 commits into from
Apr 27, 2020

Commits on Apr 27, 2020

  1. Implement faster buffered input

    This commit implements a modified ring buffer for input from Redis.
    Specifically, Flodgatt now limits the amount of data it fetches from
    Redis in one syscall to 8 KiB (two pages on most systems). Flodgatt
    will process all complete messages it receives from Redis and then
    re-use the same buffer for the next time it retrieves data.  If
    Flodgatt received a partial message, it will copy the partial message
    to the beginning of the buffer before its next read.
    
    This change has little effect on Flodgatt under light load (because it
    was rare for Redis to have more than 8 KiB of messages available at
    any one time).  However, my hope is that this will significantly
    reduce memory use on the largest instances.
    codesections committed Apr 27, 2020
    Configuration menu
    Copy the full SHA
    3782ab1 View commit details
    Browse the repository at this point in the history
  2. Improve handling of backpresure

    This commit alters how Flodgatt behaves if it receives enough messages
    for a single client to fill that clients channel. (Because the clients
    regularly send their messages, should only occur if a single client
    receives a large number of messages nearly simultaneously; this is
    rare, but could occur, especially on large instances).
    
    Previously, Flodgatt would drop messages in the rare case when the
    client's channel was full.  Now, Flodgatt will pause the current Redis
    poll and yield control back to the client streams, allowing the
    clients to empty their channels; Flodgatt will then resume polling
    Redis/sending the messages it previously received.  With the approach,
    Flodgatt will never drop messages.
    
    However, the risk to this approach is that, by never dropping
    messages, Flodgatt does not have any way to reduce the amount of work
    it needs to do when under heavy load – it delays the work slightly,
    but doesn't reduce it.  What this means is that it would be
    *theoretically* possible for Flodgatt to fall increasingly behind, if
    it is continuously receiving more messages than it can process.  Due
    to how quickly Flodgatt can process messages, though, I suspect this
    would only come up if an admin were running Flodgatt in a
    *significantly* resource constrained environment, but I wanted to
    mention it for the sake of completeness.
    
    This commit also adds a new /status/backpressure endpoint that
    displays the current length of the Redis input buffer (which should
    typically be low or 0).  Like the other /status endpoints, this
    endpoint is only enabled when Flodgatt is compiled with the
    `stub_status` feature.
    codesections committed Apr 27, 2020
    Configuration menu
    Copy the full SHA
    013f1f2 View commit details
    Browse the repository at this point in the history