RejectedSoftware Forums

Sign up

Question about vibe's connection pool

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
		}
	);
}

Re: Question about vibe's connection pool

On Sat, 13 Dec 2014 20:27:39 GMT, Lemonfiend wrote:

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?

Currently, the connection pool will create as many connections as necessary to treat the amount of simultaneous requests. There's at most 16 peers that may be kept alive through connection pools.

So, while you can work around this using the "doBatchedChunked" method, the right thing to do is add a few settings into HTTPClient and ConnectionPool. What would be necessary is a raw TCP timeout, and a maximum concurrent connections setting. This is best implemented in the existing HTTPClientSettings object, and also through constructor arguments for the ConnectionPool settings.

Re: Question about vibe's connection pool

On Sun 14 Dec 03:18, Etienne Cimon wrote:

On Sat, 13 Dec 2014 20:27:39 GMT, Lemonfiend wrote:

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?

Currently, the connection pool will create as many connections as necessary to treat the amount of simultaneous requests. There's at most 16 peers that may be kept alive through connection pools.

A max of 16 peers? What does this mean exactly for a vibe app?

So, while you can work around this using the "doBatchedChunked" method, the right thing to do is add a few settings into HTTPClient and ConnectionPool. What would be necessary is a raw TCP timeout, and a maximum concurrent connections setting. This is best implemented in the existing HTTPClientSettings object, and also through constructor arguments for the ConnectionPool settings.

You mean that this would need to be implemented in vibe.d first?
So for now I guess I'll use the chunk method, as I don't feel
comfortable changing vibe's code.