Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 10 additions & 15 deletions frameworks/userver/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,24 +1,19 @@
FROM ghcr.io/userver-framework/ubuntu-24.04-userver-base AS builder
FROM ghcr.io/userver-framework/ubuntu-24.04-userver:v3.0 AS builder

WORKDIR /src
RUN git clone https://github.com/userver-framework/userver.git && \
cd userver && git checkout v3.0

COPY userver_benchmark/ ./
RUN mkdir build && cd build && \
cmake -DUSERVER_IS_THE_ROOT_PROJECT=0 -DUSERVER_FEATURE_CRYPTOPP_BLAKE2=0 \
-DUSERVER_FEATURE_UTEST=0 \
-DUSERVER_FEATURE_POSTGRESQL=1 \
-DUSERVER_FEATURE_ERASE_LOG_WITH_LEVEL=warning \
-DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_FLAGS="-march=native" -DCMAKE_C_FLAGS="-march=native" \
-DCMAKE_CXX_COMPILER=clang++-17 -DCMAKE_C_COMPILER=clang-17 \
-DUSERVER_LTO=0 .. && \
make -j $(nproc)
cmake -DCMAKE_BUILD_TYPE=Release \
-DCMAKE_CXX_FLAGS="-march=native" \
-DCMAKE_C_FLAGS="-march=native" .. && \
cmake --build . -j $(nproc)


FROM builder AS runner
WORKDIR /app
COPY userver_configs/* ./
COPY --from=builder /src/configs/config-vars.httparena.yaml ./configs/config_vars.yaml
COPY --from=builder /src/configs/static_config.yaml ./configs/
COPY --from=builder /src/build/userver_httparena ./

EXPOSE 8080
CMD ./userver_httparena -c ./static_config.yaml
EXPOSE 8080 8443 8081
CMD ./userver_httparena -c ./configs/static_config.yaml
8 changes: 7 additions & 1 deletion frameworks/userver/meta.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,13 @@
"baseline",
"pipelined",
"limited-conn",
"static"
"json",
"json-comp",
"upload",
"api-4",
"api-16",
"static",
"async-db"
],
"maintainers": ["botanegg"]
}
1 change: 1 addition & 0 deletions frameworks/userver/userver_benchmark/.clang-format
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
BasedOnStyle: google
DerivePointerAlignment: false
IncludeBlocks: Preserve
ColumnLimit: 120
18 changes: 18 additions & 0 deletions frameworks/userver/userver_benchmark/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
__pycache__
build*/
compile_commands.json
.cache/
.ccache/
.idea/
.vscode/
!.vscode/c_cpp_properties.json
!.vscode/cmake-variants.yaml
!.vscode/README.md
.cores/
cmake-build-*
Testing/
.DS_Store
Makefile.local
CMakeUserPresets.json
configs/secure_data.json
third_party/
60 changes: 50 additions & 10 deletions frameworks/userver/userver_benchmark/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,17 +1,57 @@
cmake_minimum_required(VERSION 3.12)
cmake_minimum_required(VERSION 3.12...3.31)
project(userver_httparena CXX)

set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD 23)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

file(GLOB_RECURSE SOURCES
${CMAKE_CURRENT_SOURCE_DIR}/controllers/*.cpp
${CMAKE_CURRENT_SOURCE_DIR}/common/*.cpp
)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
include(DownloadUserver)

#boost context find problem hack
find_package(Boost CONFIG REQUIRED COMPONENTS context)

include(GNUInstallDirs)
find_package(
userver
COMPONENTS core #
postgresql
QUIET
)
if (NOT userver_FOUND)
# Tries TRY_DIR first, falls back to downloading userver from GitHub using CPM.
download_userver(TRY_DIR third_party/userver)
endif ()

add_subdirectory(userver)
userver_setup_environment()

add_executable(${PROJECT_NAME} ${SOURCES} userver_httparena.cpp)
target_link_libraries(${PROJECT_NAME} PRIVATE userver-core userver-postgresql userver-llhttp)
# Common sources
include_directories(src)

add_library(
${PROJECT_NAME}_objs OBJECT
src/handlers/baseline11/handler.hpp
src/handlers/baseline11/handler.cpp
src/handlers/baseline2/handler.hpp
src/handlers/baseline2/handler.cpp
src/handlers/json/handler.hpp
src/handlers/json/handler.cpp
src/handlers/plaintext/handler.hpp
src/handlers/plaintext/handler.cpp
src/handlers/upload/handler.hpp
src/handlers/upload/handler.cpp
src/handlers/async_db/handler.hpp
src/handlers/async_db/handler.cpp
src/dataset_provider.hpp
src/dataset_provider.cpp
src/middlewares/compression.hpp
src/middlewares/compression.cpp
src/middlewares/compression_pipeline_builder.hpp
)
target_link_libraries(
${PROJECT_NAME}_objs
PUBLIC userver::core #
userver::postgresql
)

# The Service
add_executable(${PROJECT_NAME} src/main.cpp)
target_link_libraries(${PROJECT_NAME} PRIVATE ${PROJECT_NAME}_objs)
44 changes: 44 additions & 0 deletions frameworks/userver/userver_benchmark/CMakePresets.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
{
"version": 2,
"cmakeMinimumRequired": {
"major": 3,
"minor": 20,
"patch": 0
},
"configurePresets": [
{
"name": "debug",
"displayName": "Debug",
"description": "Fully featured Debug build",
"inherits": [
"common-flags"
],
"binaryDir": "${sourceDir}/build-debug",
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Debug",
"USERVER_SANITIZE": "ub"
}
},
{
"name": "release",
"displayName": "Release",
"description": "Fully featured Release build",
"inherits": [
"common-flags"
],
"binaryDir": "${sourceDir}/build-release",
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Release"
}
},
{
"name": "common-flags",
"hidden": true,
"generator": "Ninja",
"cacheVariables": {
"USERVER_FEATURE_POSTGRESQL": "ON",
"CMAKE_EXPORT_COMPILE_COMMANDS": "ON"
}
}
]
}
37 changes: 37 additions & 0 deletions frameworks/userver/userver_benchmark/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# userver_httparena

Template of a C++ service that uses [userver framework](https://github.com/userver-framework/userver).


## Download and Build

To create your own userver-based service follow the following steps:

1. Press the "Use this template button" at the top right of this GitHub page
2. Clone the service `git clone your-service-repo && cd your-service-repo && git submodule update --init`
3. Give a proper name to your service and replace all the occurrences of "userver_httparena" string with that name
4. Feel free to tweak, adjust or fully rewrite the source code of your service.


## Makefile

`PRESET` is either `debug`, `release`, or if you've added custom presets in `CMakeUserPresets.json`, it
can also be `debug-custom`, `release-custom`.

* `make cmake-PRESET` - run cmake configure, update cmake options and source file lists
* `make build-PRESET` - build the service
* `make test-PRESET` - build the service and run all tests
* `make start-PRESET` - build the service, start it in testsuite environment and leave it running
* `make install-PRESET` - build the service and install it in directory set in environment `PREFIX`
* `make` or `make all` - build and run all tests in `debug` and `release` modes
* `make format` - reformat all C++ and Python sources
* `make dist-clean` - clean build files and cmake cache
* `make docker-COMMAND` - run `make COMMAND` in docker environment
* `make docker-clean-data` - stop docker containers


## License

The original template is distributed under the [Apache-2.0 License](https://github.com/userver-framework/userver/blob/develop/LICENSE)
and [CLA](https://github.com/userver-framework/userver/blob/develop/CONTRIBUTING.md). Services based on the template may change
the license and CLA.
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
include_guard(GLOBAL)

function(download_userver)
set(OPTIONS)
set(ONE_VALUE_ARGS TRY_DIR VERSION GIT_TAG)
set(MULTI_VALUE_ARGS)
cmake_parse_arguments(ARG "${OPTIONS}" "${ONE_VALUE_ARGS}" "${MULTI_VALUE_ARGS}" ${ARGN})

if(ARG_TRY_DIR)
get_filename_component(ARG_TRY_DIR "${ARG_TRY_DIR}" REALPATH)
if(EXISTS "${ARG_TRY_DIR}")
message(STATUS "Using userver from ${ARG_TRY_DIR}")
add_subdirectory("${ARG_TRY_DIR}" third_party/userver)
return()
endif()
endif()

# CMP0077 and CMP0126 are required for correct option forwarding.
cmake_minimum_required(VERSION 3.21)
include(get_cpm)

if(NOT DEFINED ARG_VERSION AND NOT DEFINED ARG_GIT_TAG)
set(ARG_GIT_TAG develop)
endif()

if(NOT DEFINED CPM_USE_NAMED_CACHE_DIRECTORIES)
set(CPM_USE_NAMED_CACHE_DIRECTORIES ON)
endif()

cpmaddpackage(
NAME
userver
GITHUB_REPOSITORY
userver-framework/userver
VERSION
${ARG_VERSION}
GIT_TAG
${ARG_GIT_TAG}
GIT_SHALLOW TRUE
${ARG_UNPARSED_ARGUMENTS}
)
endfunction()
24 changes: 24 additions & 0 deletions frameworks/userver/userver_benchmark/cmake/get_cpm.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# SPDX-License-Identifier: MIT
#
# SPDX-FileCopyrightText: Copyright (c) 2019-2023 Lars Melchior and contributors

set(CPM_DOWNLOAD_VERSION 0.42.1)
set(CPM_HASH_SUM "f3a6dcc6a04ce9e7f51a127307fa4f699fb2bade357a8eb4c5b45df76e1dc6a5")

if(CPM_SOURCE_CACHE)
set(CPM_DOWNLOAD_LOCATION "${CPM_SOURCE_CACHE}/cpm/CPM_${CPM_DOWNLOAD_VERSION}.cmake")
elseif(DEFINED ENV{CPM_SOURCE_CACHE})
set(CPM_DOWNLOAD_LOCATION "$ENV{CPM_SOURCE_CACHE}/cpm/CPM_${CPM_DOWNLOAD_VERSION}.cmake")
else()
set(CPM_DOWNLOAD_LOCATION "${CMAKE_BINARY_DIR}/cmake/CPM_${CPM_DOWNLOAD_VERSION}.cmake")
endif()

# Expand relative path. This is important if the provided path contains a tilde (~)
get_filename_component(CPM_DOWNLOAD_LOCATION ${CPM_DOWNLOAD_LOCATION} ABSOLUTE)

file(DOWNLOAD
https://github.com/cpm-cmake/CPM.cmake/releases/download/v${CPM_DOWNLOAD_VERSION}/CPM.cmake
${CPM_DOWNLOAD_LOCATION} EXPECTED_HASH SHA256=${CPM_HASH_SUM}
)

include(${CPM_DOWNLOAD_LOCATION})
83 changes: 0 additions & 83 deletions frameworks/userver/userver_benchmark/common/db_helpers.cpp

This file was deleted.

Loading