grammyjs / runner

Scale bots that use long polling to receive updates.
https://grammy.dev/plugins/runner
MIT License
18 stars 2 forks source link

feat: Balancing number of updates per call #9

Closed KnorpelSenf closed 1 year ago

KnorpelSenf commented 2 years ago

Currently, the runner pulls in updates as agressively as possible (when using run(bot)). While this leads to the highest possible responsiveness of the bot, it also causes more network traffic than if there was a short delay between the calls. Ideally, we would:

  1. Measure the throughput dynamically, averaging over the last 15 calls or so
  2. Compute how much time it would take to fill up an array of 100 updates
  3. Add a config option that lets users specify if they want responsiveness or few network calls, as a value between 0 and 1
  4. Dynamically add delays between the calls when the runner simply idles, waiting for more updates to accumulate before they are being fetched

Naturally, this would have to be done in a way that certain interruption in traffic do not lead to too long idle phases. In other words, this would have to be done in a way such that responsiveness does not suddenly drop arbitrarily low because the runner is trying to wait for three hours until the update array is filled.