On 7/2/17 3:11 PM, Daniel wrote:

Hi there,

I am new with vibe.d and D-lang. I've written a program to execute x set
commands in Redis but the performance is really bad for 1M or more
commands.
Maybe I am doing something silly and at the moment I am not aware of another
way to do it better. It seems it is not running asynchronous, I have tried
using the configuration for libevent and libasync but the performance was pretty much the same. Maybe there is something
wrong in the way I set the task?
Any suggestion will be appreciated. Thanks in advance.

The program

module app;

import vibe.core.core;
import vibe.core.log;
import vibe.db.redis.redis;
import std.exception : assertThrown;
import std.conv;
import std.format;
import std.getopt;

void runTest (ulong num_records)
{
     logInfo("Test starting");

	RedisClient redis;
	try redis = new RedisClient();
	catch (Exception) {
		logInfo("Failed to connect to local Redis server.");
		return;
	}

     auto task = {
         foreach (i; 0..num_records)
         {
             redis.getDatabase(0).set("Key%d".format(i), "Value%d".format(i));
         }
     };
     
     auto t1 = runTask(task);
     t1.join();

	logInfo("Test finished.");
}

int main (string[] args)
{
     auto num_records = 1_000_000UL;

     getopt(args, "records|n", &num_records);

	int ret = 0;
	runTask({
		try runTest(num_records);
		catch (Throwable th)
         {
			logError("Test failed: %s", th.msg);
			logDiagnostic("Full error: %s", th);
			ret = 1;
		}
         finally exitEventLoop(true);
	});
	runEventLoop();

	return ret;
}

This is how I run it:

$ /usr/bin/time -v -p sh -c 'dub run bulktest -b release'

Hi Daniel, I would recommend, even though it probably doesn't make a
huge difference, not to use dub to run the executable for a test, since
it does a lot of extra work besides running the exe. Just do ./bulktest.

As for why redis is slow, not a clue. I'm using it in my vibe.d project
for session management, but haven't concerned myself with performance
(yet). I'd say it's likely something to do with i/o performance.

Version of the compiler: DMD64 D Compiler v2.071.2

Note, 2.075 is about to be released, so you may want to upgrade. This
version is quite old.

-Steve