Browse Source

Merge pull request #1671 from TechEmpower/vibed

Implemented vibed for a master release
Mike Smith 10 years ago
parent
commit
e01d6faba5

+ 1 - 0
.travis.yml

@@ -38,6 +38,7 @@ env:
     - "TESTDIR=Clojure/aleph"
     - "TESTDIR=Crystal/crystal-raw"
     - "TESTDIR=Crystal/moonshine"
+    - "TESTDIR=D/vibed"
     - "TESTDIR=Dart/dart"
     - "TESTDIR=Dart/dart-redstone"
     - "TESTDIR=Dart/dart-start"

+ 7 - 0
frameworks/D/vibed/.gitignore

@@ -0,0 +1,7 @@
+.dub
+docs.json
+__dummy.html
+*.o
+*.obj
+*.dll
+*.exe

+ 34 - 0
frameworks/D/vibed/README.md

@@ -0,0 +1,34 @@
+# Vibe.D Benchmarking Test
+
+This is the Vibe.D portion of a [benchmarking test suite](../) comparing a variety of web development platforms.
+
+### JSON Encoding Test
+
+* [JSON test controller/view](source/app.d)
+
+### Data-Store/Database Mapping Test
+
+* [DB test controller/model](source/app.d)
+
+## Infrastructure Software Versions
+The tests were run with:
+* [Vibe.D v0.7.19](http://vibed.org/)
+
+## Test URLs
+### JSON Encoding Test
+
+http://localhost:8080/json
+
+### Plaintext Test
+
+http://localhost:8080/plaintext
+
+### Data-Store/Database Mapping Test
+
+MongoRaw:
+http://localhost:8080/db
+
+### Variable Query Test
+
+MongoDB Raw:
+http://localhost:8080/queries?queries=5

+ 26 - 0
frameworks/D/vibed/benchmark_config.json

@@ -0,0 +1,26 @@
+{
+  "framework": "vibed",
+  "tests": [{
+    "default": {
+      "setup_file": "setup",
+      "json_url": "/json",
+      "db_url": "/db",
+      "query_url": "/queries?queries=",
+      "plaintext_url": "/plaintext",
+      "port": 8080,
+      "approach": "Realistic",
+      "classification": "Platform",
+      "database": "MongoDB",
+      "framework": "vibed",
+      "language": "D",
+      "orm": "Raw",
+      "platform": "D",
+      "webserver": "None",
+      "os": "Linux",
+      "database_os": "Linux",
+      "display_name": "Vibe.D",
+      "notes": "",
+      "versus": "vibed"
+    }
+  }]
+}

+ 10 - 0
frameworks/D/vibed/dub.json

@@ -0,0 +1,10 @@
+{
+  "name": "fwb",
+  "description": "A simple vibe.d server application.",
+  "copyright": "Copyright © 2015, jin",
+  "authors": ["jin"],
+  "dependencies": {
+    "vibe-d": "~>0.7.19"
+  },
+  "versions": ["VibeDefaultMain"]
+}

+ 11 - 0
frameworks/D/vibed/dub.selections.json

@@ -0,0 +1,11 @@
+{
+  "fileVersion": 1,
+  "versions": {
+    "memutils": "0.3.5",
+    "vibe-d": "0.7.23",
+    "libevent": "2.0.1+2.0.16",
+    "openssl": "1.1.4+1.0.1g",
+    "libev": "5.0.0+4.04",
+    "libasync": "0.7.1"
+  }
+}

+ 3 - 0
frameworks/D/vibed/install.sh

@@ -0,0 +1,3 @@
+#!/bin/bash
+
+fw_depends dlang dub

+ 14 - 0
frameworks/D/vibed/setup.sh

@@ -0,0 +1,14 @@
+#!/bin/bash
+
+source $IROOT/dlang.installed
+source $IROOT/dub.installed
+
+sed -i 's|127.0.0.1|'"${DBHOST}"'|g' source/app.d
+
+# Clean any files from last run
+rm -f fwb
+rm -rf .dub
+
+dub build --force
+
+./fwb &

+ 102 - 0
frameworks/D/vibed/source/app.d

@@ -0,0 +1,102 @@
+import vibe.appmain;
+import vibe.d;
+import std.random;
+
+const worldSize = 10000;
+const fortunesSize = 100;
+const mongoUrl = "mongodb://127.0.0.1/";
+
+MongoClient mongo;
+MongoCollection worldCollection;
+MongoCollection fortunesCollection;
+
+shared static this()
+{
+  mongo = connectMongoDB( mongoUrl );
+  worldCollection = mongo.getCollection( "hello_world.World" );
+  fortunesCollection = mongo.getCollection( "hello_world.Fortunes" );
+
+  auto router = new URLRouter;
+  router.get("/plaintext", &plaintext);
+  router.get("/json", &json);
+  router.get("/db", &db);
+  router.get("/queries", &queries);
+  router.get("/generate-world", &generateWorld);
+  router.get("/generate-fortunes", &generateFortunes);
+  router.get("/", staticTemplate!"index.dt");
+
+  auto settings = new HTTPServerSettings;
+  settings.port = 8080;
+
+  listenHTTP(settings, router);
+}
+
+void json(HTTPServerRequest req, HTTPServerResponse res)
+{
+  auto helloWorld  = Json([
+    "message" : *new Json( "Hello, World!" )
+  ]);
+  res.writeJsonBody( helloWorld );
+}
+
+void generateWorld(HTTPServerRequest req, HTTPServerResponse res)
+{
+  try {
+    worldCollection.drop();
+  } catch( Exception error ) {}
+  for( auto i = 0 ; i < worldSize ; ++i ) {
+    worldCollection.insert([
+      "_id": i + 1,
+      "randomNumber": uniform( 0 , worldSize )
+    ]);
+  }
+  res.writeBody( "Generated" );
+}
+
+void generateFortunes(HTTPServerRequest req, HTTPServerResponse res)
+{
+  try {
+    fortunesCollection.drop();
+  } catch( Exception error ) {}
+  for( uint i = 0 ; i < worldSize ; ++i ) {
+    fortunesCollection.insert([
+      "_id": new Bson( i + 1 ),
+      "message": new Bson( to!string( uniform( 0 , fortunesSize ) ) )
+    ]);
+  }
+  res.writeBody( "Generated" );
+}
+
+void db(HTTPServerRequest req, HTTPServerResponse res)
+{
+  auto data = worldCollection.findOne([
+    "_id": uniform( 1 , worldSize + 1 )
+  ]); 
+  res.writeJsonBody( data );
+}
+
+void queries(HTTPServerRequest req, HTTPServerResponse res)
+{
+  auto count = 1;
+  try {
+    count = to!uint( req.query["queries"] );
+    if( !count ) {
+      count = 1;
+    } else if( count > 500 ) {
+      count = 500;
+    }
+  } catch( Exception error ) { }
+  
+  auto data = new Bson[ count ];
+  for( uint i = 0 ; i < count ; ++i ) {
+    data[i] = worldCollection.findOne([
+      "_id": uniform( 1 , worldSize + 1 )
+    ]);
+  }
+  res.writeJsonBody( data );
+}
+
+void plaintext(HTTPServerRequest req, HTTPServerResponse res)
+{
+  res.writeBody("Hello, World!");
+}

+ 19 - 0
frameworks/D/vibed/views/index.dt

@@ -0,0 +1,19 @@
+doctype html
+html
+  head
+    style a { display: block }
+  body
+    ul
+      li
+        a(href="/generate-world") generate world
+      li
+        a(href="/generate-fortunes") generate fortunes
+    ol
+      li
+        a(href="/json") json stringify
+      li
+        a(href="/db") single query
+      li
+        a(href="/queries?queries=5") multiple queries
+      li
+        a(href="/plaintext") plain text

+ 26 - 0
toolset/setup/linux/languages/dlang.sh

@@ -0,0 +1,26 @@
+#!/bin/bash
+
+DLANG=$IROOT/dlang
+RETCODE=$(fw_exists ${DLANG}.installed)
+[ ! "$RETCODE" == 0 ] || { \
+  source $DLANG.installed
+  return 0; }
+
+mkdir -p $DLANG
+fw_get http://downloads.dlang.org/releases/2.x/2.067.1/dmd_2.067.1-0_amd64.deb
+dpkg-deb -x dmd_2.067.1-0_amd64.deb $DLANG
+
+# According to this file (dmd.conf) dmd will, upon execution, look for
+# a dmd.conf in 1) the current working directory [bad], 2) the directory
+# specified by the HOME environment variable [bad], 3) the directory in
+# which dmd resides [less bad], and 4) the /etc directory.
+# We are trying to maintain as little global presence as possible, so
+# we need to change the DFLAGS in the dmd.conf to be correctly sandboxed
+# to the $DLANG folder (in IROOT).
+cp $DLANG/etc/dmd.conf $DLANG/usr/bin
+sed -i "s|-I/usr/|-I${DLANG}/usr/|g" $DLANG/usr/bin/dmd.conf
+sed -i "s|-L/usr/|-L${DLANG}/usr/|g" $DLANG/usr/bin/dmd.conf
+
+echo -e "export PATH=${DLANG}/usr/bin:\$PATH" > $DLANG.installed
+
+source $DLANG.installed

+ 2 - 1
toolset/setup/linux/prerequisites.sh

@@ -44,7 +44,8 @@ sudo apt-get -qqy install -o Dpkg::Options::="--force-confdef" -o Dpkg::Options:
   cloc dstat                        `# Collect resource usage statistics` \
   libsasl2-dev                      `# Needed by mgo for go-mongodb test` \
   llvm-dev                          `# Required for correct Ruby installation` \
-  libboost-dev                      `# Silicon relies on boost::lexical_cast.`
+  libboost-dev                      `# Silicon relies on boost::lexical_cast.` \
+  xdg-utils                         `# Needed by dlang.`
 
 # Install gcc-4.8 and gcc-4.9
 sudo add-apt-repository ppa:ubuntu-toolchain-r/test -y

+ 16 - 0
toolset/setup/linux/systools/dub.sh

@@ -0,0 +1,16 @@
+#!/bin/bash
+
+DUB=$IROOT/dub
+RETCODE=$(fw_exists ${DUB}.installed)
+[ ! "$RETCODE" == 0 ] || { \
+  source $DUB.installed
+  return 0; }
+
+mkdir dub
+cd dub
+fw_get http://code.dlang.org/files/dub-0.9.23-linux-x86_64.tar.gz
+fw_untar dub-0.9.23-linux-x86_64.tar.gz
+
+echo -e "export PATH=${DUB}:\$PATH" > $DUB.installed
+
+source $DUB.installed