Skip to content

Commit cb4d892

Browse files
committed
2 parents 5c8f881 + 42b0946 commit cb4d892

File tree

386 files changed

+7029
-2738
lines changed

Some content is hidden

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

386 files changed

+7029
-2738
lines changed

frameworks/C++/just-boost/just-boost.dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
# docker build --progress=plain --build-arg CXXFLAGS="-Wall" -t just-boost -f just-boost.dockerfile .
22
# docker run --rm --name just-boost -p 8000:8000 -d just-boost
33
# docker container stop just-boost
4-
FROM alpine:3.18
4+
FROM alpine:3.19
55

66
ARG APP=just-boost
77
ARG CXXFLAGS=-O3
88

99
ENV LANG=C.UTF-8 LC_ALL=C.UTF-8
1010
ENV BCPP_PG_CONN_STR="postgres://benchmarkdbuser:benchmarkdbpass@tfb-database/hello_world"
11-
ENV BCPP_N_THREADS=32
11+
#ENV BCPP_N_THREADS=0 # default 0 : number of cores
1212

1313
WORKDIR /usr/src/${APP}
1414

frameworks/C++/just-boost/main.cpp

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,6 @@ handle_target(
117117
http::request<Body, http::basic_fields<Allocator>>&& req,
118118
PGconn* conn = nullptr)
119119
{
120-
static std::string msg = "Hello, World!";
121-
122120
//std::cout << "handle_target: " << req.target() << std::endl;
123121
http::response<http::string_body> res{http::status::ok, req.version()};
124122
res.set(http::field::server, BOOST_BEAST_VERSION_STRING);
@@ -130,13 +128,13 @@ handle_target(
130128
{
131129
// {"message":"Hello, World!"}
132130
json::object obj;
133-
obj["message"] = msg;
131+
obj["message"] = "Hello, World!";
134132
res.body() = json::serialize(obj);
135133
}
136134
else if (req.target() == "/plaintext")
137135
{
138136
res.set(http::field::content_type, "text/plain");
139-
res.body() = msg;
137+
res.body() = "Hello, World!";
140138
}
141139
else if (req.target() == "/db" || req.target().starts_with("/queries/"))
142140
{
@@ -328,9 +326,10 @@ do_listen(tcp::endpoint endpoint)
328326
{
329327
std::rethrow_exception(e);
330328
}
331-
catch (std::exception &e) {
332-
std::cerr << "Error in session: " << e.what() << "\n";
333-
}
329+
catch (std::exception&){}
330+
// catch (std::exception &e) {
331+
// std::cerr << "Error in session: " << e.what() << "\n";
332+
// }
334333
});
335334

336335
}
@@ -339,7 +338,13 @@ int main(int argc, char* argv[])
339338
{
340339
auto const address = net::ip::make_address(becpp::env("BCPP_ADDRESS", "0.0.0.0"));
341340
auto const port = static_cast<unsigned short>(std::atoi(becpp::env("BCPP_PORT", "8000")));
342-
auto const threads = std::max<int>(1, std::atoi(becpp::env("BCPP_N_THREADS", "3")));
341+
auto env_threads = std::atoi(becpp::env("BCPP_N_THREADS", "0"));
342+
if (env_threads == 0)
343+
{
344+
env_threads = std::thread::hardware_concurrency();
345+
std::cout << "Using number of cores: " << env_threads << '\n';
346+
}
347+
auto const threads = std::max<int>(1, env_threads);
343348

344349
std::cout << "__GNUG__=" << __GNUG__ << '\n';
345350
std::cout << "__cplusplus=" << __cplusplus << '\n';

frameworks/C++/treefrog/controllers/worldcontroller.cpp

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include "pworld.h"
44
#include "mngworld.h"
55
#include <TCache>
6+
#include <TSqlQuery>
67

78

89
void WorldController::index()
@@ -246,17 +247,48 @@ void WorldController::cached_pqueries(const QString &num)
246247

247248
void WorldController::pupdates(const QString &num)
248249
{
250+
const QString statement("UPDATE world SET randomnumber = CASE id");
249251
QVariantList worlds;
252+
QString ids;
253+
QString q = statement;
254+
q.reserve(4096);
250255
int d = std::min(std::max(num.toInt(), 1), 500);
251256
PWorld world;
252257

258+
auto blkupdate = [&q, &ids, &statement]() {
259+
if (!ids.isEmpty()) {
260+
ids.chop(1);
261+
q += QStringLiteral(" END WHERE id IN (%1)").arg(ids);
262+
TSqlQuery query;
263+
query.exec(q);
264+
ids.clear();
265+
q = statement;
266+
}
267+
};
268+
253269
for (int i = 0; i < d; ++i) {
254270
int id = Tf::random(1, 10000);
255271
world = PWorld::get(id);
256272
world.setRandomNumber( Tf::random(1, 10000) );
257-
world.update();
273+
q += QLatin1String(" WHEN ");
274+
q += QString::number(world.id());
275+
q += QLatin1String(" THEN ");
276+
q += QString::number(world.randomNumber());
277+
ids += QString::number(world.id());
278+
ids += ',';
258279
worlds << world.toVariantMap();
280+
281+
if (!((i + 1) % 200)) {
282+
blkupdate();
283+
}
259284
}
285+
286+
if (d == 1) {
287+
world.update();
288+
} else {
289+
blkupdate();
290+
}
291+
260292
renderJson(worlds);
261293
}
262294

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

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

77
WORKDIR /src
88
RUN git clone https://github.com/userver-framework/userver.git && \
9-
cd userver && git checkout 781169b63bdbc012f7d98ed045bff75ff1b0b70d
9+
cd userver && git checkout b85d540d7022e344f6fcf9fd467c67b046c961fe
1010
COPY userver_benchmark/ ./
1111
RUN mkdir build && cd build && \
1212
cmake -DUSERVER_IS_THE_ROOT_PROJECT=0 -DUSERVER_FEATURE_CRYPTOPP_BLAKE2=0 \
13-
-DUSERVER_FEATURE_REDIS=0 -DUSERVER_FEATURE_CLICKHOUSE=0 -DUSERVER_FEATURE_MONGODB=0 -DUSERVER_FEATURE_RABBITMQ=0 -DUSERVER_FEATURE_GRPC=0 \
1413
-DUSERVER_FEATURE_UTEST=0 \
1514
-DUSERVER_FEATURE_POSTGRESQL=1 \
15+
-DUSERVER_FEATURE_ERASE_LOG_WITH_LEVEL=warning \
1616
-DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_FLAGS="-march=native" -DCMAKE_C_FLAGS="-march=native" \
17-
-DCMAKE_CXX_COMPILER=clang++-16 -DCMAKE_C_COMPILER=clang-16 -DUSERVER_USE_LD=lld-16 .. && \
17+
-DCMAKE_CXX_COMPILER=clang++-16 -DCMAKE_C_COMPILER=clang-16 -DUSERVER_USE_LD=lld-16 -DUSERVER_LTO_CACHE=0 .. && \
1818
make -j $(nproc)
1919

2020
FROM builder AS runner

frameworks/C++/userver/userver.dockerfile

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

77
WORKDIR /src
88
RUN git clone https://github.com/userver-framework/userver.git && \
9-
cd userver && git checkout 781169b63bdbc012f7d98ed045bff75ff1b0b70d
9+
cd userver && git checkout b85d540d7022e344f6fcf9fd467c67b046c961fe
1010
COPY userver_benchmark/ ./
1111
RUN mkdir build && cd build && \
1212
cmake -DUSERVER_IS_THE_ROOT_PROJECT=0 -DUSERVER_FEATURE_CRYPTOPP_BLAKE2=0 \
13-
-DUSERVER_FEATURE_REDIS=0 -DUSERVER_FEATURE_CLICKHOUSE=0 -DUSERVER_FEATURE_MONGODB=0 -DUSERVER_FEATURE_RABBITMQ=0 -DUSERVER_FEATURE_GRPC=0 \
1413
-DUSERVER_FEATURE_UTEST=0 \
1514
-DUSERVER_FEATURE_POSTGRESQL=1 \
15+
-DUSERVER_FEATURE_ERASE_LOG_WITH_LEVEL=warning \
1616
-DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_FLAGS="-march=native" -DCMAKE_C_FLAGS="-march=native" \
17-
-DCMAKE_CXX_COMPILER=clang++-16 -DCMAKE_C_COMPILER=clang-16 -DUSERVER_USE_LD=lld-16 .. && \
17+
-DCMAKE_CXX_COMPILER=clang++-16 -DCMAKE_C_COMPILER=clang-16 -DUSERVER_USE_LD=lld-16 -DUSERVER_LTO_CACHE=0 .. && \
1818
make -j $(nproc)
1919

2020
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
@@ -9,10 +9,10 @@ file(GLOB_RECURSE SOURCES
99
${CMAKE_CURRENT_SOURCE_DIR}/bare/*.cpp
1010
)
1111

12-
include(userver/cmake/SetupEnvironment.cmake)
1312
include(GNUInstallDirs)
1413

1514
add_subdirectory(userver)
15+
userver_setup_environment()
1616

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

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

Lines changed: 16 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -11,44 +11,19 @@
1111
#include <userver/engine/async.hpp>
1212
#include <userver/utils/datetime/wall_coarse_clock.hpp>
1313
#include <userver/utils/scope_guard.hpp>
14+
#include <userver/utils/small_string.hpp>
1415

1516
namespace userver_techempower::bare {
1617

1718
namespace {
1819

19-
template <std::size_t N>
20-
class SmallString final {
21-
public:
22-
SmallString() = default;
23-
24-
void Append(const char* data, std::size_t length) {
25-
const auto old_size = Size();
26-
data_.resize(old_size + length);
27-
std::memcpy(Data() + old_size, data, length);
28-
}
29-
30-
void Append(std::string_view sw) { Append(sw.data(), sw.size()); }
31-
32-
[[nodiscard]] std::string_view AsSw() const { return {Data(), Size()}; }
33-
34-
[[nodiscard]] char* Data() { return data_.data(); }
35-
[[nodiscard]] const char* Data() const { return data_.data(); }
36-
37-
[[nodiscard]] std::size_t Size() const { return data_.size(); }
38-
39-
void Clear() { data_.resize(0); }
40-
41-
private:
42-
boost::container::small_vector<char, N> data_;
43-
};
44-
4520
struct HttpParser final {
4621
http_parser parser{};
4722
http_parser_settings parser_settings{};
4823

4924
std::function<void(std::string_view)> on_request_cb{};
5025

51-
SmallString<50> url;
26+
userver::utils::SmallString<50> url;
5227

5328
explicit HttpParser(std::function<void(std::string_view)> on_request_cb)
5429
: on_request_cb{std::move(on_request_cb)} {
@@ -68,26 +43,26 @@ struct HttpParser final {
6843
static int HttpOnUrl(http_parser* parser, const char* data,
6944
std::size_t length) {
7045
auto* self = static_cast<HttpParser*>(parser->data);
71-
self->url.Append(data, length);
46+
self->url.append(std::string_view{data, length});
7247
return 0;
7348
}
7449

7550
static int HttpOnMessageBegin(http_parser* parser) {
7651
auto* self = static_cast<HttpParser*>(parser->data);
77-
self->url.Clear();
52+
self->url.clear();
7853
return 0;
7954
}
8055

8156
static int HttpOnMessageComplete(http_parser* parser) {
8257
auto* self = static_cast<HttpParser*>(parser->data);
83-
self->on_request_cb(self->url.AsSw());
58+
self->on_request_cb(static_cast<std::string_view>(self->url));
8459
return 0;
8560
}
8661
};
8762

8863
class ResponseBuffers final {
8964
public:
90-
using HeadersString = SmallString<200>;
65+
using HeadersString = userver::utils::SmallString<200>;
9166

9267
HeadersString& Next(userver::engine::io::Socket& socket, std::string&& body) {
9368
if (Size() == kMaxResponses) {
@@ -111,9 +86,9 @@ class ResponseBuffers final {
11186
std::size_t index = 0;
11287
std::size_t total_size = 0;
11388
for (const auto& response : responses_) {
114-
iovec[index++] = {response.headers.Data(), response.headers.Size()};
89+
iovec[index++] = {response.headers.data(), response.headers.size()};
11590
iovec[index++] = {response.body.data(), response.body.size()};
116-
total_size += response.headers.Size() + response.body.size();
91+
total_size += response.headers.size() + response.body.size();
11792
}
11893

11994
if (socket.SendAll(iovec.data(), iovec.size(), {}) != total_size) {
@@ -191,17 +166,17 @@ void SimpleConnection::Process() {
191166
const auto content_length_str = std::to_string(response.body.size());
192167
auto& headers = buffers.Next(socket_, std::move(response.body));
193168

194-
headers.Append(kCommonHeaders);
195-
headers.Append("Content-Type: ");
196-
headers.Append(response.content_type);
169+
headers.append(kCommonHeaders);
170+
headers.append("Content-Type: ");
171+
headers.append(response.content_type);
197172

198-
headers.Append("\r\nContent-Length: ");
199-
headers.Append(content_length_str);
173+
headers.append("\r\nContent-Length: ");
174+
headers.append(content_length_str);
200175

201-
headers.Append("\r\nDate: ");
202-
headers.Append(GetCachedDate());
176+
headers.append("\r\nDate: ");
177+
headers.append(GetCachedDate());
203178

204-
headers.Append(kHeadersEnd);
179+
headers.append(kHeadersEnd);
205180
};
206181
HttpParser parser{handle_request};
207182

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ components_manager:
8383
max_queue_size: 512
8484
connecting_limit: 15
8585
ignore_unused_query_params: true
86+
connlimit_mode: manual
8687

8788
single-query-handler:
8889
path: /db
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
2+
RUN apt-get update
3+
RUN apt-get -yqq install clang zlib1g-dev
4+
WORKDIR /app
5+
COPY src/Platform .
6+
RUN dotnet publish -c Release -o out /p:DatabaseProvider=Npgsql /p:PublishAot=true /p:OptimizationPreference=Speed /p:GarbageCollectionAdaptationMode=0
7+
8+
FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS runtime
9+
ENV URLS http://+:8080
10+
11+
WORKDIR /app
12+
COPY --from=build /app/out ./
13+
COPY appsettings.postgresql.json ./appsettings.json
14+
15+
EXPOSE 8080
16+
17+
ENTRYPOINT ["./Platform"]

frameworks/CSharp/aspnetcore/aspnetcore-minimal.dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
FROM mcr.microsoft.com/dotnet/sdk:8.0.100-rc.2 AS build
1+
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
22
WORKDIR /app
33
COPY src/Minimal .
44
RUN dotnet publish -c Release -o out
55

6-
FROM mcr.microsoft.com/dotnet/aspnet:8.0.0-rc.2 AS runtime
6+
FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS runtime
77
ENV URLS http://+:8080
88

99
WORKDIR /app

0 commit comments

Comments
 (0)