Browse Source

Lithium: 1 connection for batch mode. Use the -batch prefix for postgres batch mode. (#5986)

* Lithium: 1 connection for batch mode. Use the -batch prefix for postgres batch mode.

* Lithium: optimize escape_html
Matthieu Garrigues 4 years ago
parent
commit
1e843b93d6

+ 2 - 24
frameworks/C++/lithium/benchmark_config.json

@@ -50,7 +50,7 @@
         "notes": "",
         "notes": "",
         "versus": "None"
         "versus": "None"
       },
       },
-      "postgres-pipeline": {
+      "postgres-batch": {
         "db_url"         : "/db",
         "db_url"         : "/db",
         "query_url"      : "/queries?N=",
         "query_url"      : "/queries?N=",
         "fortune_url"    : "/fortunes",
         "fortune_url"    : "/fortunes",
@@ -67,33 +67,11 @@
         "webserver": "None",
         "webserver": "None",
         "os": "Linux",
         "os": "Linux",
         "database_os": "Linux",
         "database_os": "Linux",
-        "display_name": "Lithium-postgres-pipeline",
-        "notes": "",
-        "versus": "None"
-      },
-      "postgres-pipeline-monothread": {
-        "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-pipeline-1t",
+        "display_name": "Lithium-postgres-batch",
         "notes": "",
         "notes": "",
         "versus": "None"
         "versus": "None"
       }
       }
 
 
-
     }
     }
   ]
   ]
 }
 }

+ 2 - 2
frameworks/C++/lithium/compile_clang-pipeline.sh → frameworks/C++/lithium/compile_clang-batch.sh

@@ -17,9 +17,9 @@ fi
 
 
 wget https://raw.githubusercontent.com/matt-42/lithium/$COMMIT/single_headers/lithium_http_backend.hh
 wget https://raw.githubusercontent.com/matt-42/lithium/$COMMIT/single_headers/lithium_http_backend.hh
 
 
-clang++ -fprofile-instr-generate=./profile.prof -flto -DPROFILE_MODE -DN_SQL_CONNECTIONS=2  -DMONOTHREAD=$MONOTHREAD -DNDEBUG -D$DB_FLAG -O3 -march=native -std=c++17 ./lithium_pipeline.cc $CXX_FLAGS -lpthread -lboost_context -lssl -lcrypto -o /lithium_tbf
+clang++ -fprofile-instr-generate=./profile.prof -flto -DPROFILE_MODE -DN_SQL_CONNECTIONS=1  -DMONOTHREAD=$MONOTHREAD -DNDEBUG -D$DB_FLAG -O3 -march=native -std=c++17 ./lithium_pipeline.cc $CXX_FLAGS -lpthread -lboost_context -lssl -lcrypto -o /lithium_tbf
 /lithium_tbf tfb-database 8081
 /lithium_tbf tfb-database 8081
 llvm-profdata-10 merge -output=./profile.pgo  ./profile.prof
 llvm-profdata-10 merge -output=./profile.pgo  ./profile.prof
-clang++ -fprofile-instr-use=./profile.pgo -flto -DNDEBUG -D$DB_FLAG -DN_SQL_CONNECTIONS=2  -DMONOTHREAD=$MONOTHREAD -O3 -march=native -std=c++17 ./lithium_pipeline.cc $CXX_FLAGS -lpthread -lboost_context -lssl -lcrypto -o /lithium_tbf
+clang++ -fprofile-instr-use=./profile.pgo -flto -DNDEBUG -D$DB_FLAG -DN_SQL_CONNECTIONS=1  -DMONOTHREAD=$MONOTHREAD -O3 -march=native -std=c++17 ./lithium_pipeline.cc $CXX_FLAGS -lpthread -lboost_context -lssl -lcrypto -o /lithium_tbf
 
 
 /lithium_tbf tfb-database 8080
 /lithium_tbf tfb-database 8080

+ 1 - 1
frameworks/C++/lithium/lithium-postgres-pipeline-monothread.dockerfile → frameworks/C++/lithium/lithium-postgres-batch-monothread.dockerfile

@@ -9,7 +9,7 @@ COPY ./ ./
 RUN ./compile_libpq.sh batchmode
 RUN ./compile_libpq.sh batchmode
 ENV LD_LIBRARY_PATH=/usr/lib
 ENV LD_LIBRARY_PATH=/usr/lib
 
 
-CMD ./compile_clang-pipeline.sh TFB_PGSQL 1
+CMD ./compile_clang-batch.sh TFB_PGSQL 1
 
 
 
 
 #ENV LD_LIBRARY_PATH=/usr/lib
 #ENV LD_LIBRARY_PATH=/usr/lib

+ 1 - 1
frameworks/C++/lithium/lithium-postgres-pipeline.dockerfile → frameworks/C++/lithium/lithium-postgres-batch.dockerfile

@@ -9,4 +9,4 @@ COPY ./ ./
 RUN ./compile_libpq.sh batchmode
 RUN ./compile_libpq.sh batchmode
 ENV LD_LIBRARY_PATH=/usr/lib
 ENV LD_LIBRARY_PATH=/usr/lib
 
 
-CMD ./compile_clang-pipeline.sh TFB_PGSQL 0
+CMD ./compile_clang-batch.sh TFB_PGSQL 0

+ 19 - 2
frameworks/C++/lithium/lithium.cc

@@ -10,9 +10,26 @@
 using namespace li;
 using namespace li;
 
 
 template <typename B>
 template <typename B>
-void escape_html_entities(B& buffer, const std::string& data)
+void escape_html_entities(B& buffer, const std::string_view& data)
 {
 {
-    for(size_t pos = 0; pos != data.size(); ++pos) {
+  size_t pos = 0;
+  auto search_for_special = [&] () {
+    size_t start = pos;
+    size_t end = pos;
+    for(;pos != data.size(); ++pos) {
+      char c = data[pos];
+      if (c > '>' || (c != '&' && c != '\"' && c != '\'' && c != '<' && c == '>'))
+        end = pos + 1;
+      else break;
+    }
+
+    if (start != end)
+      buffer << std::string_view(data.data() + start, end - start);
+  };
+  
+    for(; pos != data.size(); ++pos) {
+      search_for_special();
+      if (pos >= data.size()) return;
         switch(data[pos]) {
         switch(data[pos]) {
             case '&':  buffer << "&amp;";       break;
             case '&':  buffer << "&amp;";       break;
             case '\"': buffer << "&quot;";      break;
             case '\"': buffer << "&quot;";      break;

+ 19 - 2
frameworks/C++/lithium/lithium_pipeline.cc

@@ -10,9 +10,26 @@
 using namespace li;
 using namespace li;
 
 
 template <typename B>
 template <typename B>
-void escape_html_entities(B& buffer, const std::string& data)
+void escape_html_entities(B& buffer, const std::string_view& data)
 {
 {
-    for(size_t pos = 0; pos != data.size(); ++pos) {
+  size_t pos = 0;
+  auto search_for_special = [&] () {
+    size_t start = pos;
+    size_t end = pos;
+    for(;pos != data.size(); ++pos) {
+      char c = data[pos];
+      if (c > '>' || (c != '&' && c != '\"' && c != '\'' && c != '<' && c == '>'))
+        end = pos + 1;
+      else break;
+    }
+
+    if (start != end)
+      buffer << std::string_view(data.data() + start, end - start);
+  };
+  
+    for(; pos != data.size(); ++pos) {
+      search_for_special();
+      if (pos >= data.size()) return;
         switch(data[pos]) {
         switch(data[pos]) {
             case '&':  buffer << "&amp;";       break;
             case '&':  buffer << "&amp;";       break;
             case '\"': buffer << "&quot;";      break;
             case '\"': buffer << "&quot;";      break;