Browse Source

Lithium: Use only one thread for postgres. (#5615)

* Lithim: Use only one thread for postgres.

* Fix compilation.

* Lithium - split nprocs/nthreads.

* Lithium - rerun travis.

* Lithium Fix benchmark config.

* Lithium: use default in config again.

* Lithium postgres update.

* monothread version of mysql.
Matthieu Garrigues 5 years ago
parent
commit
ac475b4dcd

+ 45 - 0
frameworks/C++/lithium/benchmark_config.json

@@ -25,6 +25,29 @@
         "notes": "",
         "notes": "",
         "versus": "None"
         "versus": "None"
       },
       },
+      "mysql-1t": {
+        "json_url"       : "/json",
+        "db_url"         : "/db",
+        "query_url"      : "/queries?N=",
+        "fortune_url"    : "/fortunes",
+        "update_url"     : "/updates?N=",
+        "plaintext_url"  : "/plaintext",
+        "port": 8080,
+        "approach": "Realistic",
+        "classification": "Micro",
+        "database": "mysql",
+        "framework": "Lithium",
+        "language": "C++",
+        "flavor": "None",
+        "orm": "Full",
+        "platform": "None",
+        "webserver": "None",
+        "os": "Linux",
+        "database_os": "Linux",
+        "display_name": "Lithium-mysql-1t",
+        "notes": "",
+        "versus": "None"
+      },
       "postgres": {
       "postgres": {
         "json_url"       : "/json",
         "json_url"       : "/json",
         "db_url"         : "/db",
         "db_url"         : "/db",
@@ -47,6 +70,28 @@
         "display_name": "Lithium-postgres",
         "display_name": "Lithium-postgres",
         "notes": "",
         "notes": "",
         "versus": "None"
         "versus": "None"
+      },
+
+      "postgres-1t": {
+        "db_url"         : "/db",
+        "query_url"      : "/queries?N=",
+        "fortune_url"    : "/fortunes",
+        "update_url"     : "/updates?N=",
+        "port": 8080,
+        "approach": "Realistic",
+        "classification": "Micro",
+        "database": "Postgres",
+        "framework": "Lithium",
+        "language": "C++",
+        "flavor": "None",
+        "orm": "Full",
+        "platform": "None",
+        "webserver": "None",
+        "os": "Linux",
+        "database_os": "Linux",
+        "display_name": "Lithium-postgres-1t",
+        "notes": "",
+        "versus": "None"
       }
       }
 
 
     }
     }

+ 15 - 0
frameworks/C++/lithium/lithium-mysql-1t.dockerfile

@@ -0,0 +1,15 @@
+FROM buildpack-deps:focal
+
+RUN apt-get update -yqq
+RUN apt-get install -yqq libboost-dev libmariadb-dev wget  libboost-context-dev g++-9
+
+COPY ./ ./
+
+ENV COMMIT=062c167b61ba14292d54bade9534adca33a8d19e
+
+RUN wget https://raw.githubusercontent.com/matt-42/lithium/$COMMIT/single_headers/lithium_mysql.hh
+RUN wget https://raw.githubusercontent.com/matt-42/lithium/$COMMIT/single_headers/lithium_http_backend.hh
+
+RUN g++ -DNDEBUG -DTFB_MYSQL -DMONOTHREAD -O3 -march=native -std=c++17 ./lithium.cc -I /usr/include/mariadb -lpthread -lmariadbclient -lboost_context -o /lithium_tbf
+
+CMD /lithium_tbf tfb-database 8080

+ 15 - 0
frameworks/C++/lithium/lithium-postgres-1t.dockerfile

@@ -0,0 +1,15 @@
+FROM buildpack-deps:focal
+
+RUN apt-get update -yqq
+RUN apt-get install -yqq g++-9 libboost-dev postgresql-server-dev-all libpq-dev wget libboost-context-dev
+
+COPY ./ ./
+
+ENV COMMIT=062c167b61ba14292d54bade9534adca33a8d19e
+
+RUN wget https://raw.githubusercontent.com/matt-42/lithium/$COMMIT/single_headers/lithium_pgsql.hh
+RUN wget https://raw.githubusercontent.com/matt-42/lithium/$COMMIT/single_headers/lithium_http_backend.hh
+
+RUN g++ -DTFB_PGSQL -DMONOTHREAD -O3 -DNDEBUG -march=native -std=c++17 ./lithium.cc -I/usr/include/postgresql -lpthread -lpq -lboost_context -o /lithium_tbf
+
+CMD /lithium_tbf tfb-database 8080

+ 29 - 14
frameworks/C++/lithium/lithium.cc

@@ -72,18 +72,27 @@ int main(int argc, char* argv[]) {
   }
   }
 
 
   int port = atoi(argv[2]);
   int port = atoi(argv[2]);
+
   int nprocs = std::thread::hardware_concurrency();
   int nprocs = std::thread::hardware_concurrency();
 
 
 #if TFB_MYSQL
 #if TFB_MYSQL
-  auto sql_db =
-    mysql_database(s::host = argv[1], s::database = "hello_world", s::user = "benchmarkdbuser",
-                   s::password = "benchmarkdbpass", s::port = 3306, s::charset = "utf8");
-  int sql_max_connection = sql_db.connect()("SELECT @@GLOBAL.max_connections;").template read<int>() - 10;
+  int nthreads = nprocs;
 #elif TFB_PGSQL
 #elif TFB_PGSQL
-  auto sql_db =
-    pgsql_database(s::host = argv[1], s::database = "hello_world", s::user = "benchmarkdbuser",
-                   s::password = "benchmarkdbpass", s::port = 5432, s::charset = "utf8");
-  int sql_max_connection = atoi(sql_db.connect()("SHOW max_connections;").template read<std::string>().c_str()) - 10;
+
+#if MONOTHREAD
+  int nthreads = 1;
+#else
+  int nthreads = nprocs;
+#endif
+
+#endif
+
+#if TFB_MYSQL
+  auto sql_db = mysql_database(s::host = argv[1], s::database = "hello_world", s::user = "benchmarkdbuser",
+                s::password = "benchmarkdbpass", s::port = 3306, s::charset = "utf8");
+#elif TFB_PGSQL
+  auto sql_db = pgsql_database(s::host = argv[1], s::database = "hello_world", s::user = "benchmarkdbuser",
+                               s::password = "benchmarkdbpass", s::port = 5432, s::charset = "utf8");
 #endif
 #endif
 
 
   auto fortunes = sql_orm_schema(sql_db, "Fortune").fields(
   auto fortunes = sql_orm_schema(sql_db, "Fortune").fields(
@@ -94,19 +103,25 @@ int main(int argc, char* argv[]) {
     s::id(s::auto_increment, s::primary_key) = int(),
     s::id(s::auto_increment, s::primary_key) = int(),
     s::randomNumber = int());
     s::randomNumber = int());
 
 
-
 #if TFB_MYSQL
 #if TFB_MYSQL
-  int db_nconn = 128/nprocs;
+  int db_nconn = 4;
   int queries_nconn = 2;
   int queries_nconn = 2;
-  int fortunes_nconn = 128/nprocs;
+  int fortunes_nconn = 4;
   int updates_nconn = 1;
   int updates_nconn = 1;
 #elif TFB_PGSQL
 #elif TFB_PGSQL
-  int db_nconn = 200/nprocs;
+  int db_nconn = 7;
   int queries_nconn = 4;
   int queries_nconn = 4;
-  int fortunes_nconn = 200/nprocs;
+  int fortunes_nconn = 7;
   int updates_nconn = 3;
   int updates_nconn = 3;
 #endif
 #endif
 
 
+#if MONOTHREAD
+  db_nconn *= nprocs;
+  queries_nconn *= nprocs;
+  fortunes_nconn *= nprocs;
+  updates_nconn *= nprocs;
+#endif
+
   http_api my_api;
   http_api my_api;
 
 
   my_api.get("/plaintext") = [&](http_request& request, http_response& response) {
   my_api.get("/plaintext") = [&](http_request& request, http_response& response) {
@@ -200,7 +215,7 @@ int main(int argc, char* argv[]) {
   };
   };
 
 
   // Start the server for the Techempower benchmark.
   // Start the server for the Techempower benchmark.
-  http_serve(my_api, port, s::nthreads = nprocs);
+  http_serve(my_api, port, s::nthreads = nthreads);
 
 
   return 0;
   return 0;
 }
 }

+ 0 - 0
frameworks/C++/lithium/lithium-mysql.dockerfile → frameworks/C++/lithium/lithium.dockerfile