فهرست منبع

Merge branch 'matt-42-master'

Brittany Mazza 10 سال پیش
والد
کامیت
619e5d2fec

+ 1 - 0
.travis.yml

@@ -26,6 +26,7 @@ env:
     - "TESTDIR=CSharp/nancy"
     - "TESTDIR=CSharp/servicestack"
     - "TESTDIR=C++/cpoll_cppsp"
+    - "TESTDIR=C++/silicon"
     - "TESTDIR=C++/treefrog"
     - "TESTDIR=C++/ULib"
     - "TESTDIR=C++/wt"

+ 15 - 0
frameworks/C++/silicon/CMakeLists.txt

@@ -0,0 +1,15 @@
+cmake_minimum_required(VERSION 2.8)
+
+project(silicon)
+
+include_directories($ENV{IROOT}/include)
+
+link_directories($ENV{IROOT}/lib)
+add_definitions(-std=c++14  -ftemplate-depth=512 -DNDEBUG -O3)
+
+add_executable(silicon_tpc_mysql main.cc)
+target_link_libraries(silicon_tpc_mysql microhttpd mysqlclient)
+
+add_executable(silicon_epoll_mysql main.cc)
+set_target_properties(silicon_epoll_mysql PROPERTIES COMPILE_FLAGS "-DTFB_USE_EPOLL")
+target_link_libraries(silicon_epoll_mysql microhttpd mysqlclient)

+ 51 - 0
frameworks/C++/silicon/benchmark_config

@@ -0,0 +1,51 @@
+{
+  "framework": "silicon",
+  "tests": [{
+    "default": {
+      "setup_file": "setup_tpc_mysql",
+      "json_url"       : "/json",
+      "db_url"         : "/db",
+      "query_url"      : "/queries?queries=",
+      "fortune_url"    : "/fortunes",
+      "update_url"     : "/updates?queries=",
+      "plaintext_url"  : "/plaintext",
+      "port": 8080,
+      "approach": "Realistic",
+      "classification": "Micro",
+      "database": "MySQL",
+      "framework": "silicon",
+      "language": "C++",
+      "orm": "Full",
+      "platform": "Silicon",
+      "webserver": "None",
+      "os": "Linux",
+      "database_os": "Linux",
+      "display_name": "silicon-tpc-mysql",
+      "notes": "",
+      "versus": ""
+    },
+    "epoll-mysql": {
+      "setup_file": "setup_epoll_mysql",
+      "json_url"       : "/json",
+      "db_url"         : "/db",
+      "query_url"      : "/queries?queries=",
+      "fortune_url"    : "/fortunes",
+      "update_url"     : "/updates?queries=",
+      "plaintext_url"  : "/plaintext",
+      "port": 8080,
+      "approach": "Realistic",
+      "classification": "Micro",
+      "database": "MySQL",
+      "framework": "silicon",
+      "language": "C++",
+      "orm": "Full",
+      "platform": "Silicon",
+      "webserver": "None",
+      "os": "Linux",
+      "database_os": "Linux",
+      "display_name": "silicon-epoll-mysql",
+      "notes": "",
+      "versus": ""
+    }
+  }]
+}

+ 20 - 0
frameworks/C++/silicon/install.sh

@@ -0,0 +1,20 @@
+#!/bin/bash
+
+# Install silicon
+DIR=`pwd`
+rm -fr silicon;
+git clone https://github.com/matt-42/silicon.git
+cd silicon;
+CXX=/usr/bin/g++-4.9 ./install.sh $IROOT
+
+# Install microhttpd
+cd $DIR
+fw_get http://mirror.ibcp.fr/pub/gnu/libmicrohttpd/libmicrohttpd-0.9.39.tar.gz
+fw_untar libmicrohttpd-0.9.39.tar.gz
+cd libmicrohttpd-0.9.39
+./configure --prefix=$IROOT
+make install
+
+cd $TROOT
+mkdir -p build
+cd build; cmake .. -DCMAKE_CXX_COMPILER=g++-4.9; make silicon_tpc_mysql; make silicon_epoll_mysql

+ 137 - 0
frameworks/C++/silicon/main.cc

@@ -0,0 +1,137 @@
+#include <algorithm>
+#include <unistd.h>
+#include <iostream>
+#include <silicon/backends/mhd.hh>
+#include <silicon/api.hh>
+#include <silicon/middlewares/mysql_connection.hh>
+#include <silicon/middlewares/mysql_orm.hh>
+#include "symbols.hh"
+
+using namespace s;
+using namespace sl;
+
+typedef decltype(D(_id(_auto_increment, _primary_key) = int(),
+                   _randomNumber = int())) random_number;
+
+typedef decltype(D(_id(_auto_increment, _primary_key) = int(),
+                   _message = std::string())) fortune;
+
+typedef mysql_orm_factory<random_number> rn_orm_factory;
+typedef mysql_orm<random_number> rn_orm;
+
+typedef mysql_orm_factory<fortune> fortune_orm_factory;
+typedef mysql_orm<fortune> fortune_orm;
+
+std::string escape_html_entities(const std::string& data)
+{
+    std::string buffer;
+    buffer.reserve(data.size());
+    for(size_t pos = 0; pos != data.size(); ++pos) {
+        switch(data[pos]) {
+            case '&':  buffer.append("&amp;");       break;
+            case '\"': buffer.append("&quot;");      break;
+            case '\'': buffer.append("&apos;");      break;
+            case '<':  buffer.append("&lt;");        break;
+            case '>':  buffer.append("&gt;");        break;
+            default:   buffer.append(&data[pos], 1); break;
+        }
+    }
+    return std::move(buffer);
+}
+
+int main(int argc, char* argv[])
+{
+
+  if (argc != 3)
+  {
+    std::cerr << "Usage: " << argv[0] << " mysql_host port" << std::endl;
+    return 1;
+  }
+  
+  auto hello_api = make_api(
+
+    _plaintext = [] () { return response(_content_type = "text/plain",
+                                         _body = "Hello, World!"); },
+
+    _json = [] () { return response(_content_type = "application/json",
+                                    _body = D(_message = "Hello, World!")); },
+                        
+    _db = [] (rn_orm& orm) {
+      random_number r;
+      orm.find_by_id(1245, r);
+      return response(_content_type = "application/json",
+                      _body = r);
+    },
+
+    _queries = [] (rn_orm& orm, get_parameters& get_params) {
+      int N = atoi(get_params["queries"].c_str());
+      N = std::max(1, std::min(N, 500));
+
+      std::vector<random_number> qs(N);
+      for (int i = 0; i < N; i++)
+        orm.find_by_id(1 + rand() % 9999, qs[i]);
+      return response(_content_type = "application/json",
+                      _body = std::move(qs));
+    },
+
+    _updates = [] (rn_orm& orm, get_parameters& get_params) {
+      int N = atoi(get_params["queries"].c_str());
+      N = std::max(1, std::min(N, 500));
+
+      std::vector<random_number> qs(N);
+      for (int i = 0; i < N; i++)
+      {
+        orm.find_by_id(1 + rand() % 9999, qs[i]);
+        qs[i].randomNumber = 1 + rand() % 9999;
+        orm.update(qs[i]);
+      }
+      return response(_content_type = "application/json",
+                      _body = std::move(qs));
+    },
+  
+    _fortunes = [] (fortune_orm& orm) {
+      std::vector<fortune> table;
+      orm.forall([&] (fortune& f) { table.push_back(f); });
+      table.push_back(fortune(0, "Additional fortune added at request time."));
+
+      std::sort(table.begin(), table.end(),
+                [] (const fortune& a, const fortune& b) { return a.message < b.message; });
+
+      std::stringstream ss;
+
+      ss << "<!DOCTYPE html><html><head><title>Fortunes</title></head><body><table><tr><th>id</th><th>message</th></tr>";
+      for(auto& f : table)
+        ss << "<tr><td>" << f.id << "</td><td>" << escape_html_entities(f.message) << "</td></tr>";
+      ss << "</table></body></html>";
+
+      return response(_content_type = "text/html",
+                      _body = ss.str());
+    }
+  
+    ).bind_factories(
+      mysql_connection_factory(argv[1], "benchmarkdbuser", "benchmarkdbpass", "hello_world"),
+      fortune_orm_factory("Fortune"),
+      rn_orm_factory("World")
+      );
+  
+  try
+  {
+
+    // Start the server.
+    sl::mhd_json_serve(hello_api, atoi(argv[2])
+#ifdef TFB_USE_EPOLL
+                       , _linux_epoll, _nthreads = 1000
+#else
+                       , _one_thread_per_connection
+#endif
+      );
+  }
+  catch (std::exception& e)
+  {
+    std::cerr << e.what() << std::endl;
+  }
+  catch (sl::error::error& e)
+  {
+    std::cerr << e.what() << std::endl;
+  }
+}

+ 3 - 0
frameworks/C++/silicon/setup_epoll_mysql.sh

@@ -0,0 +1,3 @@
+#! /bin/bash
+
+$TROOT/build/silicon_epoll_mysql ${DBHOST} 8080 &

+ 3 - 0
frameworks/C++/silicon/setup_tpc_mysql.sh

@@ -0,0 +1,3 @@
+#! /bin/bash
+
+$TROOT/build/silicon_tpc_mysql ${DBHOST} 8080 &

+ 47 - 0
frameworks/C++/silicon/symbols.hh

@@ -0,0 +1,47 @@
+// Generated by iod_generate_symbols.
+#include <iod/symbol.hh>
+#ifndef IOD_SYMBOL_db
+#define IOD_SYMBOL_db
+    iod_define_symbol(db)
+#endif
+
+#ifndef IOD_SYMBOL_fortunes
+#define IOD_SYMBOL_fortunes
+    iod_define_symbol(fortunes)
+#endif
+
+#ifndef IOD_SYMBOL_id
+#define IOD_SYMBOL_id
+    iod_define_symbol(id)
+#endif
+
+#ifndef IOD_SYMBOL_json
+#define IOD_SYMBOL_json
+    iod_define_symbol(json)
+#endif
+
+#ifndef IOD_SYMBOL_message
+#define IOD_SYMBOL_message
+    iod_define_symbol(message)
+#endif
+
+#ifndef IOD_SYMBOL_plaintext
+#define IOD_SYMBOL_plaintext
+    iod_define_symbol(plaintext)
+#endif
+
+#ifndef IOD_SYMBOL_queries
+#define IOD_SYMBOL_queries
+    iod_define_symbol(queries)
+#endif
+
+#ifndef IOD_SYMBOL_randomNumber
+#define IOD_SYMBOL_randomNumber
+    iod_define_symbol(randomNumber)
+#endif
+
+#ifndef IOD_SYMBOL_updates
+#define IOD_SYMBOL_updates
+    iod_define_symbol(updates)
+#endif
+

+ 4 - 3
toolset/setup/linux/prerequisites.sh

@@ -42,12 +42,13 @@ sudo apt-get -qqy install -o Dpkg::Options::="--force-confdef" -o Dpkg::Options:
   libjemalloc-dev libluajit-5.1-dev `# Needed by lwan at least` \
   libhiredis-dev                    `# Redis client - Needed by ngx_mruby at least` \
   cloc dstat                        `# Collect resource usage statistics` \
-  llvm-dev                          `# Required for correct Ruby installation`
+  llvm-dev                          `# Required for correct Ruby installation` \
+  libboost-dev                      `# Silicon relies on boost::lexical_cast.`
 
-# Install gcc-4.8
+# Install gcc-4.8 and gcc-4.9
 sudo add-apt-repository ppa:ubuntu-toolchain-r/test -y
 sudo apt-get -yq update
-sudo apt-get install -qqy gcc-4.8 g++-4.8
+sudo apt-get install -qqy gcc-4.8 g++-4.8 gcc-4.9 g++-4.9
 
 # Stop permanently overwriting people's files just for 
 # trying out our software!