Skip to content

Commit faf4eba

Browse files
HeromythNateBrady23
authored andcommitted
Upgrade to Hunt 1.2.x (TechEmpower#4846)
* Upgrade to Hunt 1.2.x * Rename docker file * Adjust the upper bound for random id
1 parent 086fabd commit faf4eba

29 files changed

+2567
-149
lines changed

frameworks/D/hunt/build.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,9 @@ git clone https://github.com/h2o/picohttpparser.git
55
cp patches/Makefile picohttpparser
66
cd picohttpparser
77
make package
8+
9+
10+
rm -rf http-parser
11+
git clone https://github.com/nodejs/http-parser.git
12+
cd http-parser
13+
make package

frameworks/D/hunt/dub.json

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"homepage": "https://www.huntlabs.net",
77
"license": "Apache-2.0",
88
"dependencies": {
9-
"hunt": "~>1.2.0",
9+
"hunt": "~>1.2.2",
1010
"hunt-database": "~>1.2.0",
1111
"std_data_json": "~>0.18.2"
1212
},
@@ -16,6 +16,7 @@
1616
"configurations": [
1717
{
1818
"name": "default",
19+
"sourcePaths": ["http"],
1920
"libs-posix": [
2021
"http_parser"
2122
],
@@ -28,6 +29,7 @@
2829
},
2930
{
3031
"name": "minihttp",
32+
"sourcePaths": ["pico"],
3133
"libs-posix": [
3234
"picohttpparser"
3335
],
@@ -37,9 +39,22 @@
3739
"versions": [
3840
"MINIHTTP"
3941
]
42+
},
43+
{
44+
"name": "mmap",
45+
"sourcePaths": ["mmap"],
46+
"libs-posix": [
47+
"picohttpparser"
48+
],
49+
"lflags-posix": [
50+
"-Lpicohttpparser/"
51+
],
52+
"versions": [
53+
"MMAP"
54+
]
4055
}
4156
],
4257
"subConfigurations": {
4358
"hunt-database": "postgresql"
4459
}
45-
}
60+
}

frameworks/D/hunt/http/app.d

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*
2+
* Collie - An asynchronous event-driven network framework using Dlang development
3+
*
4+
* Copyright (C) 2015-2018 Shanghai Putao Technology Co., Ltd
5+
*
6+
* Developer: Putao's Dlang team
7+
*
8+
* Licensed under the Apache-2.0 License.
9+
*
10+
*/
11+
import std.getopt;
12+
import std.stdio;
13+
14+
import hunt.database;
15+
import hunt.io;
16+
import hunt.system.Memory : totalCPUs;
17+
import http.Processor;
18+
import http.Server;
19+
import http.DemoProcessor;
20+
21+
void main(string[] args) {
22+
ushort port = 8080;
23+
GetoptResult o = getopt(args, "port|p", "Port (default 8080)", &port);
24+
if (o.helpWanted) {
25+
defaultGetoptPrinter("A simple http server powered by Hunt!", o.options);
26+
return;
27+
}
28+
29+
version (POSTGRESQL) {
30+
DatabaseOption options;
31+
debug {
32+
options = new DatabaseOption(
33+
"postgresql://benchmarkdbuser:benchmarkdbpass@10.1.11.44:5432/hello_world?charset=utf-8");
34+
} else {
35+
options = new DatabaseOption(
36+
"postgresql://benchmarkdbuser:benchmarkdbpass@tfb-database:5432/hello_world?charset=utf-8");
37+
}
38+
39+
options.setMinimumConnection(totalCPUs*3);
40+
options.setMaximumConnection(totalCPUs*3);
41+
dbConnection = new Database(options);
42+
}
43+
44+
AbstractTcpServer httpServer = new HttpServer!(DemoProcessor)("0.0.0.0", port, totalCPUs);
45+
writefln("listening on http://%s", httpServer.bindingAddress.toString());
46+
httpServer.start();
47+
}

frameworks/D/hunt/source/http/DemoProcessor.d renamed to frameworks/D/hunt/http/http/DemoProcessor.d

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module http.DemoProcessor;
22

3-
version(HTTP) :
3+
44

55
// import stdx.data.json;
66
import std.json;
@@ -150,7 +150,7 @@ class DemoProcessor : HttpProcessor {
150150

151151

152152
private void respondSingleQuery() {
153-
int id = uniform(1, 10000);
153+
int id = uniform(1, 10001);
154154
string query = "SELECT randomNumber FROM world WHERE id = " ~ id.to!string;
155155
ResultSet rs = dbConnection.query(query);
156156

@@ -168,7 +168,7 @@ class DemoProcessor : HttpProcessor {
168168

169169
JSONValue[] arr = new JSONValue[queries];
170170
for (int i = 0; i < queries; i++) {
171-
immutable id = uniform(1, 10000);
171+
immutable id = uniform(1, 10001);
172172
immutable query = "SELECT randomNumber FROM world WHERE id = " ~ id.to!string;
173173
ResultSet rs = dbConnection.query(query);
174174

@@ -224,14 +224,14 @@ class DemoProcessor : HttpProcessor {
224224

225225
JSONValue[] arr = new JSONValue[queries];
226226
for (int i = 0; i < queries; i++) {
227-
immutable id = uniform(1, 10000);
227+
immutable id = uniform(1, 10001);
228228
immutable idString = id.to!string;
229229
immutable query = "SELECT randomNumber FROM world WHERE id = " ~ idString;
230230
ResultSet rs = dbConnection.query(query);
231231
int randomNumber = to!int(rs.front()[0]);
232232
debug tracef("id=%d, randomNumber=%d", id, randomNumber);
233233

234-
randomNumber = uniform(1, 10000);
234+
randomNumber = uniform(1, 10001);
235235
string updateSql = "UPDATE world SET randomNumber = "
236236
~ randomNumber.to!string ~ " WHERE id = " ~ idString;
237237
int r = dbConnection.execute(updateSql);

frameworks/D/hunt/source/http/HttpURI.d renamed to frameworks/D/hunt/http/http/HttpURI.d

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module http.HttpURI;
22

3-
version(HTTP) :
3+
44

55
import hunt.collection.MultiMap;
66

frameworks/D/hunt/source/http/Parser.d renamed to frameworks/D/hunt/http/http/Parser.d

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
/// Used for benchmarks with simple server
33
module http.Parser;
44

5-
version(HTTP) :
5+
66

77
private:
88

frameworks/D/hunt/source/http/Processor.d renamed to frameworks/D/hunt/http/http/Processor.d

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
///
33
module http.Processor;
44

5-
version(HTTP) :
5+
66

77
import std.array, std.exception, std.format, std.algorithm.mutation, std.socket;
88
import core.stdc.stdlib;

frameworks/D/hunt/source/http/Server.d renamed to frameworks/D/hunt/http/http/Server.d

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module http.Server;
22

3-
version(HTTP) :
3+
44

55
import hunt.event;
66
import hunt.io;

frameworks/D/hunt/source/http/UrlEncoded.d renamed to frameworks/D/hunt/http/http/UrlEncoded.d

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module http.UrlEncoded;
22

3-
version(HTTP) :
3+
44

55
import hunt.collection.List;
66
import hunt.collection.MultiMap;

frameworks/D/hunt/hunt-dmd.dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@ RUN git clone https://github.com/h2o/picohttpparser.git && \
1212
cd ..
1313

1414
RUN dub upgrade --verbose
15-
RUN dub build --build=release --arch=x86_64 --compiler=dmd -c=minihttp
15+
RUN dub build --build=release --arch=x86_64 --compiler=dmd -c=mmap -f
1616

1717
CMD ["./hunt-minihttp"]

0 commit comments

Comments
 (0)