This Ada program demonstrates rate limiting, which is an important mechanism for controlling resource utilization and maintaining quality of service. Ada supports rate limiting through tasks, protected objects, and timing events.
First, we look at basic rate limiting. We create a queue of requests and process them at a rate of one request every 200 milliseconds.
Then, we implement a bursty rate limiter. This allows short bursts of requests while preserving the overall rate limit. The Bursty_Limiter task allows bursts of up to 3 events, refilling one token every 200 milliseconds.
To run the program, save it as rate_limiting.adb and use the following commands:
Running the program, you’ll see the first batch of requests handled once every ~200 milliseconds as desired. For the second batch of requests, you’ll see the first 3 served immediately because of the burstable rate limiting, then the remaining 2 with ~200ms delays each.
This example demonstrates how Ada can be used to implement rate limiting schemes, providing control over resource usage in concurrent systems.