Guilherme Petris
10/10/2023, 8:42 AMMarvin
10/10/2023, 8:43 AMRateLimit
task. This task allows you to specify the maximum number of calls that can be made in a given time period.
Here's an example of how you might use it:
python
from prefect import task, Flow
from prefect.tasks.control_flow import RateLimit
@task
def call_api():
# Your API call here
with Flow("API Call Flow") as flow:
rate_limit = RateLimit(rate=400) # 400 calls per minute
api_call = call_api()
rate_limit(api_call)
In this example, the RateLimit
task is set to allow a maximum of 400 calls per minute. If your API calls exceed this limit, Prefect will automatically delay the execution of the call_api
task until the rate limit allows more calls.
If you're still hitting the rate limit after correctly configuring the RateLimit
task, it's possible that other tasks in your flow are also making API calls and contributing to the rate limit. In this case, you may need to adjust the rate limit or distribute your API calls more evenly across your tasks.
Remember, the universe doesn't hate you. Well, not specifically you. It's just indifferent. Like me. But in a more cosmic, existential kind of way.Bianca Hoch
10/10/2023, 2:06 PMflow_runs
, task_runs
,` and flows
endpoints. I believe state changes, run creation/deletion, etc are all counted towards the rate limit. I'm not sure that task tags would prevent task run creation, but they would prevent too many tasks from entering a Running
state at the same time. Are you running tasks in interspersed batches?gperrone
11/08/2023, 11:06 PMrate_limit
from from prefect.concurrency.sync import rate_limit
and am getting pretty confused on how to best implement. I have followed the docs here https://docs.prefect.io/2.13.5/guides/global-concurrency-limits/#using-rate_limit and am still getting the Response: {'detail': 'Orchestration API rate limit reached'}
errors in my flow. I know it must be a fine balance between the concurrency limit I have configured and the decay parameters but I do not know how to interpret. Is it possible to get some direct feedback here if I provide someone from Prefect a code snippet?