Rate limiting
AIStore rate-limits traffic at two layers: frontend (client-facing) and backend (cloud-facing). It paces requests to stay within limits, and backs off and retries when limits are encountered anyway — all configurable at both the cluster and bucket levels, with zero performance overhead when disabled.
Rate limiting was introduced in v3.28; v5.3 added the on-demand backend mode (see Backend Activation Modes).
This text explains how it all fits together.
Table of Contents
- Background
- Elements
- Configuration
- Unified Rate-Limiting Logic
- Handling Batch Jobs
- Use Cases
- Monitoring and Troubleshooting
- Recap
1. Background
The original motivation was to gracefully handle rate-limited cloud storage such as Amazon S3, Google Cloud Storage (GCS), and other remote backends.
One common misconception is that integrating with systems that impose their own rate constraints boils down to simply retrying failed requests with exponential backoff.
Not true! In reality, such integrations are always a balancing act: the goal is to minimize retries while running at the maximum allowed speed - which further requires configuration, runtime state, and a few more elements explained below.
2. Elements
2.1 Pacing and Retries
Pacing keeps requests within permitted throughput before hitting any system-imposed limits—cloud or otherwise. By governing the flow of requests in real time, we reduce the need for retries.
Retries come into play when the external service or remote storage actually enforces a limit (returning 429 or 503).
When that happens, we respond with adaptive backoff and retry logic - but only if the corresponding bucket has its backend rate limiter configured: bucket-configured (enabled) or on-demand (on_demand); see Backend Activation Modes. This gives us a self-adjusting mechanism that converges on the maximum permissible speed with minimal overhead.
2.2 Frontend vs. Backend
“AIStore has a unique dual identity: it acts as reliable distributed storage (managing local and remote buckets) while also serving as a fast tiering layer for other systems.”
-
Bursty (Frontend)
- Frontend rate limiting is provided by each AIS proxy (or gateway).
- The system allows short-term spikes but enforces an overall maximum request rate.
- When clients exceed the allowed rate, they receive HTTP
429immediately.
-
Adaptive or Shaping (Backend)
- Backend rate limiting is handled by each AIS target node.
- There’s a stateful rate-limiter instance on a per
(bucket, verb)basis, where the verbs are:GET,PUT, andDELETE. - This logic dynamically adjusts request rates based on current usage and responses from the remote service.
- If a remote backend returns
429or503, AIS target may engage exponential backoff to stay under the cloud provider’s limits.
3. Configuration
Rate limiting is configured per bucket, with inheritable defaults set at the cluster level. Buckets automatically inherit the global settings, but each bucket can override them at creation time or any point thereafter. For reference, see RateLimitConf in cmn/config.go.
This includes:
- Rate-Limit Policies: Separate policies for frontend (bursty) and backend (adaptive or shaping) rate limiting.
- Performance Requirement: If rate limiting is not enabled for a particular bucket or cluster, there should be no performance penalty.
- Proportional Distribution:
- On the front, each AIS proxy assumes it handles
1 / napshare of incoming requests, wherenapis the current number of active proxies in the cluster. - On the back, each target node assumes it is one of
nattargets accessing the same remote bucket in parallel, and computes its share accordingly.
- On the front, each AIS proxy assumes it handles
For a given bucket, configuration may look as follows:
3.1 Configuration: Summary Table
Cluster defaults apply to newly created buckets, while existing buckets retain their properties and can be configured independently.
4. Unified Rate-Limiting Logic
Although frontend and backend differ in their specific mechanisms (bursty vs. shaping), the underlying logic is unified:
-
Frontend: Each proxy enforces a configurable rate limit on a per-bucket and per-operation (verb) basis.
-
Backend: Each target enforces the configured limit for outbound calls. This is wrapped by a dedicated
ais/rlbackendlayer that shapes traffic to remote AIS clusters or external clouds (e.g., S3, GCS).
Backend Activation Modes
The backend limiter runs in one of two mutually exclusive modes:
- Once active, both modes pace requests and retry rate-limit errors using the bucket’s
max_tokens,interval, andnum_retries. - An explicitly enabled (bucket-configured) limiter takes precedence: setting both
enabledandon_demandtotruefails, in cluster configuration and bucket properties alike. - The check applies to the resulting (merged) configuration: for instance, setting
on_demand=trueon a bucket that already hasenabled=truefails as well. - On-demand activation is one-way: once activated, the limiter keeps pacing, while its learned rate recovers gradually as the remote stops throttling.
- Switching
on_demandoff and back on does not reset the learned rate; a limiter that stays idle for several hours is discarded.
Here’s a simplified snippet of bucket-configured logic (enabled=true) with (4) inline comments:
- Lazy Pruning: Over time, not all buckets remain active, so the system utilizes common housekeeping mechanism to lazily prune stale rate-limiter instances.
Backend Retry Waits
Once active, rlbackend acquires a token once before each operation. After a backend 429 or 503, retries use backoff without acquiring additional tokens; errors still contribute to the shared limiter’s error statistics.
- Each wait starts from the larger of the previous retry sleep and the current token-derived interval.
- The error percentage determines the multiplier: 2x at 30% or below, 4x above 30%, and 8x above 50%. With fewer than three recorded requests, the multiplier is 2x.
- Before jitter, each sleep is capped at the larger of 6 seconds (
DfltRateMaxWait / DfltRateMaxRetries) and the current token-derived interval. Retries remain bounded bynum_retries(at most 10) and a one-minute retry-sleep budget. - Each wait applies approximately +/-3% jitter after capping, so it can slightly exceed that base cap, but never falls below the token-derived interval. The resulting sleep is carried forward to the next retry.
- The previous sleep belongs only to the current operation. A later operation starts without that accumulated delay.
Ignoring jitter, for one isolated operation with a fresh limiter, a 10ms base interval, and every attempt returning 429, ten retries sleep for 20ms, 40ms, 80ms, 160ms, 320ms, 640ms, 1.28s, 2.56s, 5.12s, 6s (16.22s total). A successful retry or a non-rate-limit error ends the retry loop.
5. Handling Batch Jobs
AIStore supports numerous batch jobs that read and transform data across buckets. For example, a job might read data from one bucket, apply a user-defined transformation, and then write the results to another bucket. Multiple rate-limiting scenarios can arise:
- Source Bucket:
- May or may not be rate-limited.
- Could be limited on the frontend, the backend, or both.
- Destination Bucket:
- Could also have its own rate-limiting policies.
- Might be a remote system with enforced limits (e.g., writing to an S3 bucket).
At first, the permutations may seem too numerous, but in reality it is easy to state a single rule:
- Frontend rate-limiting is enforced by a given running job and is conjunctive (source and/or destination wise). When both limits are defined one of them will most likely “absorb” the other.
- Backend is controlled by the corresponding
(bucket, verb)rate limiter that keeps adjusting its runtime state based on the responses from remote storage. The same limiter serves client requests and all jobs, in either mode (see Backend Activation Modes).
Remote LIST pagination in prefix-based prefetch, copy/transform, archive, and evict/delete jobs follows this same bucket policy. Configure rate_limit.backend.on_demand=true for pacing only after a rate-limit error, or rate_limit.backend.enabled=true for pacing from the start. rlbackend owns the retry budget and backoff.
With both settings false, a backend LIST error propagates to the job without an AIS retry. The initial backend call’s normal SDK retry policy is unchanged; SDK retries are disabled on calls retried by rlbackend.
6. Use Cases
6.1 Handling Backend-Imposed Limits
Scenario: You have an S3 bucket with a known rate limit of 3500 requests per second.
Configuration:
6.2 Limiting User Traffic
“You want to limit the maximum number of client requests to a specific bucket to 20,000 per minute. Further, the cluster in question happens to have 10 AIS gateways (and a load balancer on the front).”
Configuration:
This configures a given bucket to:
- Limit client requests to 20,000 per minute (notice that 2000 * 10 = 20,000).
- Allow short bursts up to 100 additional requests.
- Return status
429(“Too Many Requests”) if clients exceed these limits.
6.3 Limiting User Traffic: Example aisloader run
And then:
6.4 Combined Frontend/Backend Limiting for Cross-Cloud Transfer
Scenario: You are migrating or copying data from GCS to S3 and need to respect both providers’ limits.
Configuration:
When running a copy or transform job between these buckets, AIStore automatically respects both rate limits without (requiring) any additional configuration.
7. Monitoring and Troubleshooting
There are statistics and Prometheus metrics to monitor all performance-related aspects including (but not limited to) rate-limiting.
Below are two tables - one for GET, another for PUT - that illustrate how the performance monitoring might look for an AIStore cluster under the described rate-limited scenario.
GET Performance Table
- AWS-GET(n) / AWS-GET(t): Number and average latency of GET requests that actually hit the AWS backend.
- GET(n) / GET(t): Number and average latency of all GET requests (including those served from local cache or in-cluster data).
- GET(total/avg size): Approximate total data read and corresponding average object size.
- RATELIM-RETRY-GET(n) / RATELIM-RETRY-GET(t): Number and average latency of GET requests retried due to hitting the rate limit.
PUT Performance Table
- GCP-PUT(n) / GCP-PUT(t): Number and average latency of PUT requests that actually went to Google Cloud Storage.
- PUT(n) / PUT(t): Number and average latency of all PUT requests processed.
- PUT(total/avg size): Approximate total data written and the corresponding average object size.
- RATELIM-RETRY-PUT(n) / RATELIM-RETRY-PUT(t): Number and average latency of PUT requests retried due to rate limiting on the destination bucket.
These tables can vary widely, primarily depending on the percentage of source data that is in-cluster, but also on:
- Rate-limit settings for both the source (AWS) and the destination (GCP).
- Total number of disks in the cluster.
- Object sizes, current workload from other running jobs, available network bandwidth, etc.
In practice, you’d adjust the rate-limit interval and max_tokens (and potentially other AIStore config parameters) to match your workload and performance requirements.
Quick Troubleshooting Summary
8. Recap
The objective is to maintain linear scalability and high performance while safeguarding against external throttling or internal overload.
The solution features:
- Bursty (frontend) and adaptive (backend) rate limiters configurable on a per-bucket basis.
- Pacing, to keep runtime errors and retries to a minimum.
- Adaptive backoff and retries, to gracefully handle 429s and 503s from remote storages.