Skip to content

Commit d735d6d

Browse files
authored
Vibe.d code improvements (Dlang) (#9982)
* Vibe.d code improvements (Dlang) * Vibe.d: sporadic fortunes test failures fix
1 parent 36edf86 commit d735d6d

File tree

4 files changed

+45
-60
lines changed

4 files changed

+45
-60
lines changed

frameworks/D/vibed/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ This is the Vibe.D portion of a benchmarking test suite comparing a variety of w
1212

1313
## Infrastructure Software Versions
1414
The tests were run with:
15-
* [Vibe.D v0.9.4](http://vibed.org/)
15+
* [Vibe.D v0.10.2](http://vibed.org/)
1616

1717
## Test URLs
1818
### JSON Encoding Test

frameworks/D/vibed/dub.json

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,13 @@
77
"Sönke Ludwig"
88
],
99
"dependencies": {
10-
"vibe-d": "0.9.5",
11-
"mir-random": "2.2.15",
12-
"vibe-d:tls": "0.9.5"
10+
"vibe-d": "0.10.2",
11+
"mir-random": "2.2.20",
12+
"vibe-d:tls": "0.10.2"
1313
},
1414
"targetType": "executable",
1515
"sourcePaths": [],
1616
"subConfigurations": {
17-
"vibe-d": "vibe-core",
1817
"vibe-d:tls": "notls"
1918
},
2019
"versions": [
@@ -30,11 +29,8 @@
3029
"name": "postgresql",
3130
"mainSourceFile": "source/postgresql.d",
3231
"dependencies": {
33-
"vibe-d-postgresql": "3.1.0-rc.1",
34-
"dpq2": "1.0.17"
35-
},
36-
"subConfigurations": {
37-
"dpq2": "dynamic"
32+
"vibe-d-postgresql": "3.2.0-rc1",
33+
"dpq2": "1.2.3"
3834
}
3935
}
4036
],
Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,28 @@
11
{
22
"fileVersion": 1,
33
"versions": {
4-
"botan": "1.12.19",
5-
"botan-math": "1.0.3",
64
"derelict-pq": "4.0.0",
75
"derelict-util": "3.0.0-beta.2",
8-
"diet-ng": "1.8.1",
9-
"dpq2": "1.0.17",
10-
"eventcore": "0.9.20",
11-
"libasync": "0.8.6",
12-
"memutils": "1.0.4",
13-
"mir-algorithm": "3.14.19",
14-
"mir-core": "1.1.111",
15-
"mir-linux-kernel": "1.0.1",
16-
"mir-random": "2.2.15",
17-
"money": "2.3.1",
18-
"openssl": "3.2.2",
6+
"diet-ng": "1.8.4",
7+
"dpq2": "1.2.3",
8+
"eventcore": "0.9.36",
9+
"mir-algorithm": "3.22.4",
10+
"mir-core": "1.7.3",
11+
"mir-linux-kernel": "1.2.1",
12+
"mir-random": "2.2.20",
13+
"money": "3.0.2",
14+
"openssl": "3.3.4",
15+
"openssl-static": "1.0.5+3.0.8",
1916
"silly": "1.1.1",
2017
"stdx-allocator": "2.77.5",
21-
"taggedalgebraic": "0.11.22",
22-
"vibe-core": "1.22.4",
23-
"vibe-d": "0.9.5",
24-
"vibe-d-postgresql": "3.1.0-rc.1"
18+
"taggedalgebraic": "1.0.0",
19+
"vibe-container": "1.6.2",
20+
"vibe-core": "2.12.0",
21+
"vibe-d": "0.10.2",
22+
"vibe-d-postgresql": "3.2.0-rc1",
23+
"vibe-http": "1.2.2",
24+
"vibe-inet": "1.1.3",
25+
"vibe-serialization": "1.0.7",
26+
"vibe-stream": "1.1.1"
2527
}
2628
}

frameworks/D/vibed/source/postgresql.d

Lines changed: 20 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -16,23 +16,27 @@ enum poolSize = 64;
1616

1717
PostgresClient client;
1818

19-
shared static this()
20-
{
21-
import derelict.pq.pq;
22-
import derelict.util.exception : ShouldThrow;
23-
ShouldThrow myMissingSymCB( string symbolName ) { return ShouldThrow.No; }
24-
DerelictPQ.missingSymbolCallback = &myMissingSymCB;
25-
}
26-
2719
void main()
2820
{
29-
runWorkerTaskDist(&runServer);
30-
runApplication();
31-
}
21+
auto connectionInfo = "host=tfb-database port=5432 "
22+
~ "dbname=hello_world user=benchmarkdbuser password=benchmarkdbpass";
23+
24+
client = new PostgresClient(connectionInfo, poolSize, (Connection cn){
25+
cn.prepareEx("fortune_prpq", "SELECT id, message::text FROM Fortune");
26+
cn.prepareEx("db_prpq", "SELECT randomNumber, id FROM world WHERE id = $1");
27+
cn.prepareEx("db_update_prpq", "UPDATE world SET randomNumber = $1 WHERE id = $2");
28+
} );
29+
30+
{
31+
// Establishing each connection in the pool and performing the PREPARE procedures
32+
LockedConnection[poolSize] conns;
33+
34+
foreach(ref c; conns)
35+
c = client.lockConnection();
36+
}
3237

33-
void runServer()
34-
{
3538
import std.datetime : seconds;
39+
3640
auto router = new URLRouter;
3741
router.registerWebInterface(new WebInterface);
3842
router.rebuild();
@@ -42,6 +46,7 @@ void runServer()
4246
settings.options |= HTTPServerOption.reusePort;
4347
settings.port = 8080;
4448
listenHTTP(settings, router);
49+
runEventLoop();
4550
}
4651

4752
class WebInterface {
@@ -79,7 +84,6 @@ class WebInterface {
7984
int id = _uniformVariable(_gen);
8085
QueryParams qp;
8186
qp.preparedStatementName("db_prpq");
82-
qp.resultFormat = ValueFormat.BINARY;
8387
qp.argsVariadic(id);
8488
immutable result = conn.execPrepared(qp).rangify.front;
8589
auto w = WorldResponse(id, result[0].as!PGinteger);
@@ -109,11 +113,9 @@ class WebInterface {
109113
scope data = new WorldResponse[count];
110114
QueryParams qp;
111115
qp.preparedStatementName("db_prpq");
112-
qp.resultFormat = ValueFormat.BINARY;
113116
foreach (ref w; data) {
114117
int id = _uniformVariable(_gen);
115118
qp.argsVariadic(id);
116-
immutable query = "SELECT randomNumber, id FROM world WHERE id = " ~ id.to!string;
117119
immutable result = conn.execPrepared(qp).rangify.front;
118120
w = WorldResponse(id, result[0].as!PGinteger);
119121
}
@@ -147,7 +149,6 @@ class WebInterface {
147149
import std.uni : isNumber;
148150

149151
auto conn = client.lockConnection();
150-
scope(exit) destroy(conn);
151152

152153
int count = 1;
153154
if (queries.length && isNumber(queries[0]))
@@ -159,24 +160,22 @@ class WebInterface {
159160
scope data = new WorldResponse[count];
160161
QueryParams qp;
161162
qp.preparedStatementName("db_prpq");
162-
qp.resultFormat = ValueFormat.BINARY;
163163

164164
QueryParams qp_update;
165165
qp_update.preparedStatementName("db_update_prpq");
166-
qp_update.resultFormat = ValueFormat.BINARY;
167166

168167
foreach (ref w; data) {
169168
int id = _uniformVariable(_gen);
170169
qp.argsVariadic(id);
171-
immutable query = "SELECT id, randomNumber FROM world WHERE id = " ~ id.to!string;
172170
immutable result = conn.execPrepared(qp).rangify.front;
173171
w = WorldResponse(id, result[0].as!PGinteger);
174172

175173
// update random number
176174
w.randomNumber = _uniformVariable(_gen);
177175
qp_update.argsVariadic(w.randomNumber, id);
176+
178177
// persist to DB
179-
conn.sendQueryPrepared(qp_update);
178+
conn.execPrepared(qp_update);
180179
}
181180

182181
// write response as JSON
@@ -203,15 +202,3 @@ struct FortuneResponse {
203202
int id;
204203
string message;
205204
}
206-
207-
static this()
208-
{
209-
import std.process : environment;
210-
auto connectionInfo = "host=tfb-database port=5432 "
211-
~ "dbname=hello_world user=benchmarkdbuser password=benchmarkdbpass";
212-
client = new PostgresClient(connectionInfo, poolSize, (Connection cn){
213-
cn.prepare("fortune_prpq", "SELECT id, message::text FROM Fortune");
214-
cn.prepare("db_prpq", "SELECT randomNumber, id FROM world WHERE id = $1");
215-
cn.prepare("db_update_prpq", "UPDATE world SET randomNumber = $1 WHERE id = $2");
216-
} );
217-
}

0 commit comments

Comments
 (0)