Re: Benchmark Dlang vs Node vs Ruby

2016-05-28 Thread yawniek via Digitalmars-d-learn

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/


Re: Benchmark Dlang vs Node vs Ruby

2016-05-27 Thread Daniel Kozak via Digitalmars-d-learn
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>:

> 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
>
>
>


Re: Benchmark Dlang vs Node vs Ruby

2016-05-27 Thread llaine via Digitalmars-d-learn

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 !!!


Re: Benchmark Dlang vs Node vs Ruby

2016-05-27 Thread llaine via Digitalmars-d-learn

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




Re: Benchmark Dlang vs Node vs Ruby

2016-05-27 Thread yawniek via Digitalmars-d-learn

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




Re: Benchmark Dlang vs Node vs Ruby

2016-05-27 Thread Rene Zwanenburg via Digitalmars-d-learn

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 ^^)


Re: Benchmark Dlang vs Node vs Ruby

2016-05-27 Thread Rene Zwanenburg via Digitalmars-d-learn

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 1", 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;
}


Re: Benchmark Dlang vs Node vs Ruby

2016-05-27 Thread llaine via Digitalmars-d-learn

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?


Re: Benchmark Dlang vs Node vs Ruby

2016-05-27 Thread Rene Zwanenburg via Digitalmars-d-learn

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.


Re: Benchmark Dlang vs Node vs Ruby

2016-05-27 Thread llaine via Digitalmars-d-learn

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 1 companies on every request, resulting 
in 1, 2, 3,  companies in subsequent requests.


My level of D is really slow, so can you help me to improve this? 
:)


Re: Benchmark Dlang vs Node vs Ruby

2016-05-27 Thread Adam D. Ruppe via Digitalmars-d-learn

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.


Re: Benchmark Dlang vs Node vs Ruby

2016-05-27 Thread llaine via Digitalmars-d-learn

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


Re: Benchmark Dlang vs Node vs Ruby

2016-05-27 Thread yazd via Digitalmars-d-learn

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 1 companies on every request, resulting in 
1, 2, 3,  companies in subsequent requests.


Re: Benchmark Dlang vs Node vs Ruby

2016-05-27 Thread Daniel Kozak via Digitalmars-d-learn

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);



Re: Benchmark Dlang vs Node vs Ruby

2016-05-27 Thread llaine via Digitalmars-d-learn

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?


Re: Benchmark Dlang vs Node vs Ruby

2016-05-27 Thread llaine via Digitalmars-d-learn

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.


Re: Benchmark Dlang vs Node vs Ruby

2016-05-27 Thread Adam D. Ruppe via Digitalmars-d-learn

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?


Re: Benchmark Dlang vs Node vs Ruby

2016-05-27 Thread yazd via Digitalmars-d-learn

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.


Re: Benchmark Dlang vs Node vs Ruby

2016-05-27 Thread Adam D. Ruppe via Digitalmars-d-learn

oooh, I wanna try my libs.

Where's your database dump?


Re: Benchmark Dlang vs Node vs Ruby

2016-05-27 Thread llaine via Digitalmars-d-learn

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 
...


Re: Benchmark Dlang vs Node vs Ruby

2016-05-27 Thread bob belcher via Digitalmars-d-learn

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 :)


Re: Benchmark Dlang vs Node vs Ruby

2016-05-27 Thread llaine via Digitalmars-d-learn

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 ?


Re: Benchmark Dlang vs Node vs Ruby

2016-05-27 Thread Vadim Lopatin via Digitalmars-d-learn

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.



Benchmark Dlang vs Node vs Ruby

2016-05-27 Thread llaine via Digitalmars-d-learn

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