May 27, 2016
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
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
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
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
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
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
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
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
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
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 ^^)