On Wed, 12 Oct 2016 15:51:31 GMT, JFaianca wrote:

Having to do 3 requests, d how can i do them parallel?

auto category = redis.getDatabase().send("HGETALL category:1");
auto user = redis.getDatabase().send("HGETALL user:1");
auto test = redis.getDatabase().send("HGETALL test:3");

I tried, with async from vibe.core.concurrency, but i got less performance.
Tried with .parallel but it crash's since the threads gets messed up.

How are you guys doing parallel requests? Like promises all.

Ex javascript promises.

Promise.all([p1, p2, p3]).then(values => { 
  console.log(values); // [3, 1337, "foo"] 
});

It would be interesting to see why async made it slower. Generally, any kind of parallelism will introduce some ampunt of overhead, so a slightly worse overall performance should be expected - except for cluster configurations. The latency of a single request on the other hand should ideally improve as long as there is any network latency involved.

For vibe.d, the canonical tool would be runTask:

Response category, user, test;
auto t1 = runTask({ category = redis.getDatabase().send("HGETALL category:1"); });
auto t2 = runTask({ user = redis.getDatabase().send("HGETALL user:1"); });
auto t3 = runTask({ test = redis.getDatabase().send("HGETALL test:3"); });
t1.join();
t2.join();
t3.join();

async should result in more or less the same operations, but has some overhead because it needs to do a dynamic memory allocation. Would be interesting to implement a scoped variant of this to avoid that. But if the above version is also considerably slower (in terms of throughput), I can try to investigate further.

A vibe.core.concurrency.parallel() function could also be handy (this could also avoid the creation of a heap delegate by guaranteeing that the delegate doesn't leave the function scope):

Response category, user, test;
parallel(
  { category = redis.getDatabase().send("HGETALL category:1"); },
  { user = redis.getDatabase().send("HGETALL user:1"); },
  { test = redis.getDatabase().send("HGETALL test:3"); }
);