Simple web server benchmark - vibe.d is slower than node.js and Go?

bitwise bitwise.pvt at gmail.com
Thu Sep 21 19:40:48 UTC 2017


On Thursday, 21 September 2017 at 18:55:04 UTC, Vadim Lopatin 
wrote:
> On Thursday, 21 September 2017 at 18:49:00 UTC, bitwise wrote:
>> On Thursday, 21 September 2017 at 08:01:23 UTC, Vadim Lopatin 
>> wrote:
>>> [...]
>>
>> Doesn't vibe-d use Fibers?
>>
>> I tried to build a simple web server with a fiber-based 
>> approach once - it was horribly slow.
>>
>> I hope C# (and soon C++) style stackless resumable functions 
>> will eventually come to D.
>
> It does. But Golang uses them, too. Goroutines.

Indeed. I'm reading about them right now, and they seem to be 
"multiplexed". I wonder if Vibe.d does something similar.

The fact that you've observed lower CPU usage by the D version 
makes me think some kind of scheduling or thread-priority issue 
is the cause.

For example, on windows, the default timer frequency is very low. 
It would seem reasonable to get 1000 iterations per second in the 
example below, but you get ~64.

`
auto now = steady_clock::now();
auto done = now + milliseconds(10000);
int iterations = 0;

while(steady_clock::now() < done) {
     ++iterations;
     Sleep(1);
}

cout << (iterations / 10) << endl;
`

When I wrap the above code with timeBeginPeriod(1) and 
timeEndPeriod(1), I get ~550 on my machine.

IIRC, you get similar behavior on MacOS(maybe linux too?) unless 
you explicitly raise the thread priority.

https://msdn.microsoft.com/en-us/library/windows/desktop/dd757624(v=vs.85).aspx

So if you're benchmarking anything that sleeps regularly, like an 
event based framework, something like 
timeBeginPeriod/timeEndPeriod may help.




More information about the Digitalmars-d mailing list