Browse Source

Updated Wt to 4.0.2 (#3093)

Roel Standaert 7 years ago
parent
commit
175c5d542a

+ 66 - 56
frameworks/C++/wt/benchmark.cpp

@@ -1,28 +1,30 @@
 #include <signal.h>
 #include <cstdlib>
+#include <cstring>
 #include <string>
 #include <vector>
 #include <algorithm>
-#include <mutex>
 
-#include <Wt/WServer>
-#include <Wt/WResource>
-#include <Wt/Http/Request>
-#include <Wt/Http/Response>
-#include <Wt/WTemplate>
-#include <Wt/Utils>
+#include <Wt/WServer.h>
+#include <Wt/WResource.h>
+#include <Wt/Http/Request.h>
+#include <Wt/Http/Response.h>
+#include <Wt/WTemplate.h>
+#include <Wt/Utils.h>
 
-#include <Wt/Dbo/Dbo>
-#include <Wt/Dbo/Json>
+#include <Wt/Dbo/Dbo.h>
+#include <Wt/Dbo/Json.h>
 #ifndef BENCHMARK_USE_POSTGRES
-#include <Wt/Dbo/backend/MySQL>
+#include <Wt/Dbo/backend/MySQL.h>
 #else
-#include <Wt/Dbo/backend/Postgres>
+#include <Wt/Dbo/backend/Postgres.h>
 #endif
 
-#include <boost/random/uniform_int_distribution.hpp>
-#include <boost/random/taus88.hpp>
-#include <boost/thread/tss.hpp>
+#include <random>
+
+#ifndef WT_WIN32
+extern char **environ;
+#endif // WT_WIN32
 
 class MyMessage {
 public:
@@ -113,20 +115,29 @@ public:
 };
 
 struct DbStruct {
-  MyConnection connection;
+  MyConnection *connection;
   Wt::Dbo::Session session;
 
-  boost::taus88 rng;
-  boost::random::uniform_int_distribution<int> distribution;
+  std::default_random_engine rng;
+  std::uniform_int_distribution<int> distribution;
 
+  DbStruct()
+    : connection(0),
+      rng(clock()),
+      distribution(1, 10000) {
+    std::string dbHostStr = "localhost";
+    char *dbHost = std::getenv("DBHOST");
+    if (dbHost)
+      dbHostStr = std::string(dbHost);
 #ifndef BENCHMARK_USE_POSTGRES
-  DbStruct() : connection("hello_world", "benchmarkdbuser", "benchmarkdbpass", "INSERT_DB_HOST_HERE", 3306),
+    auto c = Wt::cpp14::make_unique<MyConnection>("hello_world", "benchmarkdbuser", "benchmarkdbpass", dbHostStr, 3306);
 #else
-  DbStruct() : connection("host=INSERT_DB_HOST_HERE port=5432 user=benchmarkdbuser password=benchmarkdbpass dbname=hello_world"),
+    auto connStr = std::string("host=") + dbHostStr + " port=5432 user=benchmarkdbuser password=benchmarkdbpass dbname=hello_world";
+    auto c = Wt::cpp14::make_unique<MyConnection>(connStr);
 #endif
-      rng(clock()),
-      distribution(1, 10000) {
-    session.setConnection(connection);
+
+    connection = c.get();
+    session.setConnection(std::move(c));
     session.mapClass<World>("world");
     session.mapClass<Fortune>("fortune");
   }
@@ -137,7 +148,7 @@ struct DbStruct {
 };
 
 namespace {
-  boost::thread_specific_ptr<DbStruct> dbStruct_;
+  thread_local DbStruct *dbStruct_;
 }
 
 class DbResource : public Wt::WResource {
@@ -146,14 +157,12 @@ public:
     response.setMimeType("application/json");
     response.addHeader("Server", "Wt");
 
-    DbStruct* db = dbStruct_.get();
-    if (!db) {
-      db = new DbStruct();
-      dbStruct_.reset(db);
+    if (!dbStruct_) {
+      dbStruct_ = new DbStruct();
     }
 
-    Wt::Dbo::Transaction transaction(db->session);
-    Wt::Dbo::ptr<World> entry = db->session.load<World>(db->rand());
+    Wt::Dbo::Transaction transaction(dbStruct_->session);
+    Wt::Dbo::ptr<World> entry = dbStruct_->session.load<World>(dbStruct_->rand());
     
     Wt::Dbo::JsonSerializer writer(response.out());
     writer.serialize(entry);
@@ -177,17 +186,15 @@ public:
     response.setMimeType("application/json");
     response.addHeader("Server", "Wt");
 
-    DbStruct* db = dbStruct_.get();
-    if (!db) {
-      db = new DbStruct();
-      dbStruct_.reset(db);
+    if (!dbStruct_) {
+      dbStruct_ = new DbStruct();
     }
 
-    Wt::Dbo::Transaction transaction(db->session);
+    Wt::Dbo::Transaction transaction(dbStruct_->session);
     std::vector<Wt::Dbo::ptr<World> > results;
     results.reserve(n);
     for (int i = 0; i < n; ++i) {
-      results.push_back(db->session.load<World>(db->rand()));
+      results.push_back(dbStruct_->session.load<World>(dbStruct_->rand()));
     }
     Wt::Dbo::JsonSerializer writer(response.out());
     writer.serialize(results);
@@ -206,7 +213,11 @@ private:
   const VFortunes *fortunes_;
   mutable std::vector<Wt::Dbo::ptr<Fortune> >::const_iterator it_;
 public:
-  FortuneTemplate(const std::vector<Wt::Dbo::ptr<Fortune> >& fortunes) : fortunes_(&fortunes), it_(fortunes.end()), Wt::WTemplate(Wt::WString::tr("fortunes")) {
+  FortuneTemplate(const std::vector<Wt::Dbo::ptr<Fortune> >& fortunes)
+    : Wt::WTemplate(tr("fortunes")),
+      fortunes_(&fortunes),
+      it_(fortunes.end())
+  {
     addFunction("while", &Wt::WTemplate::Functions::while_f);
   }
 
@@ -229,7 +240,7 @@ public:
     if (varName == "id")
       result << it_->id();
     else if (varName == "message")
-      format(result, Wt::WString::fromUTF8((*it_)->message));
+      format(result, Wt::WString((*it_)->message));
     else
       Wt::WTemplate::resolveString(varName, vars, result);
   }
@@ -241,20 +252,18 @@ public:
     response.setMimeType("text/html; charset=utf-8");
     response.addHeader("Server", "Wt");
 
-    DbStruct* db = dbStruct_.get();
-    if (!db) {
-      db = new DbStruct();
-      dbStruct_.reset(db);
+    if (!dbStruct_) {
+      dbStruct_ = new DbStruct();
     }
 
-    Wt::Dbo::Transaction transaction(db->session);
-    Fortunes fortunes = db->session.find<Fortune>();
+    Wt::Dbo::Transaction transaction(dbStruct_->session);
+    Fortunes fortunes = dbStruct_->session.find<Fortune>();
     VFortunes vFortunes;
     for (Fortunes::const_iterator i = fortunes.begin(); i != fortunes.end(); ++i)
       vFortunes.push_back(*i);
-    Fortune* additionalFortune = new Fortune();
+    auto additionalFortune = Wt::cpp14::make_unique<Fortune>();
     additionalFortune->message = "Additional fortune added at request time.";
-    vFortunes.push_back(Wt::Dbo::ptr<Fortune>(additionalFortune));
+    vFortunes.push_back(Wt::Dbo::ptr<Fortune>(std::move(additionalFortune)));
 
     std::sort(vFortunes.begin(), vFortunes.end(), fortuneCmp);
 
@@ -282,10 +291,8 @@ public:
     response.setMimeType("application/json");
     response.addHeader("Server", "Wt");
 
-    DbStruct* db = dbStruct_.get();
-    if (!db) {
-      db = new DbStruct();
-      dbStruct_.reset(db);
+    if (!dbStruct_) {
+      dbStruct_ = new DbStruct();
     }
 
     std::vector<Wt::Dbo::ptr<World> > results;
@@ -294,9 +301,9 @@ public:
       bool success = false;
       while (!success) {
         try {
-          Wt::Dbo::Transaction transaction(db->session);
-          Wt::Dbo::ptr<World> world = db->session.load<World>(db->rand());
-          world.modify()->randomNumber = db->rand();
+          Wt::Dbo::Transaction transaction(dbStruct_->session);
+          Wt::Dbo::ptr<World> world = dbStruct_->session.load<World>(dbStruct_->rand());
+          world.modify()->randomNumber = dbStruct_->rand();
           transaction.commit();
           results.push_back(world);
           success = true;
@@ -323,12 +330,13 @@ class PlaintextResource : public Wt::WResource {
 int main(int argc, char** argv) {
   try {
     Wt::WServer server(argv[0]);
-    Wt::WMessageResourceBundle *bundle = new Wt::WMessageResourceBundle();
-    bundle->use("fortunes");
-    server.setLocalizedStrings(bundle);
 
     server.setServerConfiguration(argc, argv, WTHTTP_CONFIGURATION);
 
+    auto bundle = std::make_shared<Wt::WMessageResourceBundle>();
+    bundle->use(server.appRoot() + "fortunes");
+    server.setLocalizedStrings(bundle);
+
     JsonResource jsonResource;
     server.addResource(&jsonResource, "/json");
 
@@ -348,13 +356,15 @@ int main(int argc, char** argv) {
     server.addResource(&plaintextResource, "/plaintext");
 
     if (server.start()) {
-      int sig = Wt::WServer::waitForShutdown(argv[0]);
+      int sig = Wt::WServer::waitForShutdown();
 
       std::cerr << "Shutdown (signal = " << sig << ")" << std::endl;
       server.stop();
 
+#ifndef WT_WIN32
       if (sig == SIGHUP)
         Wt::WServer::restart(argc, argv, environ);
+#endif // WT_WIN32
     }
   } catch (Wt::WServer::Exception& e) {
     std::cerr << e.what() << "\n";

+ 14 - 15
frameworks/C++/wt/fortunes.xml

@@ -1,21 +1,20 @@
 <?xml version="1.0" encoding="UTF-8" ?>
 <messages>
     <message id="fortunes">
-        <html>
-            <head>
-                <title>Fortunes</title>
-            </head>
-            <body>
-                <table>
-                    <tr>
-                        <th>id</th>
-                        <th>message</th>
-                    </tr>
-                    ${while:next-fortune fortune-table-row}
-                </table>
-            </body>
-        </html>
-    </message>
+<html>
+    <head>
+        <title>Fortunes</title>
+    </head>
+    <body>
+        <table>
+            <tr>
+                <th>id</th>
+                <th>message</th>
+            </tr>
+            ${while:next-fortune fortune-table-row}
+        </table>
+    </body>
+</html></message>
 
     <message id="fortune-table-row">
         <tr>

+ 19 - 5
frameworks/C++/wt/setup.sh

@@ -1,9 +1,23 @@
 #!/bin/bash
 
-fw_depends mysql apache wt
+fw_depends wt
 
-sed -i 's|INSERT_DB_HOST_HERE|'"${DBHOST}"'|g' benchmark.cpp
+g++-6 \
+  -std=c++14 \
+  -O3 -march=native -DNDEBUG \
+  -I${BOOST_INC} \
+  -L${BOOST_LIB} \
+  -I${WT_INC} \
+  -L${WT_LIB} \
+  -o te-benchmark.wt \
+  benchmark.cpp \
+  -lwthttp -lwt \
+  -lwtdbo -lwtdbomysql \
+  -lboost_system \
+  -lboost_program_options \
+  -lboost_thread \
+  -lboost_filesystem \
+  -lpthread \
+  -lmysqlclient
 
-g++-4.8 -O3 -DNDEBUG -std=c++0x -L${BOOST_LIB} -I${BOOST_INC} -L${WT_LIB} -I${WT_INC} -o benchmark.wt benchmark.cpp -lwt -lwthttp -lwtdbo -lwtdbomysql -lboost_thread -lboost_system
-
-./benchmark.wt -c wt_config.xml -t ${CPU_COUNT} --docroot . --http-address 0.0.0.0 --http-port 8080 --accesslog=- --no-compression
+./te-benchmark.wt -c wt_config.xml -t ${CPU_COUNT} --docroot . --approot . --http-listen 0.0.0.0:8080 --accesslog=- --no-compression

+ 20 - 5
frameworks/C++/wt/setup_postgres.sh

@@ -1,9 +1,24 @@
 #!/bin/bash
 
-fw_depends postgresql apache wt
+fw_depends wt
 
-sed -i 's|INSERT_DB_HOST_HERE|'"${DBHOST}"'|g' benchmark.cpp
+g++-6 \
+  -std=c++14 \
+  -O3 -march=native -DNDEBUG \
+  -I${BOOST_INC} \
+  -L${BOOST_LIB} \
+  -I${WT_INC} \
+  -L${WT_LIB} \
+  -o te-benchmark-pg.wt \
+  -DBENCHMARK_USE_POSTGRES \
+  benchmark.cpp \
+  -lwthttp -lwt \
+  -lwtdbo -lwtdbopostgres \
+  -lboost_system \
+  -lboost_program_options \
+  -lboost_thread \
+  -lboost_filesystem \
+  -lpthread \
+  -lpq
 
-g++-4.8 -O3 -DNDEBUG -DBENCHMARK_USE_POSTGRES -std=c++0x -L${BOOST_LIB} -I${BOOST_INC} -L${WT_LIB} -I${WT_INC} -o benchmark_postgres.wt benchmark.cpp -lwt -lwthttp -lwtdbo -lwtdbopostgres -lboost_thread -lboost_system
-
-./benchmark_postgres.wt -c wt_config.xml -t ${CPU_COUNT} --docroot . --http-address 0.0.0.0 --http-port 8080 --accesslog=- --no-compression
+./te-benchmark-pg.wt -c wt_config.xml -t ${CPU_COUNT} --docroot . --approot . --http-listen 0.0.0.0:8080 --accesslog=- --no-compression

+ 46 - 32
toolset/setup/linux/frameworks/wt.sh

@@ -1,8 +1,11 @@
 #!/bin/bash
 
+fw_depends postgresql mysql gcc-6
+
 fw_installed wt && return 0
 
-BOOST_ROOT=/usr/local
+WT_VERSION=4.0.2
+BOOST_ROOT=${IROOT}/boost
 BOOST_INC=${BOOST_ROOT}/include
 BOOST_LIB=${BOOST_ROOT}/lib
 WT_ROOT=${IROOT}/wt
@@ -11,40 +14,51 @@ WT_INC=${WT_ROOT}/include
 LD_LIBRARY_PATH="${BOOST_LIB}:${WT_LIB}:${LD_LIBRARY_PATH}"
 CPLUS_INCLUDE_PATH=/usr/include/postgresql:/usr/include/postgresql/9.3/server:$CPLUS_INCLUDE_PATH
 
-# The commented code works. While we would love to get boost from source
-# so we know exactly what we are getting, it just takes too long. Also, 
-# Ubuntu1204 can only run boost 1.48 and Ubuntu1404 can only run 1.54, 
-# even if you compile from source. Apt supplies different boost version 
-# numbers anyways (which is something it often does not do and one of the 
-# main reasons for compilation from a specific source version), so we can 
-# just use apt. See https://github.com/TechEmpower/FrameworkBenchmarks/issues/1013
-#
-#fw_get -o boost_1_48_0.tar.gz http://downloads.sourceforge.net/project/boost/boost/1.48.0/boost_1_48_0.tar.gz
-#fw_untar boost_1_48_0.tar.gz
-#cd boost_1_48_0
-#./bootstrap.sh --prefix=$IROOT/boost
-#./b2 install
-#cd ..
-
-# Instead of compiling from source, just use apt to install onto 
-# host machine
-if [ "$TFB_DISTRIB_CODENAME" == "trusty" ]; then
-    sudo apt-get -y install libboost1.54-all-dev
-elif [ "$TFB_DISTRIB_CODENAME" == "precise" ]; then
-    sudo apt-get -y install libboost1.48-all-dev
-fi
-
-fw_get -O https://github.com/emweb/wt/archive/3.3.8.tar.gz
-mv 3.3.8.tar.gz wt-3.3.8.tar.gz
-fw_untar wt-3.3.8.tar.gz
-
-cd wt-3.3.8
+# Install CMake 3.x
+sudo apt-add-repository --yes ppa:george-edison55/cmake-3.x
+sudo apt-get update -qq
+
+sudo apt-get install -qqy \
+  cmake
+
+# Build boost_thread, boost_system, boost_filesystem and boost_program_options
+fw_get -o boost_1_65_1.tar.gz https://dl.bintray.com/boostorg/release/1.65.1/source/boost_1_65_1.tar.gz
+fw_untar boost_1_65_1.tar.gz
+cd boost_1_65_1
+./bootstrap.sh
+./b2 \
+  -d0 \
+  toolset=gcc-6 \
+  variant=release \
+  link=static \
+  cxxflags="-std=c++14 -march=native" \
+  cflags="-march=native" \
+  --prefix=${BOOST_ROOT} \
+  --with-system \
+  --with-thread \
+  --with-program_options \
+  --with-filesystem \
+  install
+cd ..
+
+fw_get -O https://github.com/emweb/wt/archive/$WT_VERSION.tar.gz
+mv $WT_VERSION.tar.gz wt-$WT_VERSION.tar.gz
+fw_untar wt-$WT_VERSION.tar.gz
+
+cd wt-$WT_VERSION
 mkdir -p build
 cd build
-cmake .. -DWT_CPP_11_MODE=-std=c++0x -DCMAKE_BUILD_TYPE=Release \
+cmake .. -DCMAKE_CXX_STANDARD=14 -DCMAKE_BUILD_TYPE=Release \
+  -DBOOST_PREFIX=${BOOST_ROOT} \
   -DCMAKE_INSTALL_PREFIX=${IROOT}/wt -DCONFIGDIR=${IROOT}/wt/etc \
-  -DCMAKE_CXX_COMPILER=$(which g++-4.8) -DDESTDIR=${IROOT}/wt \
-  -DWEBUSER=$(id -u -n) -DWEBGROUP=$(id -g -n)
+  -DCMAKE_C_COMPILER=$(which gcc-6) \
+  -DCMAKE_CXX_COMPILER=$(which g++-6) -DDESTDIR=${IROOT}/wt \
+  -DWEBUSER=$(id -u -n) -DWEBGROUP=$(id -g -n) \
+  -DENABLE_SSL=OFF -DHTTP_WITH_ZLIB=OFF \
+  -DCMAKE_C_FLAGS_RELEASE="-O3 -march=native -DNDEBUG" \
+  -DCMAKE_CXX_FLAGS_RELEASE="-O3 -march=native -DNDEBUG" \
+  -DBUILD_TESTS=OFF -DENABLE_LIBWTTEST=OFF \
+  -DSHARED_LIBS=OFF
 make
 make install