this post was submitted on 16 Jan 2025
15 points (89.5% liked)

Rust

6282 readers
111 users here now

Welcome to the Rust community! This is a place to discuss about the Rust programming language.

Wormhole

[email protected]

Credits

  • The icon is a modified version of the official rust logo (changing the colors to a gradient and black background)

founded 2 years ago
MODERATORS
 

I've been coming back to the same project a few times. It's essentially just a program that interacts with an API. Only problem is whenever I get back to it, I realize how annoying it is to debug through all the "too many requests" responses I get back from the API because it has a max of 200 requests per second.

On solution would be to filter out those responses but that just feels like the wrong move, so I'm guessing the better solution would be to put some sort of rate limiter on my program. My two questions are: does that seem like a good solution and if it is, do I embed the rate limiter in my program, i.e. using the ratelimit crate or would a better solution be to run my program in a container and connect it to a reverse proxy(I think) container and control rate limiting from there?

you are viewing a single comment's thread
view the rest of the comments
[–] [email protected] 1 points 2 weeks ago* (last edited 2 weeks ago)

Dunno if its applicable to your rust http client but in python's aiohttp you can set maximum active (tcp) connections per host for the connection pool.
It does not ensure it won't ever go over the rate (especially if your requests are small) just does not let the program burst the server down. It's usually my first choice - dumb in the long run but quick and cheap.