mux-node-sdk icon indicating copy to clipboard operation
mux-node-sdk copied to clipboard

Queue based rate limiting under the hood

Open daymxn opened this issue 3 years ago • 2 comments

Something of the likes of axios-rate-limit that conforms to the 1rps sending & 5rps retrieval API limits of mux could be a great addition.

daymxn avatar Apr 22 '21 01:04 daymxn

Interesting idea, I can see how that would be valuable @NotDaymon

Are you using this SDK to write some long-running scripts?

dylanjha avatar Apr 22 '21 15:04 dylanjha

Interesting idea, I can see how that would be valuable @NotDaymon

Are you using this SDK to write some long-running scripts?

Essentially, yeah. I'm working on a streaming service for a client, and I'm utilizing mux to offload a lot of the load. I keep as much data as I can within our own local databases, so the API limits aren't too much of an issue currently. But with 1rps sending, its fairly likely I can have a situation in which two end-user moderators create assets at the same time.

Instead of creating a new instance of Mux every time I want to play with the API, I currently have a constant instance that's "shared" across resources. So they import the shared instance, and utilize that instead. This way, I can facilitate rate limits within Mux and axios directly, instead of having to modify all my Mux references to instead be queue based calls for a custom object or alternative library. I'm using axios-rate-limit over the axios instance in Mux currently. But I intend to switch that out for a more optimal solution in the future, such as heapify. And if we were looking to do that here, I would recommend that as well- for performance sake.

daymxn avatar Apr 22 '21 19:04 daymxn

We're considering this kind of functionality out of scope for an SDK like this that wraps the API endpoints. It's probably better implemented with the help of an external library (like heapify, the one linked). There's a number of utilities that can do this sort of thing.

dylanjha avatar Feb 12 '24 20:02 dylanjha