Skip to content

Commit f71f7ee

Browse files
authored
Http server d (#375)
1 parent e2de7d7 commit f71f7ee

File tree

6 files changed

+89
-7
lines changed

6 files changed

+89
-7
lines changed

bench/algorithm/binarytrees/1.d

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
@safe:
22
import std;
33

4+
extern(C) __gshared string[] rt_options = [ "gcopt=minPoolSize:300" ];
5+
46
const MIN_DEPTH = 4;
57

68
class Node {

bench/algorithm/http-server/1.d

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import std;
2+
import arsd.cgi;
3+
4+
static void startServer(RequestServer s) {
5+
s.serve!(postFunc, Cgi, defaultMaxContentLength);
6+
}
7+
8+
void postFunc(Cgi cgi) {
9+
cgi.setResponseContentType("text/plain");
10+
cgi.write(cgi.post["value"]);
11+
12+
}
13+
14+
int reqSend(Tuple!(string, int) val) {
15+
while (true) {
16+
auto content = std.net.curl.post(val[0], ["value" : val[1].to!string]);
17+
return content.to!int;
18+
}
19+
}
20+
21+
int main(string[] args)
22+
{
23+
int n = args.length > 1 ? args[1].to!int : 10;
24+
auto rnd = Random(unpredictableSeed);
25+
auto port = uniform(30000, 40000, rnd);
26+
string api = "127.0.0.1:"~to!string(port)~"/";
27+
RequestServer server = RequestServer("127.0.0.1", cast(ushort) port);
28+
server.useFork = false;
29+
auto tid = spawn(&startServer, server);
30+
auto init = iota(1,n + 1,1).map!(a => tuple(api, a));
31+
auto res = taskPool.amap!reqSend(init, n);
32+
writeln(res.sum);
33+
server.stop();
34+
return 0;
35+
}

bench/algorithm/http-server/2.d

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import std;
2+
import arsd.cgi;
3+
4+
static void startServer(RequestServer s) {
5+
s.serve!(postFunc, Cgi, defaultMaxContentLength);
6+
}
7+
8+
void postFunc(Cgi cgi) {
9+
cgi.setResponseContentType("text/plain");
10+
auto p = parseJSON(cgi.postBody);
11+
cgi.write(p["value"].to!string);
12+
13+
}
14+
15+
int reqSend(Tuple!(string, int) val) {
16+
auto client = HTTP();
17+
client.addRequestHeader("Content-Type: appliation/json", "Content-Type: appliation/json");
18+
while (true) {
19+
auto content = std.net.curl.post(val[0], (JSONValue(["value" : val[1]])).toString, client);
20+
return content.to!int;
21+
}
22+
}
23+
24+
int main(string[] args)
25+
{
26+
int n = args.length > 1 ? args[1].to!int : 10;
27+
auto rnd = Random(unpredictableSeed);
28+
auto port = uniform(30000, 40000, rnd);
29+
string api = "127.0.0.1:"~to!string(port)~"/";
30+
RequestServer server = RequestServer("127.0.0.1", cast(ushort) port);
31+
server.useFork = false;
32+
auto tid = spawn(&startServer, server);
33+
auto init = iota(1,n + 1,1).map!(a => tuple(api, a));
34+
auto res = taskPool.amap!reqSend(init, n);
35+
writeln(res.sum);
36+
server.stop();
37+
return 0;
38+
}

bench/algorithm/merkletrees/1.d

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
@safe:
22
import std;
33

4+
extern(C) __gshared string[] rt_options = [ "gcopt=minPoolSize:300" ];
5+
46
const MIN_DEPTH = 4;
57

68
class Node {

bench/bench_d.yaml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,11 @@ problems:
5656
- 1-m.d
5757
- name: json-serde
5858
source:
59-
# - 2.d
59+
- 2.d
60+
- name: http-server
61+
source:
62+
- 1.d
63+
- 2.d
6064
compiler_version_command:
6165
compiler_version_regex:
6266
runtime_version_parameter:

bench/include/d/dub.json

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@
33
"root"
44
],
55
"copyright": "Copyright © 2021, root",
6-
"dependencies": {
7-
"intel-intrinsics": {
8-
"version": "5691bf9de94b1c08244c45e6c3659fb0c150e82c",
9-
"repository": "git+https://github.com/AuburnSounds/intel-intrinsics.git"
10-
}
11-
},
6+
"dependencies": {
7+
"asdf": "~>0.7.15",
8+
"intel-intrinsics": "1.11.1",
9+
"mir-algorithm": {"version": "468377999b43fe370c2f59a40257183475f04c55", "repository": "git+https://github.com/cyrusmsk/mir-algorithm.git", "default": true},
10+
"arsd-official:cgi": "~>10.9.8"
11+
},
12+
"subConfigurations": {"arsd-official:cgi": "embedded_httpd_hybrid"},
1213
"description": "A minimal D application.",
1314
"license": "MIT",
1415
"name": "app",

0 commit comments

Comments
 (0)