Browse Source

Lithium optimizations. (#5960)

* Lithium optimizations.

* Lithium use growing_output_buffer.
Matthieu Garrigues 5 years ago
parent
commit
7ce4c61cb2

+ 1 - 1
frameworks/C++/lithium/compile_and_start_clang.sh

@@ -1,7 +1,7 @@
 #! /bin/sh
 
 DB_FLAG=$1
-COMMIT=8564c2286d0ae9508fe7d3c8dbf65b7f299f40af
+COMMIT=941b701ac884b1d7f050b721fe444b6831563239
 
 if [ $DB_FLAG = "TFB_MYSQL" ]; then
   CXX_FLAGS="-I /usr/include/mariadb  -lmariadbclient "

+ 3 - 3
frameworks/C++/lithium/compile_clang-pipeline.sh

@@ -1,7 +1,7 @@
 #! /bin/sh
 
 DB_FLAG=$1
-COMMIT=c01c26a4b7f3aa2bb21c3f5c7cb65e1b37f8c429
+COMMIT=bc145d604f14a11082cc5e00ba854d0786d69e3d
 MONOTHREAD=$2
 
 if [ $DB_FLAG = "TFB_MYSQL" ]; then
@@ -17,9 +17,9 @@ fi
 
 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=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
+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
 /lithium_tbf tfb-database 8081
 llvm-profdata-10 merge -output=./profile.pgo  ./profile.prof
-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
+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
 
 /lithium_tbf tfb-database 8080

+ 6 - 8
frameworks/C++/lithium/lithium.cc

@@ -37,7 +37,7 @@ void siege(int port) {
 }
 #endif
 
-thread_local lru_cache<int, decltype(mmm(s::id = int(), s::randomNumber = int()))> world_cache(10000);
+lru_cache<int, decltype(mmm(s::id = int(), s::randomNumber = int()))> world_cache(10000);
 
 int main(int argc, char* argv[]) {
 
@@ -124,17 +124,16 @@ int main(int argc, char* argv[]) {
     response.write_json(numbers);
   };
 
+  random_numbers.connect().forall([&] (const auto& number) {
+    world_cache(number.id, [&] { return metamap_clone(number); });
+  });
+
   my_api.get("/cached-worlds") = [&](http_request& request, http_response& response) {
     sql_db.max_async_connections_per_thread_ = queries_nconn;
     std::string N_str = request.get_parameters(s::N = std::optional<std::string>()).N.value_or("1");
     int N = atoi(N_str.c_str());
     
     N = std::max(1, std::min(N, 500));
-    
-    if (world_cache.size() == 0)
-      random_numbers.connect(request.fiber).forall([&] (const auto& number) {
-        world_cache(number.id, [&] { return metamap_clone(number); });
-      });
 
     std::vector<decltype(random_numbers.all_fields())> numbers(N);
     for (int i = 0; i < N; i++)
@@ -191,8 +190,7 @@ int main(int argc, char* argv[]) {
     std::sort(table.begin(), table.end(),
               [] (const fortune& a, const fortune& b) { return a.message < b.message; });
 
-    char b[100000];
-    li::output_buffer ss(b, sizeof(b));
+    li::growing_output_buffer ss;
  
     ss << "<!DOCTYPE html><html><head><title>Fortunes</title></head><body><table><tr><th>id</th><th>message</th></tr>";
     for(auto& f : table)

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

@@ -140,8 +140,7 @@ int main(int argc, char* argv[]) {
     std::sort(table.begin(), table.end(),
               [] (const fortune& a, const fortune& b) { return a.message < b.message; });
 
-    char b[100000];
-    li::output_buffer ss(b, sizeof(b));
+    li::growing_output_buffer ss;
  
     ss << "<!DOCTYPE html><html><head><title>Fortunes</title></head><body><table><tr><th>id</th><th>message</th></tr>";
     for(auto& f : table)