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'
Building package bulktest in /home/daniz/projects/vibe.d/tests/myredis/
Performing "release" build using dmd for x86_64.
diet-ng 1.2.1: target for configuration "library" is up to date.
vibe-d:utils 0.8.0-rc.3+commit.2.ge84c45dd: target for configuration "library" is up to date.
vibe-d:data 0.8.0-rc.3+commit.2.ge84c45dd: target for configuration "library" is up to date.
vibe-d:core 0.8.0-rc.3+commit.2.ge84c45dd: target for configuration "libevent" is up to date.
vibe-d:crypto 0.8.0-rc.3+commit.2.ge84c45dd: target for configuration "library" is up to date.
vibe-d:stream 0.8.0-rc.3+commit.2.ge84c45dd: target for configuration "generic" is up to date.
vibe-d:textfilter 0.8.0-rc.3+commit.2.ge84c45dd: target for configuration "library" is up to date.
vibe-d:diet 0.8.0-rc.3+commit.2.ge84c45dd: target for configuration "library" is up to date.
vibe-d:inet 0.8.0-rc.3+commit.2.ge84c45dd: target for configuration "library" is up to date.
vibe-d:http 0.8.0-rc.3+commit.2.ge84c45dd: target for configuration "library" is up to date.
vibe-d:redis 0.8.0-rc.3+commit.2.ge84c45dd: target for configuration "library" is up to date.
bulktest ~master: target for configuration "application" is up to date.
To force a rebuild of up-to-date targets, run again with --force.
Running ./bulktest
Test starting
Test finished.
Command being timed: "sh -c dub run bulktest -b release"
User time (seconds): 15.77
System time (seconds): 14.18
Percent of CPU this job got: 73%
Elapsed (wall clock) time (h:mm:ss or m:ss): 0:40.99
Average shared text size (kbytes): 0
Average unshared data size (kbytes): 0
Average stack size (kbytes): 0
Average total size (kbytes): 0
Maximum resident set size (kbytes): 14564
Average resident set size (kbytes): 0
Major (requiring I/O) page faults: 0
Minor (reclaiming a frame) page faults: 3410
Voluntary context switches: 999775
Involuntary context switches: 1247
Swaps: 0
File system inputs: 0
File system outputs: 8
Socket messages sent: 0
Socket messages received: 0
Signals delivered: 0
Page size (bytes): 4096
Exit status: 0
Version of the compiler: DMD64 D Compiler v2.071.2
OS: Ubuntu Linux 16.04