limit the number of active tasks

Aug 20, 2014 at 5:45 AM
I need a way to limit the number of "activated" pplx::tasks, that is, the number that are actually running, whether using cycles or blocked. I generate hundreds or even thousands of HTTP request tasks at a time, but don't want to overwhelm the web server (and tick off its administrator) by sending them all at once. What the library apparently does is start a bunch of requests, then as they block for responses, reuse the threads in the pool to start more. I'd like a way to set a limit on the number of in-process requests at any one time.

I looked at concurrency::Scheduler, but it does not appear do offer any way to limit tasks. Is there any feature of the SDK that will do this? If not, any suggestions for the design of a home-grown limit?

Aug 26, 2014 at 10:31 PM
I solved this problem by having my task generator generate functions that start tasks instead of the tasks themselves. My consumer then can decide how many of these task-starting functions to run at a time and thus how many tasks are running at a time.

Aug 27, 2014 at 6:06 PM
Hi evan,

Yes that could be one solution. Part of the problem is when you initiate an HTTP request with our http_client, there isn't one task that represents and holds the whole operation. Depending on the API we build on we could quickly asynchronously initiate the request using API's asynchrony model. In the case of WinHTTP for example this is done through callbacks. This means new requests can be started up.

It would be possible there to be a throttling feature on the http_client itself, in the http_client_config perhaps. That would limit the number of active requests at one time. If this might be valuable you could open a feature request. The implementation probably would be doing something similar to what you are on top of the http_client.