Skip to content

Global Rate Limit ​

The global rate limit config is a queue option that determines how many jobs are allowed to be processed in a specific period of time.

typescript
import { Queue } from 'bullmq';

// 1 job per second
await queue.setGlobalRateLimit(1, 1000);
python
from bullmq import Queue

# 1 job per second
await queue.setGlobalRateLimit(1, 1000)
rust
use bullmq::Queue;

// 1 job per second
queue.set_global_rate_limit(1, 1000).await?;

In order to get these values:

typescript
const { max, duration } = await queue.getGlobalRateLimit();
python
rate_limit = await queue.getGlobalRateLimit()
max_jobs, duration = rate_limit["max"], rate_limit["duration"]
elixir
{:ok, %{max: max, duration: duration}} =
  BullMQ.Queue.get_global_rate_limit("my-queue", connection: :my_redis)
rust
if let Some((max, duration)) = queue.get_global_rate_limit().await? {
    println!("{max} jobs every {duration} ms");
}

And in order to get current ttl:

typescript
const ttl = await queue.getRateLimitTtl();
python
ttl = await queue.getRateLimitTtl()
elixir
{:ok, ttl} = BullMQ.Queue.get_rate_limit_ttl("my-queue", connection: :my_redis)
csharp
long ttl = await queue.GetRateLimitTtlAsync();
rust
let ttl = queue.get_rate_limit_ttl(None).await?;
php
<?php

$ttl = $queue->getRateLimitTtl();

INFO

Note that if you choose a rate limit level in your workers, it won't override the global one.

Remove Global Rate Limit ​

It can be done using the following method:

typescript
await queue.removeGlobalRateLimit();
python
await queue.removeGlobalRateLimit()
rust
queue.remove_global_rate_limit().await?;

Read more: ​

Released under the MIT License.