Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

apostoldevel/apostol

Open more actions menu

Repository files navigation

ru

apostol-v2

Apostol (A-POST-OL)

Apostol is a template project (demo build) for the libapostol C++20 framework -- a high-performance platform for backend applications and system services on Linux with direct access to PostgreSQL.

A-POST-OL -> Asynchronous POST Orchestration Loop -- a single event loop for HTTP and PostgreSQL.


Table of Contents


Overview

Apostol is written in C++20 using an asynchronous programming model based on the epoll API, with direct access to PostgreSQL via libpq. The framework is targeted at high-load systems.

The key element is the built-in HTTP server running in a single event loop together with PostgreSQL connections.

What makes it different:

  • The HTTP server and PostgreSQL sockets live in a single event loop.
  • Data flows directly between the HTTP server and the database -- no intermediate scripting layers (PHP, Python, etc.).
  • This minimizes latency and overhead and provides predictable performance.

Main advantages:

  • Autonomy -- after building, you get a ready-to-run Linux daemon binary.
  • Speed -- handling HTTP requests and executing SQL queries is as fast as your OS and DBMS allow.
  • Connection pool -- built-in configurable PostgreSQL connection pool.
  • Modularity -- applications are assembled from independent modules like building blocks.

The framework itself lives in a separate repository and is included as a git submodule.


Benchmark

Apostol v2 vs v1 vs Python vs Node.js vs Go vs Nginx -- comparative benchmark under identical Docker conditions (wrk, 4 threads, 10s duration, 4 workers).

/ping -- direct (keep-alive ON, 100 connections)

Service RPS Latency p50
Nginx (static return) 566,000 111us
Apostol v2 507,000 170us
Go (net/http) 211,000 447us
Apostol v1 128,000 790us
Node.js (Fastify) 102,000 0.95ms
Python (FastAPI) 2,400 41ms

/db/ping -- direct (keep-alive ON, 100 connections)

Service RPS Latency p50
Apostol v2 112,000 0.91ms
Go 72,000 1.07ms
Apostol v1 61,000 1.61ms
Node.js 36,000 2.65ms
Python 2,300 42ms

/ping -- via Nginx proxy (keep-alive ON, 100 connections)

Service RPS Latency p50
Apostol v2 70,000 1.07ms
Go 38,000 2.06ms
Apostol v1 16,000 3.18ms
Node.js 5,900 14.29ms
Python 5,500 14.62ms

Key findings:

  • Apostol v2 reaches 90% of Nginx throughput on /ping (507K vs 566K)
  • On /ping keep-alive OFF, Apostol v2 matches Nginx at c100 (84K each, both use SO_REUSEPORT) and leads at c1000 (81K vs 75K)
  • On /db/ping, Apostol v2 leads with 112K RPS -- 1.6x faster than Go, 1.8x faster than v1
  • Through Nginx proxy, Apostol v2 maintains the highest throughput at 70K RPS

Full results, methodology, and analysis: REST API Benchmark.


Modules

The framework has a modular architecture with built-in UDP/TCP/WebSocket/HTTP servers and an asynchronous PostgreSQL client.

This build includes three modules

Module Type Description
PGHTTP Worker HTTP to PostgreSQL function dispatcher -- implement REST API logic in PL/pgSQL
WebServer Worker Static file serving with built-in Swagger UI
PGFetch Helper LISTEN/NOTIFY driven HTTP fetch -- send HTTP requests from PL/pgSQL

More details about this build: article.

Additional modules

With additional modules Apostol can be turned into:

For a full CRM build with all modules see apostol-crm.


Projects

Real-world projects built with Apostol:

  • CopyFrog -- AI-based platform for generating ad copy, video creatives, and marketing descriptions;
  • ChargeMeCar -- central system for charging stations (OCPP);
  • Campus Caster & Campus CORS -- NTRIP caster for real-time GNSS corrections;
  • Talking to AI -- ChatGPT integration in a Telegram bot;
  • PlugMe -- CRM system for charging stations and EV owners;
  • DEBT Master -- debt collection automation system;
  • Ship Safety ERP -- ERP system for shipping companies;
  • BitDeals -- bitcoin payment processing service.

Architecture

apostol/
├── src/
│   ├── app/main.cpp                  — application entry point
│   ├── lib/libapostol/               — framework (git submodule)
│   └── modules/
│       ├── Workers/                  — HTTP request handlers
│       │   ├── PGHTTP/              — git submodule
│       │   └── WebServer/           — git submodule
│       └── Helpers/                  — background tasks
│           └── PGFetch/             — git submodule
├── conf/default.json                 — configuration
├── www/                              — web files (Swagger UI, etc.)
└── docker-compose.yaml               — Docker environment

Each module is a separate git submodule -- add or remove modules to build exactly the application you need.


Quick start with Docker

The fastest way to try Apostol -- Docker Compose with PostgreSQL, PgBouncer, and pgweb:

git clone --recursive https://github.com/apostoldevel/apostol.git
cd apostol
./docker-build.sh
docker compose up

After startup:

Instead of pgweb, you can use any other tool for working with PostgreSQL. PostgreSQL inside the container is available on port 5433.


Build from source

Dependencies (Debian/Ubuntu)

sudo apt-get install build-essential cmake cmake-data g++ \
    libssl-dev libcurl4-openssl-dev libpq-dev zlib1g-dev

Clone and build

git clone --recursive https://github.com/apostoldevel/apostol.git
cd apostol
./configure
cmake --build cmake-build-release --parallel $(nproc)

Or manually:

cmake -B build -DCMAKE_BUILD_TYPE=Release
cmake --build build --parallel $(nproc)

Install

sudo cmake --install cmake-build-release

By default, the apostol binary is installed into /usr/sbin, configuration files into /etc/apostol/.

Minimal build (no PostgreSQL, no SSL, no libcurl)

./configure --without-postgresql --without-ssl --without-curl
cmake --build cmake-build-release --parallel $(nproc)

Configuration

Default config: conf/default.json

After install the configuration is stored at /etc/apostol/apostol.json.

Key settings:

Setting Default Description
server.port 4977 HTTP listen port
server.listen 127.0.0.1 Listen address
server.backlog 4096 TCP listen backlog
daemon.enabled false Run as daemon
process.master true Master/worker mode
process.helper true Enable helper process
postgres.worker Worker DB connection
postgres.helper Helper DB connection

Running

# Foreground
./cmake-build-release/apostol

# As a daemon
./cmake-build-release/apostol -d

# Test configuration
./cmake-build-release/apostol -t

# Systemd service (after install)
sudo systemctl start apostol

systemd status example

● apostol.service - Apostol
     Loaded: loaded (/lib/systemd/system/apostol.service; enabled)
     Active: active (running)
   Main PID: 461163 (apostol)
     CGroup: /system.slice/apostol.service
             ├─461163 apostol: master process /usr/sbin/apostol
             └─461164 apostol: worker process ("pq fetch", "web server")

Process control

Signal Command Action
SIGTERM -s stop Fast shutdown
SIGQUIT -s quit Graceful shutdown
SIGHUP -s reload Reload config
SIGUSR1 -s reopen Reopen log files

Creating your own project

This repository is a starting point. To create your own application:

  1. Fork or copy this repo
  2. Add the modules you need as git submodules (see available modules)
  3. Register them in Workers.hpp / Helpers.hpp
  4. Customize conf/default.json and main.cpp

For automated project scaffolding see the install script in libapostol.


Links

License

Apostol is registered as computer software: Certificate of State Registration (in Russian).

MIT

Releases

Packages

Used by

Contributors

Languages

Morty Proxy This is a proxified and sanitized view of the page, visit original site.