Commit Graph

8 Commits

Author SHA1 Message Date
Daniel Sockwell daf7d1ae7f
Add tests for polling for multiple messages (#149)
* Add tests for polling for multiple messages

This commit adds a mock Redis interface and adds tests that poll the
mock interface for multiple messages at a time.  These tests test that
Flodgatt is robust against receiving incomplete messages, including if
the message break results in receiving invalid UTF8.

* Remove temporary files
2020-05-07 10:56:11 -04:00
Daniel Sockwell 4a13412f98
Improve handling of large Redis input (#143)
* 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.

* 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.
2020-04-27 16:03:05 -04:00
Daniel Sockwell b18500b884
Resolve memory-use regression (#140)
* Use monotonically increasing channel_id

Using a monotonically increasing channel_id (instead of a Uuid)
reduces memory use under load by ~3%

* Use replace unbounded channels with bounded

This also slightly reduces memory use

* Heap allocate Event

Wrapping the Event struct in an Arc avoids excessive copying and significantly reduces memory use.

* Implement more efficient unsubscribe strategy

* Fix various Clippy lints; bump version

* Update config defaults
2020-04-24 13:23:59 -04:00
Daniel Sockwell 91186fb9f7
Postgres (#137)
* Revise Postgres to use `simple_query`

* Fix bug in logging `ENV` config errors

* Improve parsing of values from Postgres

* Finish Postgres changes
2020-04-23 12:04:30 -04:00
Daniel Sockwell 016f49a2d8
Improve module privacy (#136)
* Adjust module privacy

* Use trait object

* Finish module privacy refactor
2020-04-22 14:38:22 -04:00
Daniel Sockwell 1dcddc23de
Update module privacy (#133)
This squashed commit rolls up a series of changes designed to improve
Flodgatt's public API/module boundary.  Specifically, this limits the
number of Items that are exported outside the top-level modules (in some
cases because they were already not needed outside that module due to
the earlier code reorganization and in some cases by using public
re-exports to export particular Items from a private module).

Similarly, this commit moves the `Event` struct to the `response`
module (maintaining privacy for the `Event`'s implementation details)
while re-exporting the `Id` struct that `Event` uses internally at the
top level.

All of these changes are made with the goal of making Flodgatt's code
easier to reason about in isolation, which should both make it easier to
maintain and make it easier for new contributors to make changes without
understanding the entire codebase.  Additionally, having fewer public
modules will make documenting Flodgatt more extensively much easier.
2020-04-21 16:39:31 -04:00
Daniel Sockwell 37b652ad79
Error handling, pt3 (#131)
* Improve handling of Postgres errors

* Finish error handling improvements

* Remove `format!` calls from hot path
2020-04-14 20:37:49 -04:00
Daniel Sockwell 45f9d4b9fb
Code reorganization (#130)
* Reorganize files

* Refactor main()

* Code reorganization [WIP]

* Reorganize code [WIP]

* Refacto RedisConn [WIP]

* Complete code reorganization
2020-04-13 16:03:06 -04:00