Skip to content

Zhigalov/load-testing-lecture-2025

Repository files navigation

This repository is for userver v2.8 or older versions. For newer versions of userver please use userver-create-service script.

pg_clck

Template of a C++ service that uses userver framework with PostgreSQL.

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
  3. Give a proper name to your service and replace all the occurrences of "clck" string with that name (could be done via find . -not -path "./third_party/*" -not -path ".git/*" -not -path './build-*' -type f | xargs sed -i 's/clck/YOUR_SERVICE_NAME/g').
  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 and clean database data

License

The original template is distributed under the Apache-2.0 License and CLA. Services based on the template may change the license and CLA.

Run

  1. Run tests
make cmake-debug && make test-debug
  1. Create top_secret.yamyamll file:
// cat ~/top_secret.yaml
worker-threads: 4
worker-fs-threads: 2
logger-level: info
is-testing: false
server-port: 8080
dbconnection: '<connection_string>'
  1. Build release
make cmake-release && make build-release
  1. Run server
./build-release/clck --config configs/static_config.yaml --config_vars ~/top_secret.yaml
  1. Curl
curl http://158.160.81.197:8080/unknown/1 -v
< HTTP/1.1 404 Not Found
Url not found

curl http://158.160.81.197:8080/v1/create -d '{"url": "https://dostavka.yandex.ru/"}' -v
< HTTP/1.1 200 OK
{"short_url":"http://158.160.81.197:8080/Xp3k/1","hash":"Xp3k","version":1}

curl http://158.160.81.197:8080/Xp3k/1
https://dostavka.yandex.ru/

About

Userver example service for load testing

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published