Skip to content

Commit 3c65965

Browse files
committed
userver: HttpArena benchmark implementation (userver-create-service)
10 benchmark profiles (baseline, pipelined, limited-conn, json, json-comp, upload, api-4, api-16, static, async-db) - 6 HTTP handlers (baseline11, baseline2, json, plaintext, upload, async_db) - gzip compression middleware - Dockerfile based on ubuntu-24.04-userver
1 parent e2f6beb commit 3c65965

42 files changed

Lines changed: 957 additions & 533 deletions

Some content is hidden

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

frameworks/userver/Dockerfile

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,19 @@
1-
FROM ghcr.io/userver-framework/ubuntu-24.04-userver-base AS builder
1+
FROM ghcr.io/userver-framework/ubuntu-24.04-userver:v3.0 AS builder
22

33
WORKDIR /src
4-
RUN git clone https://github.com/userver-framework/userver.git && \
5-
cd userver && git checkout v3.0
6-
74
COPY userver_benchmark/ ./
85
RUN mkdir build && cd build && \
9-
cmake -DUSERVER_IS_THE_ROOT_PROJECT=0 -DUSERVER_FEATURE_CRYPTOPP_BLAKE2=0 \
10-
-DUSERVER_FEATURE_UTEST=0 \
11-
-DUSERVER_FEATURE_POSTGRESQL=1 \
12-
-DUSERVER_FEATURE_ERASE_LOG_WITH_LEVEL=warning \
13-
-DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_FLAGS="-march=native" -DCMAKE_C_FLAGS="-march=native" \
14-
-DCMAKE_CXX_COMPILER=clang++-17 -DCMAKE_C_COMPILER=clang-17 \
15-
-DUSERVER_LTO=0 .. && \
16-
make -j $(nproc)
6+
cmake -DCMAKE_BUILD_TYPE=Release \
7+
-DCMAKE_CXX_FLAGS="-march=native" \
8+
-DCMAKE_C_FLAGS="-march=native" .. && \
9+
cmake --build . -j $(nproc)
10+
1711

1812
FROM builder AS runner
1913
WORKDIR /app
20-
COPY userver_configs/* ./
14+
COPY --from=builder /src/configs/config-vars.httparena.yaml ./configs/config_vars.yaml
15+
COPY --from=builder /src/configs/static_config.yaml ./configs/
2116
COPY --from=builder /src/build/userver_httparena ./
2217

23-
EXPOSE 8080
24-
CMD ./userver_httparena -c ./static_config.yaml
18+
EXPOSE 8080 8443 8081
19+
CMD ./userver_httparena -c ./configs/static_config.yaml

frameworks/userver/meta.json

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,13 @@
1010
"baseline",
1111
"pipelined",
1212
"limited-conn",
13-
"static"
13+
"json",
14+
"json-comp",
15+
"upload",
16+
"api-4",
17+
"api-16",
18+
"static",
19+
"async-db"
1420
],
1521
"maintainers": ["botanegg"]
1622
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
__pycache__
2+
build*/
3+
compile_commands.json
4+
.cache/
5+
.ccache/
6+
.idea/
7+
.vscode/
8+
!.vscode/c_cpp_properties.json
9+
!.vscode/cmake-variants.yaml
10+
!.vscode/README.md
11+
.cores/
12+
cmake-build-*
13+
Testing/
14+
.DS_Store
15+
Makefile.local
16+
CMakeUserPresets.json
17+
configs/secure_data.json
18+
third_party/
Lines changed: 50 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,57 @@
1-
cmake_minimum_required(VERSION 3.12)
1+
cmake_minimum_required(VERSION 3.12...3.31)
22
project(userver_httparena CXX)
33

4-
set(CMAKE_CXX_STANDARD 20)
4+
set(CMAKE_CXX_STANDARD 23)
5+
set(CMAKE_CXX_STANDARD_REQUIRED ON)
56

6-
file(GLOB_RECURSE SOURCES
7-
${CMAKE_CURRENT_SOURCE_DIR}/controllers/*.cpp
8-
${CMAKE_CURRENT_SOURCE_DIR}/common/*.cpp
9-
)
7+
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
8+
include(DownloadUserver)
9+
10+
#boost context find problem hack
11+
find_package(Boost CONFIG REQUIRED COMPONENTS context)
1012

11-
include(GNUInstallDirs)
13+
find_package(
14+
userver
15+
COMPONENTS core #
16+
postgresql
17+
QUIET
18+
)
19+
if (NOT userver_FOUND)
20+
# Tries TRY_DIR first, falls back to downloading userver from GitHub using CPM.
21+
download_userver(TRY_DIR third_party/userver)
22+
endif ()
1223

13-
add_subdirectory(userver)
1424
userver_setup_environment()
1525

16-
add_executable(${PROJECT_NAME} ${SOURCES} userver_httparena.cpp)
17-
target_link_libraries(${PROJECT_NAME} PRIVATE userver-core userver-postgresql userver-llhttp)
26+
# Common sources
27+
include_directories(src)
28+
29+
add_library(
30+
${PROJECT_NAME}_objs OBJECT
31+
src/handlers/baseline11/handler.hpp
32+
src/handlers/baseline11/handler.cpp
33+
src/handlers/baseline2/handler.hpp
34+
src/handlers/baseline2/handler.cpp
35+
src/handlers/json/handler.hpp
36+
src/handlers/json/handler.cpp
37+
src/handlers/plaintext/handler.hpp
38+
src/handlers/plaintext/handler.cpp
39+
src/handlers/upload/handler.hpp
40+
src/handlers/upload/handler.cpp
41+
src/handlers/async_db/handler.hpp
42+
src/handlers/async_db/handler.cpp
43+
src/dataset_provider.hpp
44+
src/dataset_provider.cpp
45+
src/middlewares/compression.hpp
46+
src/middlewares/compression.cpp
47+
src/middlewares/compression_pipeline_builder.hpp
48+
)
49+
target_link_libraries(
50+
${PROJECT_NAME}_objs
51+
PUBLIC userver::core #
52+
userver::postgresql
53+
)
54+
55+
# The Service
56+
add_executable(${PROJECT_NAME} src/main.cpp)
57+
target_link_libraries(${PROJECT_NAME} PRIVATE ${PROJECT_NAME}_objs)
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
{
2+
"version": 2,
3+
"cmakeMinimumRequired": {
4+
"major": 3,
5+
"minor": 20,
6+
"patch": 0
7+
},
8+
"configurePresets": [
9+
{
10+
"name": "debug",
11+
"displayName": "Debug",
12+
"description": "Fully featured Debug build",
13+
"inherits": [
14+
"common-flags"
15+
],
16+
"binaryDir": "${sourceDir}/build-debug",
17+
"cacheVariables": {
18+
"CMAKE_BUILD_TYPE": "Debug",
19+
"USERVER_SANITIZE": "ub"
20+
}
21+
},
22+
{
23+
"name": "release",
24+
"displayName": "Release",
25+
"description": "Fully featured Release build",
26+
"inherits": [
27+
"common-flags"
28+
],
29+
"binaryDir": "${sourceDir}/build-release",
30+
"cacheVariables": {
31+
"CMAKE_BUILD_TYPE": "Release"
32+
}
33+
},
34+
{
35+
"name": "common-flags",
36+
"hidden": true,
37+
"generator": "Ninja",
38+
"cacheVariables": {
39+
"USERVER_FEATURE_POSTGRESQL": "ON",
40+
"CMAKE_EXPORT_COMPILE_COMMANDS": "ON"
41+
}
42+
}
43+
]
44+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# userver_httparena
2+
3+
Template of a C++ service that uses [userver framework](https://github.com/userver-framework/userver).
4+
5+
6+
## Download and Build
7+
8+
To create your own userver-based service follow the following steps:
9+
10+
1. Press the "Use this template button" at the top right of this GitHub page
11+
2. Clone the service `git clone your-service-repo && cd your-service-repo && git submodule update --init`
12+
3. Give a proper name to your service and replace all the occurrences of "userver_httparena" string with that name
13+
4. Feel free to tweak, adjust or fully rewrite the source code of your service.
14+
15+
16+
## Makefile
17+
18+
`PRESET` is either `debug`, `release`, or if you've added custom presets in `CMakeUserPresets.json`, it
19+
can also be `debug-custom`, `release-custom`.
20+
21+
* `make cmake-PRESET` - run cmake configure, update cmake options and source file lists
22+
* `make build-PRESET` - build the service
23+
* `make test-PRESET` - build the service and run all tests
24+
* `make start-PRESET` - build the service, start it in testsuite environment and leave it running
25+
* `make install-PRESET` - build the service and install it in directory set in environment `PREFIX`
26+
* `make` or `make all` - build and run all tests in `debug` and `release` modes
27+
* `make format` - reformat all C++ and Python sources
28+
* `make dist-clean` - clean build files and cmake cache
29+
* `make docker-COMMAND` - run `make COMMAND` in docker environment
30+
* `make docker-clean-data` - stop docker containers
31+
32+
33+
## License
34+
35+
The original template is distributed under the [Apache-2.0 License](https://github.com/userver-framework/userver/blob/develop/LICENSE)
36+
and [CLA](https://github.com/userver-framework/userver/blob/develop/CONTRIBUTING.md). Services based on the template may change
37+
the license and CLA.
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
include_guard(GLOBAL)
2+
3+
function(download_userver)
4+
set(OPTIONS)
5+
set(ONE_VALUE_ARGS TRY_DIR VERSION GIT_TAG)
6+
set(MULTI_VALUE_ARGS)
7+
cmake_parse_arguments(ARG "${OPTIONS}" "${ONE_VALUE_ARGS}" "${MULTI_VALUE_ARGS}" ${ARGN})
8+
9+
if(ARG_TRY_DIR)
10+
get_filename_component(ARG_TRY_DIR "${ARG_TRY_DIR}" REALPATH)
11+
if(EXISTS "${ARG_TRY_DIR}")
12+
message(STATUS "Using userver from ${ARG_TRY_DIR}")
13+
add_subdirectory("${ARG_TRY_DIR}" third_party/userver)
14+
return()
15+
endif()
16+
endif()
17+
18+
# CMP0077 and CMP0126 are required for correct option forwarding.
19+
cmake_minimum_required(VERSION 3.21)
20+
include(get_cpm)
21+
22+
if(NOT DEFINED ARG_VERSION AND NOT DEFINED ARG_GIT_TAG)
23+
set(ARG_GIT_TAG develop)
24+
endif()
25+
26+
if(NOT DEFINED CPM_USE_NAMED_CACHE_DIRECTORIES)
27+
set(CPM_USE_NAMED_CACHE_DIRECTORIES ON)
28+
endif()
29+
30+
cpmaddpackage(
31+
NAME
32+
userver
33+
GITHUB_REPOSITORY
34+
userver-framework/userver
35+
VERSION
36+
${ARG_VERSION}
37+
GIT_TAG
38+
${ARG_GIT_TAG}
39+
GIT_SHALLOW TRUE
40+
${ARG_UNPARSED_ARGUMENTS}
41+
)
42+
endfunction()
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# SPDX-License-Identifier: MIT
2+
#
3+
# SPDX-FileCopyrightText: Copyright (c) 2019-2023 Lars Melchior and contributors
4+
5+
set(CPM_DOWNLOAD_VERSION 0.42.1)
6+
set(CPM_HASH_SUM "f3a6dcc6a04ce9e7f51a127307fa4f699fb2bade357a8eb4c5b45df76e1dc6a5")
7+
8+
if(CPM_SOURCE_CACHE)
9+
set(CPM_DOWNLOAD_LOCATION "${CPM_SOURCE_CACHE}/cpm/CPM_${CPM_DOWNLOAD_VERSION}.cmake")
10+
elseif(DEFINED ENV{CPM_SOURCE_CACHE})
11+
set(CPM_DOWNLOAD_LOCATION "$ENV{CPM_SOURCE_CACHE}/cpm/CPM_${CPM_DOWNLOAD_VERSION}.cmake")
12+
else()
13+
set(CPM_DOWNLOAD_LOCATION "${CMAKE_BINARY_DIR}/cmake/CPM_${CPM_DOWNLOAD_VERSION}.cmake")
14+
endif()
15+
16+
# Expand relative path. This is important if the provided path contains a tilde (~)
17+
get_filename_component(CPM_DOWNLOAD_LOCATION ${CPM_DOWNLOAD_LOCATION} ABSOLUTE)
18+
19+
file(DOWNLOAD
20+
https://github.com/cpm-cmake/CPM.cmake/releases/download/v${CPM_DOWNLOAD_VERSION}/CPM.cmake
21+
${CPM_DOWNLOAD_LOCATION} EXPECTED_HASH SHA256=${CPM_HASH_SUM}
22+
)
23+
24+
include(${CPM_DOWNLOAD_LOCATION})

frameworks/userver/userver_benchmark/common/db_helpers.cpp

Lines changed: 0 additions & 83 deletions
This file was deleted.

0 commit comments

Comments
 (0)