Browse Source

Upgrade/modernize vibe.d test (#2916)

* Upgrade dependencies.

* Modernize code.

- separate data structures for each thread
- runApplication instead of static constructor

* Fix file permissions.

* Use manual memory management mode to reduce GC pressure.
Sönke Ludwig 8 years ago
parent
commit
62a936287d
3 changed files with 31 additions and 21 deletions
  1. 3 3
      frameworks/D/vibed/dub.json
  2. 7 5
      frameworks/D/vibed/dub.selections.json
  3. 21 13
      frameworks/D/vibed/setup.sh

+ 3 - 3
frameworks/D/vibed/dub.json

@@ -4,13 +4,13 @@
   "copyright": "Copyright © 2015, jin",
   "copyright": "Copyright © 2015, jin",
   "authors": ["jin", "Sönke Ludwig"],
   "authors": ["jin", "Sönke Ludwig"],
   "dependencies": {
   "dependencies": {
-    "vibe-d": "~>0.8.0-beta",
-    "vibe-core": "~>1.0.0-beta"
+    "vibe-d": "~>0.8.0",
+    "vibe-core": "~>1.0.0"
   },
   },
-  "versions": ["VibeDefaultMain"],
   "targetType": "executable",
   "targetType": "executable",
   "sourcePaths": [],
   "sourcePaths": [],
   "subConfigurations": {"vibe-d": "vibe-core"},
   "subConfigurations": {"vibe-d": "vibe-core"},
+  "versions": ["VibeManualMemoryManagement"],
   "configurations": [
   "configurations": [
   	{
   	{
   		"name": "mongodb",
   		"name": "mongodb",

+ 7 - 5
frameworks/D/vibed/dub.selections.json

@@ -1,14 +1,16 @@
 {
 {
 	"fileVersion": 1,
 	"fileVersion": 1,
 	"versions": {
 	"versions": {
-		"diet-ng": "1.2.0",
-		"eventcore": "0.8.10",
+		"botan": "1.12.9",
+		"botan-math": "1.0.3",
+		"diet-ng": "1.2.1",
+		"eventcore": "0.8.12",
 		"libasync": "0.8.3",
 		"libasync": "0.8.3",
 		"libevent": "2.0.2+2.0.16",
 		"libevent": "2.0.2+2.0.16",
 		"memutils": "0.4.9",
 		"memutils": "0.4.9",
 		"openssl": "1.1.5+1.0.1g",
 		"openssl": "1.1.5+1.0.1g",
-		"taggedalgebraic": "0.10.5",
-		"vibe-core": "1.0.0-beta.5",
-		"vibe-d": "0.8.0-beta.5"
+		"taggedalgebraic": "0.10.7",
+		"vibe-core": "1.0.0",
+		"vibe-d": "0.8.0"
 	}
 	}
 }
 }

+ 21 - 13
frameworks/D/vibed/setup.sh

@@ -1,3 +1,4 @@
+import vibe.core.core;
 import vibe.db.mongo.mongo;
 import vibe.db.mongo.mongo;
 import vibe.http.router;
 import vibe.http.router;
 import vibe.http.server;
 import vibe.http.server;
@@ -10,31 +11,38 @@ import std.array;
 enum worldSize = 10000;
 enum worldSize = 10000;
 
 
 
 
-shared static this()
+void main()
+{
+	runWorkerTaskDist(&runServer);
+	runApplication();
+}
+
+void runServer()
 {
 {
 	auto router = new URLRouter;
 	auto router = new URLRouter;
 	router.registerWebInterface(new WebInterface);
 	router.registerWebInterface(new WebInterface);
 	router.rebuild();
 	router.rebuild();
 
 
 	auto settings = new HTTPServerSettings;
 	auto settings = new HTTPServerSettings;
-	settings.options |= HTTPServerOption.distribute;
+	settings.options |= HTTPServerOption.reusePort;
 	settings.port = 8080;
 	settings.port = 8080;
 	listenHTTP(settings, router);
 	listenHTTP(settings, router);
 }
 }
 
 
-MongoCollection _worldCollection;
-MongoCollection _fortuneCollection;
+class WebInterface {
+	private {
+		MongoCollection _worldCollection;
+		MongoCollection _fortuneCollection;
+	}
 
 
-// sets up the MongoDB connection pools for each thread
-static this()
-{
-	import std.process : environment;
-	auto db = connectMongoDB(environment["DBHOST"]);
-	_worldCollection = db.getCollection("hello_world.world");
-	_fortuneCollection = db.getCollection("hello_world.fortune");
-}
+	this()
+	{
+		import std.process : environment;
+		auto db = connectMongoDB(environment.get("DBHOST", "127.0.0.1"));
+		_worldCollection = db.getCollection("hello_world.world");
+		_fortuneCollection = db.getCollection("hello_world.fortune");
+	}
 
 
-class WebInterface {
 	// GET /
 	// GET /
 	void get()
 	void get()
 	{
 	{