May 09, 2018
On which system? AFAIK HTTPServerOption.reusePort works on Linux but maybe not on others OSes. Other question is what events driver is use (libasync, libevent, vibe-core)

On Wed, May 9, 2018 at 9:12 PM, Arun Chandrasekaran via Digitalmars-d < digitalmars-d@puremagic.com> wrote:

> On Monday, 30 October 2017 at 17:23:02 UTC, Daniel Kozak wrote:
>
>> Maybe this one:
>>
>> import vibe.d;
>> import std.regex;
>> import std.array : appender;
>>
>> static reg = ctRegex!"^/greeting/([a-z]+)$";
>>
>> void main()
>> {
>>     setupWorkerThreads(logicalProcessorCount);
>>     runWorkerTaskDist(&runServer);
>>     runApplication();
>> }
>>
>> void runServer()
>> {
>>     auto settings = new HTTPServerSettings;
>>     settings.options |= HTTPServerOption.reusePort;
>>     settings.port = 3000;
>>     settings.serverString = null;
>>     listenHTTP(settings, &handleRequest);
>> }
>>
>> void handleRequest(HTTPServerRequest req,
>>                     HTTPServerResponse res)
>> {
>>     switch(req.path)
>>     {
>>     case "/": res.writeBody("Hello World", "text/plain");
>>         break;
>>     default:
>>         auto m = matchFirst(req.path, reg);
>>         string message = "Hello, ";
>>         auto app = appender(message);
>>         app.reserve(32);
>>         app ~= m[1];
>>         res.writeBody(app.data, "text/plain");
>>     }
>> }
>>
>> On Mon, Oct 30, 2017 at 5:41 PM, ade90036 via Digitalmars-d < digitalmars-d@puremagic.com> wrote:
>>
>> On Thursday, 21 September 2017 at 13:09:33 UTC, Daniel Kozak wrote:
>>>
>>> wrong version, this is my letest version: https://paste.ofcode.org/qWsQi
>>>> kdhKiAywgBpKwANFR
>>>>
>>>> On Thu, Sep 21, 2017 at 3:01 PM, Daniel Kozak <kozzi11@gmail.com> wrote:
>>>>
>>>> my version: https://paste.ofcode.org/RLX7GM6SHh3DjBBHd7wshj
>>>>
>>>>>
>>>>> On Thu, Sep 21, 2017 at 2:50 PM, Sönke Ludwig via Digitalmars-d < digitalmars-d@puremagic.com> wrote:
>>>>>
>>>>> Am 21.09.2017 um 14:41 schrieb Vadim Lopatin:
>>>>>
>>>>>>
>>>>>> [...]
>>>>>>
>>>>>>>
>>>>>>> Oh, sorry, I forgot the reusePort option, so that multiple sockets
>>>>>> can listen on the same port:
>>>>>>
>>>>>>     auto settings = new HTTPServerSettings("0.0.0.0:3000");
>>>>>>     settings.options |= HTTPServerOption.reusePort;
>>>>>>     listenHTTP(settings, &handleRequest);
>>>>>>
>>>>>>
>>>>> Hi, would it be possible to re-share the example of vibe.d woth
>>> multithreaded support.
>>>
>>> The pastebin link has expired and the pull request doesnt have the latest version.
>>>
>>> Thanks
>>>
>>> Ade
>>>
>>
> With vibe.d 0.8.2, even when multiple worker threads are setup, only one thread handles the requests:
>
> ```
> import core.thread;
> import vibe.d;
> import std.experimental.all;
>
> auto reg = ctRegex!"^/greeting/([a-z]+)$";
>
> void main()
> {
>     writefln("Master %d is running", getpid());
>     setupWorkerThreads(logicalProcessorCount + 1);
>     runWorkerTaskDist(&runServer);
>     runApplication();
> }
>
> void runServer()
> {
>     auto settings = new HTTPServerSettings;
>     settings.options |= HTTPServerOption.reusePort;
>     settings.port = 8080;
>     settings.bindAddresses = ["127.0.0.1"];
>     listenHTTP(settings, &handleRequest);
> }
>
> void handleRequest(HTTPServerRequest req,
>                     HTTPServerResponse res)
> {
>     writeln("My Thread Id: ", to!string(thisThreadID));
>     // simulate long runnig task
>     Thread.sleep(dur!("seconds")(3));
>
>     if (req.path == "/")
>         res.writeBody("Hello, World! from " ~ to!string(thisThreadID),
> "text/plain");
>     else if (auto m = matchFirst(req.path, reg))
>         res.writeBody("Hello, " ~ m[1] ~ " from " ~
> to!string(thisThreadID), "text/plain");
> }
> ```
>
> That could be the reason for slowness.
>


May 09, 2018
On Wednesday, 9 May 2018 at 21:55:15 UTC, Daniel Kozak wrote:
> On which system? AFAIK HTTPServerOption.reusePort works on Linux but maybe not on others OSes. Other question is what events driver is use (libasync, libevent, vibe-core)
>
> On Wed, May 9, 2018 at 9:12 PM, Arun Chandrasekaran via Digitalmars-d < digitalmars-d@puremagic.com> wrote:
>
>> On Monday, 30 October 2017 at 17:23:02 UTC, Daniel Kozak wrote:
>>
>>> Maybe this one:
>>>
>>> import vibe.d;
>>> import std.regex;
>>> import std.array : appender;
>>>
>>> static reg = ctRegex!"^/greeting/([a-z]+)$";
>>>
>>> void main()
>>> {
>>>     setupWorkerThreads(logicalProcessorCount);
>>>     runWorkerTaskDist(&runServer);
>>>     runApplication();
>>> }
>>>
>>> void runServer()
>>> {
>>>     auto settings = new HTTPServerSettings;
>>>     settings.options |= HTTPServerOption.reusePort;
>>>     settings.port = 3000;
>>>     settings.serverString = null;
>>>     listenHTTP(settings, &handleRequest);
>>> }
>>>
>>> void handleRequest(HTTPServerRequest req,
>>>                     HTTPServerResponse res)
>>> {
>>>     switch(req.path)
>>>     {
>>>     case "/": res.writeBody("Hello World", "text/plain");
>>>         break;
>>>     default:
>>>         auto m = matchFirst(req.path, reg);
>>>         string message = "Hello, ";
>>>         auto app = appender(message);
>>>         app.reserve(32);
>>>         app ~= m[1];
>>>         res.writeBody(app.data, "text/plain");
>>>     }
>>> }
>>>
>>> On Mon, Oct 30, 2017 at 5:41 PM, ade90036 via Digitalmars-d < digitalmars-d@puremagic.com> wrote:
>>>
>>> On Thursday, 21 September 2017 at 13:09:33 UTC, Daniel Kozak wrote:
>>>>
>>>> wrong version, this is my letest version: https://paste.ofcode.org/qWsQi
>>>>> kdhKiAywgBpKwANFR
>>>>>
>>>>> On Thu, Sep 21, 2017 at 3:01 PM, Daniel Kozak <kozzi11@gmail.com> wrote:
>>>>>
>>>>> my version: https://paste.ofcode.org/RLX7GM6SHh3DjBBHd7wshj
>>>>>
>>>>>>
>>>>>> On Thu, Sep 21, 2017 at 2:50 PM, Sönke Ludwig via Digitalmars-d < digitalmars-d@puremagic.com> wrote:
>>>>>>
>>>>>> Am 21.09.2017 um 14:41 schrieb Vadim Lopatin:
>>>>>>
>>>>>>>
>>>>>>> [...]
>>>>>>>
>>>>>>>>
>>>>>>>> Oh, sorry, I forgot the reusePort option, so that multiple sockets
>>>>>>> can listen on the same port:
>>>>>>>
>>>>>>>     auto settings = new HTTPServerSettings("0.0.0.0:3000");
>>>>>>>     settings.options |= HTTPServerOption.reusePort;
>>>>>>>     listenHTTP(settings, &handleRequest);
>>>>>>>
>>>>>>>
>>>>>> Hi, would it be possible to re-share the example of vibe.d woth
>>>> multithreaded support.
>>>>
>>>> The pastebin link has expired and the pull request doesnt have the latest version.
>>>>
>>>> Thanks
>>>>
>>>> Ade
>>>>
>>>
>> With vibe.d 0.8.2, even when multiple worker threads are setup, only one thread handles the requests:
>>
>> ```
>> import core.thread;
>> import vibe.d;
>> import std.experimental.all;
>>
>> auto reg = ctRegex!"^/greeting/([a-z]+)$";
>>
>> void main()
>> {
>>     writefln("Master %d is running", getpid());
>>     setupWorkerThreads(logicalProcessorCount + 1);
>>     runWorkerTaskDist(&runServer);
>>     runApplication();
>> }
>>
>> void runServer()
>> {
>>     auto settings = new HTTPServerSettings;
>>     settings.options |= HTTPServerOption.reusePort;
>>     settings.port = 8080;
>>     settings.bindAddresses = ["127.0.0.1"];
>>     listenHTTP(settings, &handleRequest);
>> }
>>
>> void handleRequest(HTTPServerRequest req,
>>                     HTTPServerResponse res)
>> {
>>     writeln("My Thread Id: ", to!string(thisThreadID));
>>     // simulate long runnig task
>>     Thread.sleep(dur!("seconds")(3));
>>
>>     if (req.path == "/")
>>         res.writeBody("Hello, World! from " ~ to!string(thisThreadID),
>> "text/plain");
>>     else if (auto m = matchFirst(req.path, reg))
>>         res.writeBody("Hello, " ~ m[1] ~ " from " ~
>> to!string(thisThreadID), "text/plain");
>> }
>> ```
>>
>> That could be the reason for slowness.

Ubuntu 17.10 64 bit, DMD v2.079.1, E7-4860, 8 core 32 GB RAM.

With slight modifcaition to capture the timestamp of the request on the server:

    import std.datetime.systime : Clock;
    auto tm = Clock.currTime().toISOExtString();
    writeln(tm, " My Thread Id: ", to!string(thisThreadID));
    // simulate long runnig task
    Thread.sleep(dur!("seconds")(3));

    if (req.path == "/")
        res.writeBody(tm ~ " Hello, World! from " ~ to!string(thisThreadID), "text/plain");


Launch two parallel curls.. and here is the server log..

Master 13284 is running
[vibe-6(5fQI) INF] Listening for requests on http://0.0.0.0:8080/
[vibe-7(xljY) INF] Listening for requests on http://0.0.0.0:8080/
[vibe-2(FVCk) INF] Listening for requests on http://0.0.0.0:8080/
[vibe-3(peZP) INF] Listening for requests on http://0.0.0.0:8080/
[vibe-8(c5pQ) INF] Listening for requests on http://0.0.0.0:8080/
[vibe-4(T/oM) INF] Listening for requests on http://0.0.0.0:8080/
[vibe-5(zc5i) INF] Listening for requests on http://0.0.0.0:8080/
[vibe-1(Rdux) INF] Listening for requests on http://0.0.0.0:8080/
[vibe-0(PNMK) INF] Listening for requests on http://0.0.0.0:8080/
2018-05-09T15:32:41.5424275 My Thread Id: 140129463940864
2018-05-09T15:32:44.5450092 My Thread Id: 140129463940864
2018-05-09T15:32:56.3998322 My Thread Id: 140129463940864
2018-05-09T15:32:59.4022579 My Thread Id: 140129463940864
2018-05-09T15:33:12.4973215 My Thread Id: 140129463940864
2018-05-09T15:33:15.4996923 My Thread Id: 140129463940864


PS: Your top posting makes reading your replies difficult
May 11, 2018
On Wednesday, 9 May 2018 at 22:37:22 UTC, Arun Chandrasekaran wrote:
>>> That could be the reason for slowness.
>
> Ubuntu 17.10 64 bit, DMD v2.079.1, E7-4860, 8 core 32 GB RAM.
>
> With slight modifcaition to capture the timestamp of the request on the server:
>
>     import std.datetime.systime : Clock;
>     auto tm = Clock.currTime().toISOExtString();
>     writeln(tm, " My Thread Id: ", to!string(thisThreadID));
>     // simulate long runnig task
>     Thread.sleep(dur!("seconds")(3));
>
>     if (req.path == "/")
>         res.writeBody(tm ~ " Hello, World! from " ~ to!string(thisThreadID), "text/plain");
>
>
> Launch two parallel curls.. and here is the server log..
>
> Master 13284 is running
> [vibe-6(5fQI) INF] Listening for requests on http://0.0.0.0:8080/
> [vibe-7(xljY) INF] Listening for requests on http://0.0.0.0:8080/
> [vibe-2(FVCk) INF] Listening for requests on http://0.0.0.0:8080/
> [vibe-3(peZP) INF] Listening for requests on http://0.0.0.0:8080/
> [vibe-8(c5pQ) INF] Listening for requests on http://0.0.0.0:8080/
> [vibe-4(T/oM) INF] Listening for requests on http://0.0.0.0:8080/
> [vibe-5(zc5i) INF] Listening for requests on http://0.0.0.0:8080/
> [vibe-1(Rdux) INF] Listening for requests on http://0.0.0.0:8080/
> [vibe-0(PNMK) INF] Listening for requests on http://0.0.0.0:8080/
> 2018-05-09T15:32:41.5424275 My Thread Id: 140129463940864
> 2018-05-09T15:32:44.5450092 My Thread Id: 140129463940864
> 2018-05-09T15:32:56.3998322 My Thread Id: 140129463940864
> 2018-05-09T15:32:59.4022579 My Thread Id: 140129463940864
> 2018-05-09T15:33:12.4973215 My Thread Id: 140129463940864
> 2018-05-09T15:33:15.4996923 My Thread Id: 140129463940864
>
>
> PS: Your top posting makes reading your replies difficult

I have change my example a little:

case "/": res.writeBody("Hello World " ~ to!string(thisThreadID), "text/plain");

And I get this (siege -p -c15 0b -t 10s http://127.0.0.1:3000 | grep World | sort | uniq):

Hello World 140064214951680
Hello World 140064223344384
Hello World 140064231737088
Hello World 140064240129792
Hello World 140064248522496
Hello World 140064256915200

Si I get six different thread ids, which is OK because I have 6 cores




May 11, 2018
On Friday, 11 May 2018 at 07:56:04 UTC, Daniel Kozak wrote:
> On Wednesday, 9 May 2018 at 22:37:22 UTC, Arun Chandrasekaran wrote:
>> [...]
>
> I have change my example a little:
>
> case "/": res.writeBody("Hello World " ~ to!string(thisThreadID), "text/plain");
>
> And I get this (siege -p -c15 0b -t 10s http://127.0.0.1:3000 | grep World | sort | uniq):
>
> Hello World 140064214951680
> Hello World 140064223344384
> Hello World 140064231737088
> Hello World 140064240129792
> Hello World 140064248522496
> Hello World 140064256915200
>
> Si I get six different thread ids, which is OK because I have 6 cores

my dub.json:

{
	"name": "sbench",
	"authors": [
		"Daniel Kozak"
	],
	"dependencies": {
		"vibe-d": "~>0.8.4-beta.1",
		"vibe-d:tls": "0.8.4-beta.1",
		"vibe-core": "1.4.1-beta.2"
	},
	"subConfigurations": {
		"vibe-d:core": "vibe-core",
		"vibe-d:tls": "notls"
	},
	"description": "A simple vibe.d server application.",
	"copyright": "Copyright © 2018, Daniel Kozak",
	"license": "proprietary"
}
May 11, 2018
On Friday, 11 May 2018 at 07:56:04 UTC, Daniel Kozak wrote:
> On Wednesday, 9 May 2018 at 22:37:22 UTC, Arun Chandrasekaran wrote:
>> [...]
>
> I have change my example a little:
>
> case "/": res.writeBody("Hello World " ~ to!string(thisThreadID), "text/plain");
>
> And I get this (siege -p -c15 0b -t 10s http://127.0.0.1:3000 | grep World | sort | uniq):
>
> Hello World 140064214951680
> Hello World 140064223344384
> Hello World 140064231737088
> Hello World 140064240129792
> Hello World 140064248522496
> Hello World 140064256915200
>
> Si I get six different thread ids, which is OK because I have 6 cores

siege makes a difference. Earlier I had two chrome windows open and I just tried a simple GET from each, with a considerable delay and I saw the same thread ID in both the responses. Thanks for your help! But couldn't understand how two chrome windows could consistently get the same thread ID. netstat shows one ESTABLISHED socket. May be Chrome multiplexes the connection? That doesn't sound right to me.
May 12, 2018
On Friday, 11 May 2018 at 23:24:32 UTC, Arun Chandrasekaran wrote:
> On Friday, 11 May 2018 at 07:56:04 UTC, Daniel Kozak wrote:
>> [...]
>
> siege makes a difference. Earlier I had two chrome windows open and I just tried a simple GET from each, with a considerable delay and I saw the same thread ID in both the responses. Thanks for your help! But couldn't understand how two chrome windows could consistently get the same thread ID. netstat shows one ESTABLISHED socket. May be Chrome multiplexes the connection? That doesn't sound right to me.

Very likely:

https://www.igvita.com/posa/high-performance-networking-in-google-chrome/#tcp-pre-connect
1 2 3 4 5 6
Next ›   Last »