I have to make thousands of connections to a server that isn't mine.
Is it necessary to do this in chunks, or does vibe do this internally?
Ie. Does vibe grow its connectionpool to a thousand if I call doBatch?
Or, is doBatchChunked a better approach?
void doBatch(int numRequests = 1000)
{
Task[numRequests] taskpool;
for(int i = 0; i < numRequests; i++)
{
taskpool[i] = runTask({
doRequest(i);
});
}
foreach(task; taskpool)
task.join();
// do other things
}
void doBatchChunked(int numRequests = 1000)
{
enum poolSize = 10;
Task[poolSize] taskpool;
int count;
while(count < numRequests)
{
int remaining = numRequests - count;
int batchSize = remaining < poolSize ? remaining : poolSize;
for(int i = 0; i < batchSize; i++)
{
taskpool[i] = runTask({
doRequest(count);
});
count++;
}
foreach(task; taskpool)
task.join();
}
// do other things
}
void doRequest(int id)
{
requestHTTP(`http://www.example.org`,
(scope request)
{
request.method = HTTPMethod.GET;
import std.conv: to;
request.requestURL = `/id=` ~ to!string(id);
},
(scope response)
{
auto json = response.readJson();
// do something with the json
}
);
}