Deal with response rate limiting #49

Closed
opened 2020-11-30 20:13:34 +00:00 by projectmoon · 1 comment
Owner

If a response messages from the bot is rate-limited, the message will simply be dropped and the user will never get a response. An error is logged, but this is all. The solution is some kind of queue of unsent messages with exponential backoff. Sled's event watcher is a good candidate for this, as it allows us to store any unsent messages.

Possible solution:

  • Store message response in a sled Tree.
  • The Tree has a watcher subscribed to all new entries.
  • When the watcher receives a new event, it will dump the message into a buffered queue, which is consumed by an async task. Possibly MPSC model.
  • The consumer has a single backoff time, which increases and decreases depending on ratelimit errors.
  • A message that failed to send is shoved back into the queue.
  • When message successfully sent, remove it from the sled Tree.
  • On bot startup, all messages still in the tree are immediately sent into the queue.

With this solution we may under rare circumstances get responses sent twice on a bot restart, but it's better than losing the messages. We can work on not duplicating message sends after basic rate limit handling.

If a response messages from the bot is rate-limited, the message will simply be dropped and the user will never get a response. An error is logged, but this is all. The solution is some kind of queue of unsent messages with exponential backoff. Sled's event watcher is a good candidate for this, as it allows us to store any unsent messages. Possible solution: - Store message response in a sled Tree. - The Tree has a watcher subscribed to all new entries. - When the watcher receives a new event, it will dump the message into a buffered queue, which is consumed by an async task. Possibly MPSC model. - The consumer has a single backoff time, which increases and decreases depending on ratelimit errors. - A message that failed to send is shoved back into the queue. - When message successfully sent, remove it from the sled Tree. - On bot startup, all messages still in the tree are immediately sent into the queue. With this solution we may under rare circumstances get responses sent twice on a bot restart, but it's better than losing the messages. We can work on not duplicating message sends after basic rate limit handling.
Author
Owner

The SDK now has built-in support for handling server rate limiting. So this original issue isn't much of a problem anymore.

The SDK now has built-in support for handling server rate limiting. So this original issue isn't much of a problem anymore.
Sign in to join this conversation.
No Milestone
No project
No Assignees
1 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: projectmoon/tenebrous-dicebot#49
No description provided.