I need to send requests to REST API endpoint, but there is a limit (imposed by the API) - I cannot send more than 10 MB/s.
Every request has a fixed size (let's assume 1 MB for simplicity).
I could create a collection of 10 requests and wait until all of them are finished, and if less than second passed, I would wait before sending another round of requests.
This would be fine, and I found this question that deals with this problem.
However, I am not limited by number of calls per second, but rather by data per second!
This means that if some of the requests are not yet finished, they might be still sending the data. This means that I would have to wait for all the requests to finish in order to start another round.
Edge case scenario might be 1 request that takes long time (e.g. 5 seconds), whereas all other took 0.9 second. I could start another round of 9 requests while the 5 seconds request takes its time to finish!
Unfortunately, all of the solutions that I found focus on either limiting data (but for streams) or amount of requests, but not both.
How can I ensure that I only use 10 MB/s when sending http requests, but don't get blocked by some requests that take longer than others to finish?