Skip to content

Instantly share code, notes, and snippets.

@leotada
Created July 19, 2019 05:01
Show Gist options
  • Save leotada/986dcbc1176005a6a401d73a0fe4408c to your computer and use it in GitHub Desktop.
Save leotada/986dcbc1176005a6a401d73a0fe4408c to your computer and use it in GitHub Desktop.
Fibonacci Vibe.d multithread benchmark
import core.thread;
import vibe.vibe;
import std.stdio;
int fib(int n)
{
if (n <= 1)
return n;
return fib(n - 1) + fib(n - 2);
}
void handleRequest(HTTPServerRequest req, HTTPServerResponse res)
{
if (req.path == "/bench")
{
res.writeJsonBody(["message": fib(15)]);
}
}
void runServer()
{
auto settings = new HTTPServerSettings;
settings.options |= HTTPServerOption.reusePort;
settings.port = 8000;
settings.bindAddresses = ["0.0.0.0"];
listenHTTP(settings, &handleRequest);
}
void main()
{
writefln("Master %d is running", getpid());
setupWorkerThreads(logicalProcessorCount);
runWorkerTaskDist(&runServer);
runApplication();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment