www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Benchmark Dlang vs Node vs Ruby

reply llaine <darksioul yopmail.com> writes:
Hi guys,

In my journey of learning about D I tried to benchmark D with 
Vibe.d vs node with express and Ruby with Sinatra.

And the results are pretty surprising.
I have to admit that I though D was more faster than that. How is 
this even possible ?

I am doing something wrong ?


Here are the numbers with the project :

https://github.com/llaine/benchmarks/blob/master/README.md
May 27 2016
next sibling parent reply Vadim Lopatin <coolreader.org gmail.com> writes:
On Friday, 27 May 2016 at 13:45:23 UTC, llaine wrote:
 Hi guys,

 In my journey of learning about D I tried to benchmark D with 
 Vibe.d vs node with express and Ruby with Sinatra.

 And the results are pretty surprising.
 I have to admit that I though D was more faster than that. How 
 is this even possible ?

 I am doing something wrong ?


 Here are the numbers with the project :

 https://github.com/llaine/benchmarks/blob/master/README.md
Probably node and Ruby cache PGSQL connection - keeping it open.
May 27 2016
next sibling parent llaine <darksioul yopmail.com> writes:
On Friday, 27 May 2016 at 13:54:20 UTC, Vadim Lopatin wrote:
 On Friday, 27 May 2016 at 13:45:23 UTC, llaine wrote:
 Hi guys,

 In my journey of learning about D I tried to benchmark D with 
 Vibe.d vs node with express and Ruby with Sinatra.

 And the results are pretty surprising.
 I have to admit that I though D was more faster than that. How 
 is this even possible ?

 I am doing something wrong ?


 Here are the numbers with the project :

 https://github.com/llaine/benchmarks/blob/master/README.md
Probably node and Ruby cache PGSQL connection - keeping it open.
How I'm suppose to do it ?
May 27 2016
prev sibling parent llaine <darksioul yopmail.com> writes:
On Friday, 27 May 2016 at 13:54:20 UTC, Vadim Lopatin wrote:
 On Friday, 27 May 2016 at 13:45:23 UTC, llaine wrote:
 Hi guys,

 In my journey of learning about D I tried to benchmark D with 
 Vibe.d vs node with express and Ruby with Sinatra.

 And the results are pretty surprising.
 I have to admit that I though D was more faster than that. How 
 is this even possible ?

 I am doing something wrong ?


 Here are the numbers with the project :

 https://github.com/llaine/benchmarks/blob/master/README.md
Probably node and Ruby cache PGSQL connection - keeping it open.
Okay I'll manage to do it, but still the req/sec are pretty low ...
May 27 2016
prev sibling next sibling parent bob belcher <claudiu.garba gmail.com> writes:
On Friday, 27 May 2016 at 13:45:23 UTC, llaine wrote:
 Hi guys,

 In my journey of learning about D I tried to benchmark D with 
 Vibe.d vs node with express and Ruby with Sinatra.

 And the results are pretty surprising.
 I have to admit that I though D was more faster than that. How 
 is this even possible ?

 I am doing something wrong ?


 Here are the numbers with the project :

 https://github.com/llaine/benchmarks/blob/master/README.md
You should know: https://www.techempower.com/benchmarks/#section=data-r12&hw=peak&test=json&l=ft4 Dlang is quite slow. I have no idea way, or how to improve it. But clear, is not that fast. Maybe for web related is slow. I'm more curious about more benchmarks :)
May 27 2016
prev sibling next sibling parent Adam D. Ruppe <destructionator gmail.com> writes:
oooh, I wanna try my libs.

Where's your database dump?
May 27 2016
prev sibling next sibling parent yazd <email email.com> writes:
On Friday, 27 May 2016 at 13:45:23 UTC, llaine wrote:
 Hi guys,

 In my journey of learning about D I tried to benchmark D with 
 Vibe.d vs node with express and Ruby with Sinatra.

 And the results are pretty surprising.
 I have to admit that I though D was more faster than that. How 
 is this even possible ?

 I am doing something wrong ?


 Here are the numbers with the project :

 https://github.com/llaine/benchmarks/blob/master/README.md
The postgres library (dpq) that you're using doesn't use the event loop that vibe-d provides. Every call you are doing is blocking the whole server. Of course this is going to be slow. You can try using http://code.dlang.org/packages/vibe-d-postgresql.
May 27 2016
prev sibling next sibling parent reply Adam D. Ruppe <destructionator gmail.com> writes:
On Friday, 27 May 2016 at 13:45:23 UTC, llaine wrote:
 I am doing something wrong ?
So, the benchmark, the Ruby, and the JS all use the path to be /.... the D seems to use /companies (though I don't know vibe). Is that right?
May 27 2016
next sibling parent reply llaine <darksioul yopmail.com> writes:
On Friday, 27 May 2016 at 14:17:16 UTC, Adam D. Ruppe wrote:
 On Friday, 27 May 2016 at 13:45:23 UTC, llaine wrote:
 I am doing something wrong ?
So, the benchmark, the Ruby, and the JS all use the path to be /.... the D seems to use /companies (though I don't know vibe). Is that right?
Yes it's that i'm routing to /companies to get the result, but let me change the psql library delete this routing and trying again.
May 27 2016
parent reply Daniel Kozak <kozzi11 gmail.com> writes:
On Friday, 27 May 2016 at 14:18:31 UTC, llaine wrote:
 On Friday, 27 May 2016 at 14:17:16 UTC, Adam D. Ruppe wrote:
 On Friday, 27 May 2016 at 13:45:23 UTC, llaine wrote:
 I am doing something wrong ?
So, the benchmark, the Ruby, and the JS all use the path to be /.... the D seems to use /companies (though I don't know vibe). Is that right?
Yes it's that i'm routing to /companies to get the result, but let me change the psql library delete this routing and trying again.
Yous should enable http://vibed.org/api/vibe.http.server/HTTPServerOption.distribute something like this: auto settings = new HTTPServerSettings; settings.port = 8080; settings.options |= HTTPServerOption.distribute; listenHTTP(settings, router);
May 27 2016
parent llaine <darksioul yopmail.com> writes:
On Friday, 27 May 2016 at 14:48:19 UTC, Daniel Kozak wrote:
 On Friday, 27 May 2016 at 14:18:31 UTC, llaine wrote:
 On Friday, 27 May 2016 at 14:17:16 UTC, Adam D. Ruppe wrote:
 On Friday, 27 May 2016 at 13:45:23 UTC, llaine wrote:
 I am doing something wrong ?
So, the benchmark, the Ruby, and the JS all use the path to be /.... the D seems to use /companies (though I don't know vibe). Is that right?
Yes it's that i'm routing to /companies to get the result, but let me change the psql library delete this routing and trying again.
Yous should enable http://vibed.org/api/vibe.http.server/HTTPServerOption.distribute something like this: auto settings = new HTTPServerSettings; settings.port = 8080; settings.options |= HTTPServerOption.distribute; listenHTTP(settings, router);
Hi, With this option I get the same results but something interesting is displayed on the binary output : core.exception.InvalidMemoryOperationError src/core/exception.d(693): Invalid memory operation The code : https://github.com/llaine/benchmarks/blob/master/vibed/source/app.d
May 27 2016
prev sibling parent reply llaine <darksioul yopmail.com> writes:
On Friday, 27 May 2016 at 14:17:16 UTC, Adam D. Ruppe wrote:
 On Friday, 27 May 2016 at 13:45:23 UTC, llaine wrote:
 I am doing something wrong ?
So, the benchmark, the Ruby, and the JS all use the path to be /.... the D seems to use /companies (though I don't know vibe). Is that right?
All right after switching of psql client I had lower results actually ... Req/Sec 22.85 for 30 seconds. What are you using to do web if you don't user Vibe.d?
May 27 2016
next sibling parent reply yazd <email email.com> writes:
On Friday, 27 May 2016 at 14:46:47 UTC, llaine wrote:
 On Friday, 27 May 2016 at 14:17:16 UTC, Adam D. Ruppe wrote:
 On Friday, 27 May 2016 at 13:45:23 UTC, llaine wrote:
 I am doing something wrong ?
So, the benchmark, the Ruby, and the JS all use the path to be /.... the D seems to use /companies (though I don't know vibe). Is that right?
All right after switching of psql client I had lower results actually ... Req/Sec 22.85 for 30 seconds. What are you using to do web if you don't user Vibe.d?
Your code is not doing the same thing in the benchmarks. In D, you are appending 10000 companies on every request, resulting in 10000, 20000, 30000, .... companies in subsequent requests.
May 27 2016
parent reply llaine <darksioul yopmail.com> writes:
On Friday, 27 May 2016 at 14:59:44 UTC, yazd wrote:
 On Friday, 27 May 2016 at 14:46:47 UTC, llaine wrote:
 On Friday, 27 May 2016 at 14:17:16 UTC, Adam D. Ruppe wrote:
 On Friday, 27 May 2016 at 13:45:23 UTC, llaine wrote:
 I am doing something wrong ?
So, the benchmark, the Ruby, and the JS all use the path to be /.... the D seems to use /companies (though I don't know vibe). Is that right?
All right after switching of psql client I had lower results actually ... Req/Sec 22.85 for 30 seconds. What are you using to do web if you don't user Vibe.d?
Your code is not doing the same thing in the benchmarks. In D, you are appending 10000 companies on every request, resulting in 10000, 20000, 30000, .... companies in subsequent requests.
My level of D is really slow, so can you help me to improve this? :)
May 27 2016
parent Rene Zwanenburg <renezwanenburg gmail.com> writes:
On Friday, 27 May 2016 at 15:04:31 UTC, llaine wrote:
 My level of D is really slow, so can you help me to improve 
 this? :)
Here's an alternative getCompanies. Untested so it may contain some mistakes. Company[] getCompanies() { auto conn = client.lockConnection(); immutable result = conn.execStatement("SELECT id, name from companies LIMIT 10000", ValueFormat.TEXT); delete conn; import std.algorithm : map; import std.array : array; return result .rangify .map!(row => Company(row["id"].as!PGtext, row["name"].as!PGtext)) .array; }
May 27 2016
prev sibling parent Adam D. Ruppe <destructionator gmail.com> writes:
On Friday, 27 May 2016 at 14:46:47 UTC, llaine wrote:
 What are you using to do web if you don't user Vibe.d?
I wrote my own web libraries starting back in ~2009ish (well before vibe.d existed) and still use them. The modules are in here: https://github.com/adamdruppe/arsd though I don't really support it for general audiences, you're basically on your own unless you have a specific question.
May 27 2016
prev sibling next sibling parent reply Rene Zwanenburg <renezwanenburg gmail.com> writes:
On Friday, 27 May 2016 at 13:45:23 UTC, llaine wrote:
 Hi guys,

 In my journey of learning about D I tried to benchmark D with 
 Vibe.d vs node with express and Ruby with Sinatra.

 And the results are pretty surprising.
 I have to admit that I though D was more faster than that. How 
 is this even possible ?

 I am doing something wrong ?


 Here are the numbers with the project :

 https://github.com/llaine/benchmarks/blob/master/README.md
Could this line be the problem? https://github.com/llaine/benchmarks/blob/master/vibed/source/app.d#L30 You keep appending the db result to a class member, so the response size grows with every call. Additionally minimizing allocations should give a nice speed boost.
May 27 2016
parent reply llaine <darksioul yopmail.com> writes:
On Friday, 27 May 2016 at 15:11:32 UTC, Rene Zwanenburg wrote:
 On Friday, 27 May 2016 at 13:45:23 UTC, llaine wrote:
 Hi guys,

 In my journey of learning about D I tried to benchmark D with 
 Vibe.d vs node with express and Ruby with Sinatra.

 And the results are pretty surprising.
 I have to admit that I though D was more faster than that. How 
 is this even possible ?

 I am doing something wrong ?


 Here are the numbers with the project :

 https://github.com/llaine/benchmarks/blob/master/README.md
Could this line be the problem? https://github.com/llaine/benchmarks/blob/master/vibed/source/app.d#L30 You keep appending the db result to a class member, so the response size grows with every call. Additionally minimizing allocations should give a nice speed boost.
As I said I'm sorry, my level in D is really low, so : - How can I not keep appending ? - And how can I minimize allocations?
May 27 2016
parent Rene Zwanenburg <renezwanenburg gmail.com> writes:
On Friday, 27 May 2016 at 15:18:38 UTC, llaine wrote:
 - And how can I minimize allocations?
My previous post still allocates though, through that call to array at the end. I'm not sure how to completely remove all allocations (I'm not that familiar with vibe.d), but I strongly suspect it's possible. Someone else may know how. That said, it's a an optimization which should not be necessary in the general case. Only if you're doing something where there's tight maximum latency requirements (or when doing benchmarks ^^)
May 27 2016
prev sibling parent reply yawniek <dlang srtnwz.com> writes:
On Friday, 27 May 2016 at 13:45:23 UTC, llaine wrote:
 Hi guys,

 In my journey of learning about D I tried to benchmark D with 
 Vibe.d vs node with express and Ruby with Sinatra.

 And the results are pretty surprising.
 I have to admit that I though D was more faster than that. How 
 is this even possible ?

 I am doing something wrong ?


 Here are the numbers with the project :

 https://github.com/llaine/benchmarks/blob/master/README.md
you should: - use this https://github.com/etcimon/ddb Postgres client - fix your logic - NOT use option distribute - use LDC2 beta2 as compiler with release flag - use neweset vibe.d version and then your results should be easily above 1000 rps
May 27 2016
next sibling parent reply llaine <darksioul yopmail.com> writes:
On Friday, 27 May 2016 at 15:32:13 UTC, yawniek wrote:
 On Friday, 27 May 2016 at 13:45:23 UTC, llaine wrote:
 Hi guys,

 In my journey of learning about D I tried to benchmark D with 
 Vibe.d vs node with express and Ruby with Sinatra.

 And the results are pretty surprising.
 I have to admit that I though D was more faster than that. How 
 is this even possible ?

 I am doing something wrong ?


 Here are the numbers with the project :

 https://github.com/llaine/benchmarks/blob/master/README.md
you should: - use this https://github.com/etcimon/ddb Postgres client - fix your logic - NOT use option distribute - use LDC2 beta2 as compiler with release flag - use neweset vibe.d version and then your results should be easily above 1000 rps
Okay by just fixing my logic, I go up to 839.42 Req/Sec for 10 sec and 601.74 Req/Sec for 30sec which is pretty impressive! My other question here is, can I specify directly in dub the compiler I want to use? Something like this : dub -compiler=ldc|dmd ... Because I really want to try to reach 1000rps
May 27 2016
parent llaine <darksioul yopmail.com> writes:
On Friday, 27 May 2016 at 15:48:18 UTC, llaine wrote:
 On Friday, 27 May 2016 at 15:32:13 UTC, yawniek wrote:
 On Friday, 27 May 2016 at 13:45:23 UTC, llaine wrote:
 [...]
you should: - use this https://github.com/etcimon/ddb Postgres client - fix your logic - NOT use option distribute - use LDC2 beta2 as compiler with release flag - use neweset vibe.d version and then your results should be easily above 1000 rps
Okay by just fixing my logic, I go up to 839.42 Req/Sec for 10 sec and 601.74 Req/Sec for 30sec which is pretty impressive! My other question here is, can I specify directly in dub the compiler I want to use? Something like this : dub -compiler=ldc|dmd ... Because I really want to try to reach 1000rps
I've update my SQL dump with 100 entries and now and I have better results! Pretty amazing :) If you guys want to improve it feel free to PR !!!
May 27 2016
prev sibling parent reply Daniel Kozak via Digitalmars-d-learn <digitalmars-d-learn puremagic.com> writes:
Why not to use distribute oprion?
Dne 27. 5. 2016 17:35 napsal u=C5=BEivatel "yawniek via Digitalmars-d-learn=
" <
digitalmars-d-learn puremagic.com>:

 On Friday, 27 May 2016 at 13:45:23 UTC, llaine wrote:

 Hi guys,

 In my journey of learning about D I tried to benchmark D with Vibe.d vs
 node with express and Ruby with Sinatra.

 And the results are pretty surprising.
 I have to admit that I though D was more faster than that. How is this
 even possible ?

 I am doing something wrong ?


 Here are the numbers with the project :

 https://github.com/llaine/benchmarks/blob/master/README.md
you should: - use this https://github.com/etcimon/ddb Postgres client - fix your logic - NOT use option distribute - use LDC2 beta2 as compiler with release flag - use neweset vibe.d version and then your results should be easily above 1000 rps
May 27 2016
parent yawniek <dlang srtnwz.com> writes:
On Friday, 27 May 2016 at 16:47:19 UTC, Daniel Kozak wrote:
 Why not to use distribute oprion?
 Dne 27. 5. 2016 17:35 napsal uživatel "yawniek via 
 Digitalmars-d-learn" <
 digitalmars-d-learn puremagic.com>:
it its a flawed strategy. what you should do is let the kernel handle it and use SO_ REUSEPORT libasync supports it. see e.g. https://github.com/rejectedsoftware/vibe.d/issues/1139 and https://lwn.net/Articles/542629/
May 28 2016