Skip to content

Commit 768a99d

Browse files
authored
Merge branch 'TechEmpower:master' into master
2 parents 0fc9945 + 5b1b1e7 commit 768a99d

File tree

220 files changed

+4430
-3895
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

220 files changed

+4430
-3895
lines changed

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,17 @@ RUN apt update && \
66

77
WORKDIR /src
88
RUN git clone https://github.com/userver-framework/userver.git && \
9-
cd userver && git checkout fcf0514be560f46740f8a654f2fdce5dc1cd450c
9+
cd userver && git checkout c2ca5454f0b0e93dd0a2e082904dedda5cda3052
1010

1111
COPY userver_benchmark/ ./
1212
RUN mkdir build && cd build && \
1313
cmake -DUSERVER_IS_THE_ROOT_PROJECT=0 -DUSERVER_FEATURE_CRYPTOPP_BLAKE2=0 \
1414
-DUSERVER_FEATURE_UTEST=0 \
1515
-DUSERVER_FEATURE_POSTGRESQL=1 \
1616
-DUSERVER_FEATURE_ERASE_LOG_WITH_LEVEL=warning \
17-
-DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_FLAGS="-march=native" -DCMAKE_C_FLAGS="-march=native" \
18-
-DCMAKE_CXX_COMPILER=clang++-16 -DCMAKE_C_COMPILER=clang-16 -DUSERVER_USE_LD=lld-16 -DUSERVER_LTO_CACHE=0 .. && \
17+
-DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_FLAGS="-march=native -flto=thin" -DCMAKE_C_FLAGS="-march=native -flto=thin" \
18+
-DCMAKE_CXX_COMPILER=clang++-16 -DCMAKE_C_COMPILER=clang-16 -DUSERVER_USE_LD=lld-16 \
19+
-DUSERVER_LTO=0 .. && \
1920
make -j $(nproc)
2021

2122
FROM builder AS runner

frameworks/C++/userver/userver.dockerfile

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,17 @@ RUN apt update && \
66

77
WORKDIR /src
88
RUN git clone https://github.com/userver-framework/userver.git && \
9-
cd userver && git checkout fcf0514be560f46740f8a654f2fdce5dc1cd450c
9+
cd userver && git checkout c2ca5454f0b0e93dd0a2e082904dedda5cda3052
1010

1111
COPY userver_benchmark/ ./
1212
RUN mkdir build && cd build && \
1313
cmake -DUSERVER_IS_THE_ROOT_PROJECT=0 -DUSERVER_FEATURE_CRYPTOPP_BLAKE2=0 \
1414
-DUSERVER_FEATURE_UTEST=0 \
1515
-DUSERVER_FEATURE_POSTGRESQL=1 \
1616
-DUSERVER_FEATURE_ERASE_LOG_WITH_LEVEL=warning \
17-
-DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_FLAGS="-march=native" -DCMAKE_C_FLAGS="-march=native" \
18-
-DCMAKE_CXX_COMPILER=clang++-16 -DCMAKE_C_COMPILER=clang-16 -DUSERVER_USE_LD=lld-16 -DUSERVER_LTO_CACHE=0 .. && \
17+
-DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_FLAGS="-march=native -flto=thin" -DCMAKE_C_FLAGS="-march=native -flto=thin" \
18+
-DCMAKE_CXX_COMPILER=clang++-16 -DCMAKE_C_COMPILER=clang-16 -DUSERVER_USE_LD=lld-16 \
19+
-DUSERVER_LTO=0 .. && \
1920
make -j $(nproc)
2021

2122
FROM builder AS runner

frameworks/C++/userver/userver_benchmark/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,4 @@ add_subdirectory(userver)
1515
userver_setup_environment()
1616

1717
add_executable(${PROJECT_NAME} ${SOURCES} userver_techempower.cpp)
18-
target_link_libraries(${PROJECT_NAME} PRIVATE userver-core userver-postgresql)
18+
target_link_libraries(${PROJECT_NAME} PRIVATE userver-core userver-postgresql userver-llhttp)

frameworks/C++/userver/userver_benchmark/bare/simple_connection.cpp

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#include <array>
44

55
#include <cctz/time_zone.h>
6-
#include <http_parser.h>
6+
#include <llhttp.h>
77
#include <boost/container/small_vector.hpp>
88

99
#include "simple_server.hpp"
@@ -18,42 +18,41 @@ namespace userver_techempower::bare {
1818
namespace {
1919

2020
struct HttpParser final {
21-
http_parser parser{};
22-
http_parser_settings parser_settings{};
21+
llhttp_t parser{};
22+
llhttp_settings_t parser_settings{};
2323

2424
std::function<void(std::string_view)> on_request_cb{};
2525

2626
userver::utils::SmallString<50> url;
2727

2828
explicit HttpParser(std::function<void(std::string_view)> on_request_cb)
2929
: on_request_cb{std::move(on_request_cb)} {
30-
http_parser_init(&parser, HTTP_REQUEST);
31-
parser.data = this;
32-
33-
http_parser_settings_init(&parser_settings);
30+
llhttp_settings_init(&parser_settings);
3431
parser_settings.on_url = HttpOnUrl;
3532
parser_settings.on_message_begin = HttpOnMessageBegin;
3633
parser_settings.on_message_complete = HttpOnMessageComplete;
34+
35+
llhttp_init(&parser, HTTP_REQUEST, &parser_settings);
36+
parser.data = this;
3737
}
3838

39-
void Execute(const char* data, std::size_t length) {
40-
http_parser_execute(&parser, &parser_settings, data, length);
39+
auto Execute(const char* data, std::size_t length) {
40+
return llhttp_execute(&parser, data, length);
4141
}
4242

43-
static int HttpOnUrl(http_parser* parser, const char* data,
44-
std::size_t length) {
43+
static int HttpOnUrl(llhttp_t* parser, const char* data, std::size_t length) {
4544
auto* self = static_cast<HttpParser*>(parser->data);
4645
self->url.append(std::string_view{data, length});
4746
return 0;
4847
}
4948

50-
static int HttpOnMessageBegin(http_parser* parser) {
49+
static int HttpOnMessageBegin(llhttp_t* parser) {
5150
auto* self = static_cast<HttpParser*>(parser->data);
5251
self->url.clear();
5352
return 0;
5453
}
5554

56-
static int HttpOnMessageComplete(http_parser* parser) {
55+
static int HttpOnMessageComplete(llhttp_t* parser) {
5756
auto* self = static_cast<HttpParser*>(parser->data);
5857
self->on_request_cb(static_cast<std::string_view>(self->url));
5958
return 0;
@@ -192,8 +191,7 @@ void SimpleConnection::Process() {
192191
break;
193192
}
194193

195-
parser.Execute(buffer.data(), last_bytes_read);
196-
if (parser.parser.http_errno != 0) {
194+
if (parser.Execute(buffer.data(), last_bytes_read) != HPE_OK) {
197195
break;
198196
}
199197

frameworks/C++/userver/userver_benchmark/controllers/multiple_queries/handler.cpp

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -37,24 +37,24 @@ std::string Handler::HandleRequestThrow(
3737
}
3838

3939
std::string Handler::GetResponse(int queries) const {
40-
boost::container::small_vector<db_helpers::WorldTableRow, 20> result(queries);
41-
for (auto& value : result) {
42-
value.id = db_helpers::GenerateRandomId();
43-
}
44-
45-
{
40+
const auto db_result = [this, queries] {
4641
const auto lock = semaphore_.Acquire();
4742

48-
auto trx =
49-
pg_->Begin(db_helpers::kClusterHostType, {}, db_helpers::kDefaultPgCC);
50-
for (auto& value : result) {
51-
value.random_number = trx.Execute(db_helpers::kDefaultPgCC,
52-
db_helpers::kSelectRowQuery, value.id)
53-
.AsSingleRow<db_helpers::WorldTableRow>(
54-
userver::storages::postgres::kRowTag)
55-
.random_number;
43+
auto query_queue = pg_->CreateQueryQueue(db_helpers::kClusterHostType,
44+
db_helpers::kDefaultPgCC.execute);
45+
query_queue.Reserve(queries);
46+
for (std::size_t i = 0; i < static_cast<std::size_t>(queries); ++i) {
47+
query_queue.Push(db_helpers::kDefaultPgCC, db_helpers::kSelectRowQuery,
48+
db_helpers::GenerateRandomId());
5649
}
57-
trx.Commit();
50+
51+
return query_queue.Collect(db_helpers::kDefaultPgCC.execute);
52+
}();
53+
54+
boost::container::small_vector<db_helpers::WorldTableRow, 20> result(queries);
55+
for (std::size_t i = 0; i < static_cast<std::size_t>(queries); ++i) {
56+
result[i] = db_result[i].AsSingleRow<db_helpers::WorldTableRow>(
57+
userver::storages::postgres::kRowTag);
5858
}
5959

6060
userver::formats::json::StringBuilder sb{};

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

Lines changed: 32 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,15 @@
77

88
#include <boost/container/small_vector.hpp>
99

10+
namespace userver::storages::postgres::io::traits {
11+
12+
// Hijack userver's whitelist of allowed containers
13+
template <typename T, std::size_t Size>
14+
struct IsCompatibleContainer<boost::container::small_vector<T, Size>>
15+
: std::true_type {};
16+
17+
} // namespace userver::storages::postgres::io::traits
18+
1019
namespace userver_techempower::updates {
1120

1221
namespace {
@@ -46,41 +55,39 @@ std::string Handler::HandleRequestThrow(
4655
}
4756

4857
std::string Handler::GetResponse(int queries) const {
49-
// userver's PG doesn't accept boost::small_vector as an input, sadly
50-
std::vector<db_helpers::WorldTableRow> values(queries);
51-
for (auto& value : values) {
52-
value.id = db_helpers::GenerateRandomId();
58+
boost::container::small_vector<int, 20> ids(queries);
59+
for (auto& id : ids) {
60+
id = db_helpers::GenerateRandomId();
5361
}
5462
// we have to sort ids to not deadlock in update
55-
std::sort(values.begin(), values.end(),
56-
[](const auto& lhs, const auto& rhs) { return lhs.id < rhs.id; });
63+
std::sort(ids.begin(), ids.end(),
64+
[](const auto& lhs, const auto& rhs) { return lhs < rhs; });
5765

58-
boost::container::small_vector<db_helpers::WorldTableRow, 20> result;
66+
boost::container::small_vector<int, 20> values(queries);
67+
for (auto& value : values) {
68+
value = db_helpers::GenerateRandomValue();
69+
}
5970

60-
{
71+
const auto db_results = [this, &ids, &values] {
6172
const auto lock = semaphore_.Acquire();
6273

63-
auto trx =
64-
pg_->Begin(db_helpers::kClusterHostType, {}, db_helpers::kDefaultPgCC);
65-
for (auto& value : values) {
66-
value.random_number = trx.Execute(db_helpers::kDefaultPgCC,
67-
db_helpers::kSelectRowQuery, value.id)
68-
.AsSingleRow<db_helpers::WorldTableRow>(
69-
userver::storages::postgres::kRowTag)
70-
.random_number;
74+
auto query_queue = pg_->CreateQueryQueue(db_helpers::kClusterHostType,
75+
db_helpers::kDefaultPgCC.execute);
76+
query_queue.Reserve(ids.size() + 1 /* for the update query */);
77+
for (const auto id : ids) {
78+
query_queue.Push(db_helpers::kDefaultPgCC, db_helpers::kSelectRowQuery,
79+
id);
7180
}
7281

73-
// We copy values here (and hope compiler optimizes it into one memcpy call)
74-
// to not serialize into json within transaction
75-
result.assign(values.begin(), values.end());
82+
query_queue.Push(db_helpers::kDefaultPgCC, update_query_, ids, values);
7683

77-
for (auto& value : values) {
78-
value.random_number = db_helpers::GenerateRandomValue();
79-
}
84+
return query_queue.Collect(db_helpers::kDefaultPgCC.execute);
85+
}();
8086

81-
trx.ExecuteDecomposeBulk(db_helpers::kDefaultPgCC, update_query_, values,
82-
values.size());
83-
trx.Commit();
87+
boost::container::small_vector<db_helpers::WorldTableRow, 20> result(queries);
88+
for (std::size_t i = 0; i < result.size(); ++i) {
89+
result[i] = db_results[i].AsSingleRow<db_helpers::WorldTableRow>(
90+
userver::storages::postgres::kRowTag);
8491
}
8592

8693
userver::formats::json::StringBuilder sb{};

frameworks/C++/userver/userver_benchmark/userver_techempower.cpp

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
#include <userver/clients/dns/component.hpp>
66

7+
#include <userver/server/middlewares/configuration.hpp>
78
#include <userver/storages/postgres/component.hpp>
89
#include <userver/storages/secdist/component.hpp>
910
#include <userver/storages/secdist/provider_component.hpp>
@@ -45,6 +46,20 @@ class NoopTracingManager final
4546
userver::server::http::HttpResponse&) const final {}
4647
};
4748

49+
class MinimalMiddlewarePipelineBuilder final
50+
: public userver::server::middlewares::PipelineBuilder {
51+
public:
52+
static constexpr std::string_view kName{
53+
"minimal-middleware-pipeline-builder"};
54+
using userver::server::middlewares::PipelineBuilder::PipelineBuilder;
55+
56+
private:
57+
userver::server::middlewares::MiddlewaresList BuildPipeline(
58+
userver::server::middlewares::MiddlewaresList) const override {
59+
return {"userver-unknown-exceptions-handling-middleware"};
60+
}
61+
};
62+
4863
int Main(int argc, char* argv[]) {
4964
auto component_list =
5065
userver::components::MinimalServerComponentList()
@@ -63,8 +78,9 @@ int Main(int argc, char* argv[]) {
6378
.Append<cached_queries::WorldCacheComponent>() // cache component
6479
.Append<cached_queries::Handler>()
6580
.Append<fortunes::Handler>()
66-
// tracing tweaks
81+
// tracing and metrics tweaks
6782
.Append<NoopTracingManager>()
83+
.Append<MinimalMiddlewarePipelineBuilder>()
6884
// bare
6985
.Append<bare::SimpleRouter>()
7086
.Append<bare::SimpleServer>();

frameworks/C++/userver/userver_configs/static_config.yaml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# yaml
22
components_manager:
33
event_thread_pool:
4-
threads: 5
4+
threads: 9
55
dedicated_timer_threads: 1
66
coro_pool:
77
initial_size: 10000 # Preallocate 10000 coroutines at startup.
@@ -12,7 +12,7 @@ components_manager:
1212

1313
main-task-processor: # Make a task processor for CPU-bound couroutine tasks.
1414
thread_name: main-worker # OS will show the threads of this task processor with 'main-worker' prefix.
15-
worker_threads: 23
15+
worker_threads: 46
1616
guess-cpu-limit: true
1717

1818
fs-task-processor: # Make a separate task processor for filesystem bound tasks.
@@ -29,6 +29,7 @@ components_manager:
2929
handler-defaults:
3030
set_tracing_headers: false
3131
server-name: us
32+
middleware-pipeline-builder: minimal-middleware-pipeline-builder
3233
simple-router:
3334
simple-server:
3435
port: 8081
@@ -62,6 +63,7 @@ components_manager:
6263
noop-tracing-manager:
6364
tracing-manager-locator:
6465
component-name: noop-tracing-manager
66+
minimal-middleware-pipeline-builder:
6567

6668
plaintext-handler:
6769
path: /plaintext

frameworks/C/h2o/h2o.dockerfile

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ RUN apt-get -yqq update && \
1313
curl \
1414
flex \
1515
g++ \
16+
libbpfcc-dev \
1617
libbrotli-dev \
1718
libcap-dev \
1819
libicu-dev \
@@ -27,9 +28,11 @@ RUN apt-get -yqq update && \
2728
make \
2829
ninja-build \
2930
pkg-config \
31+
rsync \
32+
ruby \
3033
systemtap-sdt-dev
3134

32-
ARG H2O_VERSION=13ba727ad12dfb2338165d2bcfb2136457e33c8a
35+
ARG H2O_VERSION=18b175f71ede08b50d3e5ae8303dacef3ea510fc
3336

3437
WORKDIR /tmp/h2o-build
3538
RUN curl -LSs "https://github.com/h2o/h2o/archive/${H2O_VERSION}.tar.gz" | \
@@ -39,6 +42,7 @@ RUN curl -LSs "https://github.com/h2o/h2o/archive/${H2O_VERSION}.tar.gz" | \
3942
-DCMAKE_AR=/usr/bin/gcc-ar \
4043
-DCMAKE_C_FLAGS="-flto -march=native -mtune=native" \
4144
-DCMAKE_RANLIB=/usr/bin/gcc-ranlib \
45+
-DWITH_MRUBY=on \
4246
-G Ninja \
4347
-S . && \
4448
cmake --build build -j && \

frameworks/CSharp/appmpower/src/Data/DbConnection.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -142,10 +142,7 @@ public void Dispose()
142142

143143
public async Task OpenAsync()
144144
{
145-
#if ADO && SQLSERVER
146-
_internalConnection = new();
147-
_internalConnection.DbConnection = new System.Data.SqlClient.SqlConnection(_connectionString);
148-
#elif ADO && POSTGRESQL
145+
#if ADO && POSTGRESQL
149146
_internalConnection = new();
150147
_internalConnection.DbConnection = new Npgsql.NpgsqlConnection(_connectionString);
151148
#else

0 commit comments

Comments
 (0)