Explorar el Código

[C++] [userver] bump userver commit, optimize fortunes (#8549)

* [C++] [userver] Do less logging-related work in PG queries

* don't validate parameters in queries

* optimizes fortunes: no need to copy strings, string_view would do

* + clang-format

* up userver commit

* up userver commit
itrofimow hace 1 año
padre
commit
545483082b

+ 1 - 1
frameworks/C++/userver/userver-bare.dockerfile

@@ -6,7 +6,7 @@ RUN apt update && \
 
 WORKDIR /src
 RUN git clone https://github.com/userver-framework/userver.git && \
-    cd userver && git checkout 73727ce95d24f18651fc018c45f50c492f858027
+    cd userver && git checkout 781169b63bdbc012f7d98ed045bff75ff1b0b70d
 COPY userver_benchmark/ ./
 RUN mkdir build && cd build && \
     cmake -DUSERVER_IS_THE_ROOT_PROJECT=0 -DUSERVER_FEATURE_CRYPTOPP_BLAKE2=0 \

+ 1 - 1
frameworks/C++/userver/userver.dockerfile

@@ -6,7 +6,7 @@ RUN apt update && \
 
 WORKDIR /src
 RUN git clone https://github.com/userver-framework/userver.git && \
-    cd userver && git checkout 73727ce95d24f18651fc018c45f50c492f858027
+    cd userver && git checkout 781169b63bdbc012f7d98ed045bff75ff1b0b70d
 COPY userver_benchmark/ ./
 RUN mkdir build && cd build && \
     cmake -DUSERVER_IS_THE_ROOT_PROJECT=0 -DUSERVER_FEATURE_CRYPTOPP_BLAKE2=0 \

+ 7 - 0
frameworks/C++/userver/userver_benchmark/common/db_helpers.cpp

@@ -27,6 +27,13 @@ int ParseFromQueryVal(std::string_view query_val) {
 
 }  // namespace
 
+userver::storages::postgres::Query CreateNonLoggingQuery(
+    std::string statement) {
+  return userver::storages::postgres::Query{
+      statement, std::nullopt /* name */,
+      userver::storages::postgres::Query::LogMode::kNameOnly};
+}
+
 int GenerateRandomId() {
   return userver::utils::RandRange(1, kMaxWorldRows + 1);
 }

+ 7 - 2
frameworks/C++/userver/userver_benchmark/common/db_helpers.hpp

@@ -8,11 +8,16 @@
 
 namespace userver_techempower::db_helpers {
 
+userver::storages::postgres::Query CreateNonLoggingQuery(std::string statement);
+
 constexpr int kMaxWorldRows = 10000;
-const userver::storages::postgres::Query kSelectRowQuery{
-    "SELECT id, randomNumber FROM World WHERE id = $1"};
+
+const userver::storages::postgres::Query kSelectRowQuery =
+    CreateNonLoggingQuery("SELECT id, randomNumber FROM World WHERE id = $1");
+
 constexpr auto kClusterHostType =
     userver::storages::postgres::ClusterHostType::kMaster;
+
 constexpr std::string_view kDbComponentName = "hello-world-db";
 
 struct WorldTableRow final {

+ 8 - 7
frameworks/C++/userver/userver_benchmark/controllers/fortunes/handler.cpp

@@ -14,7 +14,7 @@ const std::string kContentTypeTextHtml{"text/html; charset=utf-8"};
 
 struct Fortune final {
   int id;
-  std::string message;
+  std::string_view message;
 };
 
 constexpr std::string_view kResultingHtmlHeader{
@@ -133,7 +133,8 @@ Handler::Handler(const userver::components::ComponentConfig& config,
               .FindComponent<userver::components::Postgres>(
                   db_helpers::kDbComponentName)
               .GetCluster()},
-      select_all_fortunes_query_{"SELECT id, message FROM Fortune"},
+      select_all_fortunes_query_{
+          db_helpers::CreateNonLoggingQuery("SELECT id, message FROM Fortune")},
       semaphore_{kBestConcurrencyWildGuess} {}
 
 std::string Handler::HandleRequestThrow(
@@ -144,14 +145,14 @@ std::string Handler::HandleRequestThrow(
 }
 
 std::string Handler::GetResponse() const {
-  auto fortunes = [this] {
+  const auto pg_result = [this] {
     const auto lock = semaphore_.Acquire();
-    return pg_
-        ->Execute(db_helpers::kClusterHostType, select_all_fortunes_query_)
-        .AsContainer<std::vector<Fortune>>(
-            userver::storages::postgres::kRowTag);
+    return pg_->Execute(db_helpers::kClusterHostType,
+                        select_all_fortunes_query_);
   }();
 
+  auto fortunes = pg_result.AsContainer<std::vector<Fortune>>(
+      userver::storages::postgres::kRowTag);
   fortunes.push_back({0, "Additional fortune added at request time."});
 
   std::sort(fortunes.begin(), fortunes.end(),

+ 1 - 1
frameworks/C++/userver/userver_benchmark/controllers/updates/handler.cpp

@@ -30,7 +30,7 @@ Handler::Handler(const userver::components::ComponentConfig& config,
       pg_{context.FindComponent<userver::components::Postgres>("hello-world-db")
               .GetCluster()},
       query_arg_name_{"queries"},
-      update_query_{kUpdateQueryStr},
+      update_query_{db_helpers::CreateNonLoggingQuery(kUpdateQueryStr)},
       semaphore_{kBestConcurrencyWildGuess} {}
 
 userver::formats::json::Value Handler::HandleRequestJsonThrow(

+ 4 - 3
frameworks/C++/userver/userver_configs/static_config.yaml

@@ -17,7 +17,7 @@ components_manager:
 
         fs-task-processor:              # Make a separate task processor for filesystem bound tasks.
             thread_name: fs-worker
-            worker_threads: 4
+            worker_threads: 1
 
     default_task_processor: main-task-processor
 
@@ -49,8 +49,8 @@ components_manager:
 
         dynamic-config:                      # Dynamic config storage options, do nothing
             fs-cache-path: ''
-        dynamic-config-fallbacks:            # Load options from file and push them into the dynamic config storage.
-            fallback-path: /app/dynamic_config_fallback.json
+            defaults-path: /app/dynamic_config_fallback.json
+            fs-task-processor: fs-task-processor
 
         testsuite-support:
 
@@ -82,6 +82,7 @@ components_manager:
             max_pool_size: 260
             max_queue_size: 512
             connecting_limit: 15
+            ignore_unused_query_params: true
 
         single-query-handler:
             path: /db