浏览代码

Vibe.d code improvements (Dlang) (#9982)

* Vibe.d code improvements (Dlang)

* Vibe.d: sporadic fortunes test failures fix
Denis Feklushkin 2 月之前
父节点
当前提交
d735d6d208

+ 1 - 1
frameworks/D/vibed/README.md

@@ -12,7 +12,7 @@ This is the Vibe.D portion of a benchmarking test suite comparing a variety of w
 
 ## Infrastructure Software Versions
 The tests were run with:
-* [Vibe.D v0.9.4](http://vibed.org/)
+* [Vibe.D v0.10.2](http://vibed.org/)
 
 ## Test URLs
 ### JSON Encoding Test

+ 5 - 9
frameworks/D/vibed/dub.json

@@ -7,14 +7,13 @@
     "Sönke Ludwig"
   ],
   "dependencies": {
-    "vibe-d": "0.9.5",
-    "mir-random": "2.2.15",
-    "vibe-d:tls": "0.9.5"
+    "vibe-d": "0.10.2",
+    "mir-random": "2.2.20",
+    "vibe-d:tls": "0.10.2"
   },
   "targetType": "executable",
   "sourcePaths": [],
   "subConfigurations": {
-    "vibe-d": "vibe-core",
     "vibe-d:tls": "notls"
   },
   "versions": [
@@ -30,11 +29,8 @@
       "name": "postgresql",
       "mainSourceFile": "source/postgresql.d",
       "dependencies": {
-        "vibe-d-postgresql": "3.1.0-rc.1",
-        "dpq2": "1.0.17"
-      },
-      "subConfigurations": {
-        "dpq2": "dynamic"
+        "vibe-d-postgresql": "3.2.0-rc1",
+        "dpq2": "1.2.3"
       }
     }
   ],

+ 19 - 17
frameworks/D/vibed/dub.selections.json

@@ -1,26 +1,28 @@
 {
 	"fileVersion": 1,
 	"versions": {
-		"botan": "1.12.19",
-		"botan-math": "1.0.3",
 		"derelict-pq": "4.0.0",
 		"derelict-util": "3.0.0-beta.2",
-		"diet-ng": "1.8.1",
-		"dpq2": "1.0.17",
-		"eventcore": "0.9.20",
-		"libasync": "0.8.6",
-		"memutils": "1.0.4",
-		"mir-algorithm": "3.14.19",
-		"mir-core": "1.1.111",
-		"mir-linux-kernel": "1.0.1",
-		"mir-random": "2.2.15",
-		"money": "2.3.1",
-		"openssl": "3.2.2",
+		"diet-ng": "1.8.4",
+		"dpq2": "1.2.3",
+		"eventcore": "0.9.36",
+		"mir-algorithm": "3.22.4",
+		"mir-core": "1.7.3",
+		"mir-linux-kernel": "1.2.1",
+		"mir-random": "2.2.20",
+		"money": "3.0.2",
+		"openssl": "3.3.4",
+		"openssl-static": "1.0.5+3.0.8",
 		"silly": "1.1.1",
 		"stdx-allocator": "2.77.5",
-		"taggedalgebraic": "0.11.22",
-		"vibe-core": "1.22.4",
-		"vibe-d": "0.9.5",
-		"vibe-d-postgresql": "3.1.0-rc.1"
+		"taggedalgebraic": "1.0.0",
+		"vibe-container": "1.6.2",
+		"vibe-core": "2.12.0",
+		"vibe-d": "0.10.2",
+		"vibe-d-postgresql": "3.2.0-rc1",
+		"vibe-http": "1.2.2",
+		"vibe-inet": "1.1.3",
+		"vibe-serialization": "1.0.7",
+		"vibe-stream": "1.1.1"
 	}
 }

+ 20 - 33
frameworks/D/vibed/source/postgresql.d

@@ -16,23 +16,27 @@ enum poolSize = 64;
 
 PostgresClient client;
 
-shared static this()
-{
-	import derelict.pq.pq;
-	import derelict.util.exception : ShouldThrow;
-	ShouldThrow myMissingSymCB( string symbolName ) { return ShouldThrow.No; }
-	DerelictPQ.missingSymbolCallback = &myMissingSymCB;
-}
-
 void main()
 {
-	runWorkerTaskDist(&runServer);
-	runApplication();
-}
+	auto connectionInfo = "host=tfb-database port=5432 "
+						~ "dbname=hello_world  user=benchmarkdbuser password=benchmarkdbpass";
+
+	client = new PostgresClient(connectionInfo, poolSize, (Connection cn){
+		cn.prepareEx("fortune_prpq", "SELECT id, message::text FROM Fortune");
+		cn.prepareEx("db_prpq", "SELECT randomNumber, id FROM world WHERE id = $1");
+		cn.prepareEx("db_update_prpq", "UPDATE world SET randomNumber = $1  WHERE id = $2");
+	} );
+
+	{
+		// Establishing each connection in the pool and performing the PREPARE procedures
+		LockedConnection[poolSize] conns;
+
+		foreach(ref c; conns)
+			c = client.lockConnection();
+	}
 
-void runServer()
-{
 	import std.datetime : seconds;
+
 	auto router = new URLRouter;
 	router.registerWebInterface(new WebInterface);
 	router.rebuild();
@@ -42,6 +46,7 @@ void runServer()
 	settings.options |= HTTPServerOption.reusePort;
 	settings.port = 8080;
 	listenHTTP(settings, router);
+	runEventLoop();
 }
 
 class WebInterface {
@@ -79,7 +84,6 @@ class WebInterface {
 		int id = _uniformVariable(_gen);
 		QueryParams qp;
 		qp.preparedStatementName("db_prpq");
-		qp.resultFormat = ValueFormat.BINARY;
 		qp.argsVariadic(id);
 		immutable result = conn.execPrepared(qp).rangify.front;
 		auto w = WorldResponse(id, result[0].as!PGinteger);
@@ -109,11 +113,9 @@ class WebInterface {
 		scope data = new WorldResponse[count];
 		QueryParams qp;
 		qp.preparedStatementName("db_prpq");
-		qp.resultFormat = ValueFormat.BINARY;
 		foreach (ref w; data) {
 			int id = _uniformVariable(_gen);
 			qp.argsVariadic(id);
-			immutable query = "SELECT randomNumber, id FROM world WHERE id = " ~  id.to!string;
 			immutable result = conn.execPrepared(qp).rangify.front;
 			w = WorldResponse(id, result[0].as!PGinteger);
 		}
@@ -147,7 +149,6 @@ class WebInterface {
 		import std.uni : isNumber;
 
 		auto conn = client.lockConnection();
-		scope(exit)	destroy(conn);
 
 		int count = 1;
 		if (queries.length && isNumber(queries[0]))
@@ -159,24 +160,22 @@ class WebInterface {
 		scope data = new WorldResponse[count];
 		QueryParams qp;
 		qp.preparedStatementName("db_prpq");
-		qp.resultFormat = ValueFormat.BINARY;
 
 		QueryParams qp_update;
 		qp_update.preparedStatementName("db_update_prpq");
-		qp_update.resultFormat = ValueFormat.BINARY;
 
 		foreach (ref w; data) {
 			int id = _uniformVariable(_gen);
 			qp.argsVariadic(id);
-			immutable query = "SELECT id, randomNumber FROM world WHERE id = " ~  id.to!string;
 			immutable result = conn.execPrepared(qp).rangify.front;
 			w = WorldResponse(id, result[0].as!PGinteger);
 
 			// update random number
 			w.randomNumber = _uniformVariable(_gen);
 			qp_update.argsVariadic(w.randomNumber, id);
+
 			// persist to DB
-			conn.sendQueryPrepared(qp_update);
+			conn.execPrepared(qp_update);
 		}
 
 		// write response as JSON
@@ -203,15 +202,3 @@ struct FortuneResponse {
 	int id;
 	string message;
 }
-
-static this()
-{
-	import std.process : environment;
-	auto connectionInfo = "host=tfb-database port=5432 "
-						~ "dbname=hello_world  user=benchmarkdbuser password=benchmarkdbpass";
-	client = new PostgresClient(connectionInfo, poolSize, (Connection cn){
-		cn.prepare("fortune_prpq", "SELECT id, message::text FROM Fortune");
-		cn.prepare("db_prpq", "SELECT randomNumber, id FROM world WHERE id = $1");
-		cn.prepare("db_update_prpq", "UPDATE world SET randomNumber = $1  WHERE id = $2");
-	} );
-}