<div dir="ltr">On which system? AFAIK <span style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:12.8px;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">HTTPServerOption.reusePort works on Linux but maybe not on others OSes. Other question is what events driver is use (libasync, libevent, vibe-core)</span></div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, May 9, 2018 at 9:12 PM, Arun Chandrasekaran via Digitalmars-d <span dir="ltr"><<a href="mailto:digitalmars-d@puremagic.com" target="_blank">digitalmars-d@puremagic.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">On Monday, 30 October 2017 at 17:23:02 UTC, Daniel Kozak wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Maybe this one:<br>
<br>
import vibe.d;<br>
import std.regex;<br>
import std.array : appender;<br>
<br>
static reg = ctRegex!"^/greeting/([a-z]+)$"<wbr>;<br>
<br>
void main()<br>
{<br>
setupWorkerThreads(logicalProc<wbr>essorCount);<br>
runWorkerTaskDist(&runServer);<br>
runApplication();<br>
}<br>
<br>
void runServer()<br>
{<br>
auto settings = new HTTPServerSettings;<br>
settings.options |= HTTPServerOption.reusePort;<br>
settings.port = 3000;<br>
settings.serverString = null;<br>
listenHTTP(settings, &handleRequest);<br>
}<br>
<br>
void handleRequest(HTTPServerReques<wbr>t req,<br>
HTTPServerResponse res)<br>
{<br>
switch(req.path)<br>
{<br>
case "/": res.writeBody("Hello World", "text/plain");<br>
break;<br>
default:<br>
auto m = matchFirst(req.path, reg);<br>
string message = "Hello, ";<br>
auto app = appender(message);<br>
app.reserve(32);<br>
app ~= m[1];<br>
res.writeBody(app.data, "text/plain");<br>
}<br>
}<br>
<br>
On Mon, Oct 30, 2017 at 5:41 PM, ade90036 via Digitalmars-d < <a href="mailto:digitalmars-d@puremagic.com" target="_blank">digitalmars-d@puremagic.com</a>> wrote:<br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
On Thursday, 21 September 2017 at 13:09:33 UTC, Daniel Kozak wrote:<br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
wrong version, this is my letest version: <a href="https://paste.ofcode.org/qWsQi" rel="noreferrer" target="_blank">https://paste.ofcode.org/qWsQi</a> kdhKiAywgBpKwANFR<br>
<br>
On Thu, Sep 21, 2017 at 3:01 PM, Daniel Kozak <<a href="mailto:kozzi11@gmail.com" target="_blank">kozzi11@gmail.com</a>> wrote:<br>
<br>
my version: <a href="https://paste.ofcode.org/RLX7GM6SHh3DjBBHd7wshj" rel="noreferrer" target="_blank">https://paste.ofcode.org/RLX7G<wbr>M6SHh3DjBBHd7wshj</a><br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
On Thu, Sep 21, 2017 at 2:50 PM, Sönke Ludwig via Digitalmars-d < <a href="mailto:digitalmars-d@puremagic.com" target="_blank">digitalmars-d@puremagic.com</a>> wrote:<br>
<br>
Am 21.09.2017 um 14:41 schrieb Vadim Lopatin:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
[...]<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
</blockquote>
Oh, sorry, I forgot the reusePort option, so that multiple sockets can listen on the same port:<br>
<br>
auto settings = new HTTPServerSettings("<a href="http://0.0.0.0:3000" rel="noreferrer" target="_blank">0.0.0.0:30<wbr>00</a>");<br>
settings.options |= HTTPServerOption.reusePort;<br>
listenHTTP(settings, &handleRequest);<br>
<br>
</blockquote>
<br>
</blockquote></blockquote>
Hi, would it be possible to re-share the example of vibe.d woth multithreaded support.<br>
<br>
The pastebin link has expired and the pull request doesnt have the latest version.<br>
<br>
Thanks<br>
<br>
Ade<br>
</blockquote></blockquote>
<br>
With vibe.d 0.8.2, even when multiple worker threads are setup, only one thread handles the requests:<br>
<br>
```<br>
import core.thread;<br>
import vibe.d;<br>
import std.experimental.all;<br>
<br>
auto reg = ctRegex!"^/greeting/([a-z]+)$"<wbr>;<br>
<br>
void main()<br>
{<br>
writefln("Master %d is running", getpid());<br>
setupWorkerThreads(logicalProc<wbr>essorCount + 1);<br>
runWorkerTaskDist(&runServer);<br>
runApplication();<br>
}<br>
<br>
void runServer()<br>
{<br>
auto settings = new HTTPServerSettings;<br>
settings.options |= HTTPServerOption.reusePort;<br>
settings.port = 8080;<br>
settings.bindAddresses = ["127.0.0.1"];<br>
listenHTTP(settings, &handleRequest);<br>
}<br>
<br>
void handleRequest(HTTPServerReques<wbr>t req,<br>
HTTPServerResponse res)<br>
{<br>
writeln("My Thread Id: ", to!string(thisThreadID));<br>
// simulate long runnig task<br>
Thread.sleep(dur!("seconds")(3<wbr>));<br>
<br>
if (req.path == "/")<br>
res.writeBody("Hello, World! from " ~ to!string(thisThreadID), "text/plain");<br>
else if (auto m = matchFirst(req.path, reg))<br>
res.writeBody("Hello, " ~ m[1] ~ " from " ~ to!string(thisThreadID), "text/plain");<br>
}<br>
```<br>
<br>
That could be the reason for slowness.<br>
</blockquote></div><br></div>