René's URL Explorer Experiment


Title: New Mechanism for Avoiding Flood Limits · Issue #3018 · python-telegram-bot/python-telegram-bot · GitHub

Open Graph Title: New Mechanism for Avoiding Flood Limits · Issue #3018 · python-telegram-bot/python-telegram-bot

X Title: New Mechanism for Avoiding Flood Limits · Issue #3018 · python-telegram-bot/python-telegram-bot

Description: supercedes & closes #2139 Below I write down the different thoughts that I had on how we can introduce a new rate limiting mechanism. Pretty much everything is up for discussion. What do you want to have designed differently? What did I ...

Open Graph Description: supercedes & closes #2139 Below I write down the different thoughts that I had on how we can introduce a new rate limiting mechanism. Pretty much everything is up for discussion. What do you want t...

X Description: supercedes & closes #2139 Below I write down the different thoughts that I had on how we can introduce a new rate limiting mechanism. Pretty much everything is up for discussion. What do you wa...

Opengraph URL: https://github.com/python-telegram-bot/python-telegram-bot/issues/3018

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"New Mechanism for Avoiding Flood Limits","articleBody":"supercedes & closes #2139\r\n\r\nBelow I write down the different thoughts that I had on how we can introduce a new rate limiting mechanism. Pretty much everything is up for discussion. What do you want to have designed differently? What did I miss?\r\n\r\n# Feature/Mechanism-Wishlist \r\n\r\n## Integration into PTB\r\n\r\nOne of the major shortcomings of `MessageQueue` was that it was not properly integrated with the framework. IMO that's one of the main points that should be considered. I image that the setup be such that something like\r\n\r\n```python\r\nExtBot(…, rate_limiter=RateLimiter(…))\r\n```\r\nor\r\n```python\r\nApplication.bulder().token('token').rate_limiter(RateLimiter(…)).build()\r\n```\r\nsuffices. That is, `ExtBot` would have a (protected?) attribute holding the rate limiter and all requests would automatically go through that.\r\nNote that I wrote `ExtBot` - this functionality should be purely for `telegram.ext` and not in `telegram`.\r\n\r\n`getUpdates` should not get passed through the rate limiter.\r\n\r\n## Abstract Interface\r\n\r\nI'd like to make this a pluggable interface similar to `BaseRequest`. that way we give users a chance to implement custom, elaborate logic on their own. Such an interface class will probably just have once method - maybe `process_request` or so that `Bot` will call.\r\n\r\nHowever, I'm somewhat unsure what this method should do/return. I see two options:\r\n\r\n1. Return the actual return value of the api request. In this case, `ExtBot` would probably do something like `await self._rate_limiter.process_request(self._post(…))` and in `process_update` one could do somethling like `async with self._semaphore: await coroutine`\r\n2. Alternatively, `procless_update` could return an async context manager, such that `ExtBot` would do `async with self._rate_limiter.process_request(…): await self._post(…)`\r\n\r\nI guess the second one might be a bit harder for python-novices to implement. Then again, doing that is a rather advanced task anyway.\r\nThe first one may also allow for a bit more flexibility in the implementations. OTOH, the context manager approach separates the `Bot` from the `RateLimiter` a bit more clearly, which I potentially like.\r\n\r\n### Open question: Retries\r\n\r\nOne thing that one can think of is whether the rate limiter should be allowed/expected to retry a request in case a `RetryAfter` exception is raised. My gut feeling is that it shouldn't, as it violates the chain of command in the PTB framework. But I'm not completely sure.\r\nIn case we want to allow for retries, we'd have to provide way for that to be possible, e.g. by passing a tuple `(method, kwargs)` such that the rate limiter can call `method(**kwargs)` as often as needed.\r\n\r\n## Per-Request Decisions/Priorities\r\n\r\nIMO it's important to try and allow for requests to be processed differently depending on \r\n\r\n* the endpoint (`answerInlineQuery`, `sendMessage`, etc)\r\n* the parameters passed to that endpoint\r\n* maybe even additional arguments that can be passed on a per-call basis.\r\n\r\nThis would allow to e.g. give answering inline queries a higher priority than sending messages and giving batch-notifications a lower priority than other messages (there even was a Discussions entry requesting something like this at some point, but I can't find it now)\r\n\r\nSo a signature of `process_request` could look like\r\n\r\n```python\r\nasync def process_request(self, (coroutine ,)endpoint: str, data: Dict[str, Any], rate_limit_kwargs: Dict[str, Any]):\r\n    ...\r\n``` \r\n\r\nHere IMO the `data` should *not* be the `RequestData` that we pass to `BaseRequest` but basically the plain parameters that are passed to the bot method (after inserting `DefaultValues`.\r\n\r\n# Naming\r\n\r\nMaybe `BaseRateLimiter`?\r\n\r\n# Possible built-in implementation\r\n\r\nWe could provide a basic implementation out of the box. For that we could use a 3rd party dependency like `aiolimiter` or `pyrate-limiter`. Both are published under the MIT license, so that shouldn't be a problem. `aiolimiter` has only one stable release but to me it looks bit bit cleaner, with a small, well defined feature set - though that may just be a first impression.\r\nI imagine that such an implementation could be relatively close to what `MessageQueue` formerly did, i.e. enforce a global delay and a per-group/chat delay. One could think of providing that in a priority-queue style fashion such that user can specify a priority though the `rate_limit_kwargs`.\r\n\r\n# Implementation\r\n\r\nThe main task of calling `process_request` in the right spot should not be too difficult. The main issue that I see is to keep the logic away from `tg.Bot`. For that I have a few ideas:\r\n\r\n## Part 1\r\nFor passing `endpoint` and `data` it should suffice to split up `tg.Bot._post` a bit so that `ExtBot` has a chance to link into the spot between inserting `DefaultValues` and calling `Bot.request._post`.\r\n\r\n## Part 2\r\nFor passing `rate_limit_kwargs`, that's a bit more tricky. We'd have to add a new parameter to all methods of `ExtBot`, but we don't want to add them to `Bot`. \r\n\r\nOne straightforward option would be to split up `Bot.send_message` into `Bot._send_message` and `Bot.send_message`, where only the protected one has the additional parameter. `Bot.send_message` would then just pass everything along to `_send_message` and `ExtBot.send_message` would call `Bot._send_message` directly. This would result in *many* additional loc in `tg.Bot`. Additionally, this doesn't play well with shortcut methods.\r\n\r\nThe other idea that is to piggyback on `api_kwargs`: We add a parameter `rate_limit_kwargs` to `ExtBot.send_message`, but call `super().send_message(…, api_kwargs=api_kwargs |= {secret_key: rate_limit_kwargs)`. Then before passing everything to the rate limiter, we extract them as `rate_limit_kwargs = api_kwargs.pop(secret_key, {})`. This looks like a dirty hack at first glance, but the longer I think about it, the more I actually like it:\r\n\r\n1. `api_kwargs` doesn't interfere with any of the other parameters, so it's rather safe to use for that\r\n2. keeps `Bot` and `ExtBot` apart without introducing endless boilerplate\r\n3. allows the shortcut methods to also have a paremeter `rate_limit_kwargs` - we can just throw an error if they are used with a `Bot` instead of an `ExtBot`\r\n","author":{"url":"https://github.com/Bibo-Joshi","@type":"Person","name":"Bibo-Joshi"},"datePublished":"2022-05-09T19:01:14Z","url":"https://github.com/python-telegram-bot/python-telegram-bot/issues/3018"}

react-profiling0
react-import-mapreact,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322
route-pattern/_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format)
route-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:ea1ca3d8-b5af-b6ed-ec18-432210189a44
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idE9D2:3A8E64:252871B:30E9D2A:6B025DED
html-safe-nonce8a2d488a8e802873dd22cf02ce6a5ab68a360e26dce313772ebc03f3c0a704e5
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFOUQyOjNBOEU2NDoyNTI4NzFCOjMwRTlEMkE6NkIwMjVERUQiLCJ2aXNpdG9yX2lkIjoiODczNDg5NzI2MDUyMzA1MjUyNSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9
visitor-hmac7e3dd454ac162a0817e1bd978fadc6d7f2805e776c7db01b7807f03345ffc167
hovercard-subject-tagissue:1230125532
github-keyboard-shortcutsrepository,issues,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///voltron/issues_fragments/issue_layout
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/python-telegram-bot/python-telegram-bot/3018/issue_layout
twitter:imagehttps://opengraph.githubassets.com/d188ddeb8bf67ab5f96fcf4e0a268924c4b8500d5aee487627031ef67e2e0289/python-telegram-bot/python-telegram-bot/issues/3018
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/d188ddeb8bf67ab5f96fcf4e0a268924c4b8500d5aee487627031ef67e2e0289/python-telegram-bot/python-telegram-bot/issues/3018
og:image:altsupercedes & closes #2139 Below I write down the different thoughts that I had on how we can introduce a new rate limiting mechanism. Pretty much everything is up for discussion. What do you want t...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernameBibo-Joshi
hostnamegithub.com
expected-hostnamegithub.com
None87e774ee7c6b3bee0490394e4d3e57ec9dbc956f74b87ea685dc8996c1676456
turbo-cache-controlno-preview
go-importgithub.com/python-telegram-bot/python-telegram-bot git https://github.com/python-telegram-bot/python-telegram-bot.git
octolytics-dimension-user_id16178365
octolytics-dimension-user_loginpython-telegram-bot
octolytics-dimension-repository_id38696925
octolytics-dimension-repository_nwopython-telegram-bot/python-telegram-bot
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id38696925
octolytics-dimension-repository_network_root_nwopython-telegram-bot/python-telegram-bot
turbo-body-classeslogged-out env-production page-responsive
disable-turbofalse
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release423dbb54c5e7bfecc838eb387c1435eb3d0e760d
ui-targetfull
theme-color#1e2327
color-schemelight dark
react-app-nameissues

Links:

Skip to contenthttps://github.com/python-telegram-bot/python-telegram-bot/issues/3018#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython-telegram-bot%2Fpython-telegram-bot%2Fissues%2F3018
GitHubRepository hosting, code review, and collaborationhttps://github.com/platform
CopilotAI coding agent for tasks, projects, and automated workhttps://github.com/features/copilot
ActionsCI/CD and automationhttps://github.com/features/actions
Code QualityQuality analysis, fixes, and enforcementhttps://github.com/features/code-quality
CodespacesCloud development environmentshttps://github.com/features/codespaces
Code SecurityVulnerability detection and remediationhttps://github.com/security/advanced-security/code-security
Secret ProtectionSecret scanning and leak preventionhttps://github.com/security/advanced-security/secret-protection
All Featureshttps://github.com/features
Documentationhttps://docs.github.com/en
Traininghttps://learn.github.com/skills
Certificationshttps://learn.github.com/credentials
Build with Copilothttps://github.com/features/ai
Customize Copilothttps://docs.github.com/en/copilot/how-tos/copilot-on-github/customize-copilot/customize-copilot-overview
Integrationshttps://github.com/marketplace
Trending reposhttps://github.com/trending
GitHub Sponsorshttps://github.com/open-source/sponsors
Developer articleshttps://github.com/resources/articles
ChangelogYour source for the latest features, improvements, and fixes across GitHub products, all in one place.https://github.blog/changelog/
Enterpriseshttps://github.com/enterprise
Teamhttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
See all industrieshttps://github.com/solutions/industry
Why GitHubhttps://github.com/why-github
Customer Storieshttps://github.com/customer-stories
Business insightshttps://github.com/solutions/executive-insights
Trust Centerhttps://github.com/trust-center
GitHub Advanced SecurityEnterprise-grade code securityhttps://github.com/security/advanced-security
Copilot for businessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/enterprise/premium-support
Documentationhttps://docs.github.com/en
Resource centerhttps://github.com/resources
Bloghttps://github.blog/
Events & webinarshttps://github.com/resources/events
Community Forumhttps://github.com/orgs/community/discussions
Customer Storieshttps://github.com/customer-stories
Integrationshttps://github.com/marketplace
Customer supporthttps://help.github.com/
Traininghttps://learn.github.com/skills
GitHub Statushttps://www.githubstatus.com/
Abouthttps://github.com/about
Partnershttps://github.com/partners
Changeloghttps://github.blog/changelog/
GitHub UniverseThe event for developers, by developers — talks, workshops, and what’s next for GitHub.https://githubuniverse.com/
Pricinghttps://github.com/pricing
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython-telegram-bot%2Fpython-telegram-bot%2Fissues%2F3018
Sign uphttps://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fvoltron%2Fissues_fragments%2Fissue_layout&source=header-repo&source_repo=python-telegram-bot%2Fpython-telegram-bot
Reloadhttps://github.com/python-telegram-bot/python-telegram-bot/issues/3018
Reloadhttps://github.com/python-telegram-bot/python-telegram-bot/issues/3018
Reloadhttps://github.com/python-telegram-bot/python-telegram-bot/issues/3018
python-telegram-bothttps://github.com/python-telegram-bot
python-telegram-bothttps://github.com/python-telegram-bot/python-telegram-bot
Codehttps://github.com/python-telegram-bot/python-telegram-bot
Issues23 (23)https://github.com/python-telegram-bot/python-telegram-bot/issues
Pull requests19 (19)https://github.com/python-telegram-bot/python-telegram-bot/pulls
Discussionshttps://github.com/python-telegram-bot/python-telegram-bot/discussions
Actionshttps://github.com/python-telegram-bot/python-telegram-bot/actions
Projectshttps://github.com/python-telegram-bot/python-telegram-bot/projects
Wikihttps://github.com/python-telegram-bot/python-telegram-bot/wiki
Security and qualityhttps://github.com/python-telegram-bot/python-telegram-bot/security
Insightshttps://github.com/python-telegram-bot/python-telegram-bot/insights
https://github.com/python-telegram-bot/python-telegram-bot
New issuehttps://github.com/login?return_to=https://github.com/python-telegram-bot/python-telegram-bot/issues/3018
New issuehttps://github.com/login?return_to=https://github.com/python-telegram-bot/python-telegram-bot/issues/3018
💡 featurehttps://github.com/python-telegram-bot/python-telegram-bot/issues?q=type:"💡 feature"
#3148https://github.com/python-telegram-bot/python-telegram-bot/pull/3148
New Mechanism for Avoiding Flood Limitshttps://github.com/python-telegram-bot/python-telegram-bot/issues/3018#top
#3148https://github.com/python-telegram-bot/python-telegram-bot/pull/3148
v20.0a3https://github.com/python-telegram-bot/python-telegram-bot/milestone/35
https://github.com/Bibo-Joshi
Bibo-Joshihttps://github.com/Bibo-Joshi
on May 9, 2022https://github.com/python-telegram-bot/python-telegram-bot/issues/3018#issue-1230125532
#2139https://github.com/python-telegram-bot/python-telegram-bot/issues/2139
Bibo-Joshihttps://github.com/Bibo-Joshi
enhancementhttps://github.com/python-telegram-bot/python-telegram-bot/issues?q=state%3Aopen%20label%3A%22enhancement%22
on May 9, 2022https://github.com/python-telegram-bot/python-telegram-bot/issues/3018#event-6575555980
Bibo-Joshihttps://github.com/Bibo-Joshi
v20.0a1https://github.com/python-telegram-bot/python-telegram-bot/milestone/33
on May 9, 2022https://github.com/python-telegram-bot/python-telegram-bot/issues/3018#event-6575555993
https://github.com/Bibo-Joshi
Bibo-Joshihttps://github.com/Bibo-Joshi
on Jun 1, 2022https://github.com/python-telegram-bot/python-telegram-bot/issues/3018#issuecomment-1144022327
@harshil21https://github.com/harshil21
https://github.com/harshil21
harshil21https://github.com/harshil21
on Jun 1, 2022https://github.com/python-telegram-bot/python-telegram-bot/issues/3018#issuecomment-1144030359
mjpieters/aiolimiter#73https://github.com/mjpieters/aiolimiter/issues/73
getcoroutinelocalshttps://docs.python.org/3/library/inspect.html#inspect.getcoroutinelocals
https://github.com/Bibo-Joshi
Bibo-Joshihttps://github.com/Bibo-Joshi
on Jun 1, 2022https://github.com/python-telegram-bot/python-telegram-bot/issues/3018#issuecomment-1144034035
getcoroutinelocalshttps://docs.python.org/3/library/inspect.html#inspect.getcoroutinelocals
https://github.com/harshil21
harshil21https://github.com/harshil21
on Jun 1, 2022https://github.com/python-telegram-bot/python-telegram-bot/issues/3018#issuecomment-1144040132
Bibo-Joshihttps://github.com/Bibo-Joshi
v20.0a1https://github.com/python-telegram-bot/python-telegram-bot/milestone/33
v20.0a2https://github.com/python-telegram-bot/python-telegram-bot/milestone/35
on Jun 8, 2022https://github.com/python-telegram-bot/python-telegram-bot/issues/3018#event-6772906305
Bibo-Joshihttps://github.com/Bibo-Joshi
completedhttps://github.com/python-telegram-bot/python-telegram-bot/issues?q=is%3Aissue%20state%3Aclosed%20archived%3Afalse%20reason%3Acompleted
#3148https://github.com/python-telegram-bot/python-telegram-bot/pull/3148
on Aug 26, 2022https://github.com/python-telegram-bot/python-telegram-bot/issues/3018#event-7264560165
github-actionshttps://github.com/apps/github-actions
on Sep 2, 2022https://github.com/python-telegram-bot/python-telegram-bot/issues/3018#event-7314926893
Bibo-Joshihttps://github.com/Bibo-Joshi
enhancementhttps://github.com/python-telegram-bot/python-telegram-bot/issues?q=state%3Aopen%20label%3A%22enhancement%22
on Nov 4, 2024https://github.com/python-telegram-bot/python-telegram-bot/issues/3018#event-15107743149
Sign up for freehttps://github.com/signup?return_to=https://github.com/python-telegram-bot/python-telegram-bot/issues/3018
Sign in to commenthttps://github.com/login?return_to=https://github.com/python-telegram-bot/python-telegram-bot/issues/3018
💡 featurehttps://github.com/python-telegram-bot/python-telegram-bot/issues?q=type:"💡 feature"
v20.0a3https://github.com/python-telegram-bot/python-telegram-bot/milestone/35
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.