DataPath

Contributing to DataPath

Thanks for helping out. This file covers building, testing and benchmarking DataPath. For what the library does and how to use it, see README.md.

Building

Requires CMake 3.16+ and a C++17 compiler (MSVC 2019+, GCC 9+, Clang 10+) for the tests and samples. The library itself builds with C++11 or newer (C++14 or newer on MSVC).

cmake -S . -B build -DCMAKE_BUILD_TYPE=Release
cmake --build build --config Release
ctest --test-dir build -C Release --output-on-failure

Options: DATAPATH_SHARED (shared library, default OFF), DATAPATH_CXX_STANDARD (standard the library is built with, default 17 or CMAKE_CXX_STANDARD; tests and samples use at least 17), DATAPATH_BUILD_TESTS and DATAPATH_BUILD_SAMPLES (default ON for top-level builds). The datapath::datapath target can be used through add_subdirectory.

Library code (include/, source/) must build as C++11. When a newer standard library facility helps, use it through source/common/compat.hpp, which picks it by feature-test macro (__cpp_lib_*) and falls back to a local equivalent; CI builds the library as C++11, C++14 (MSVC) and C++23. Tests, samples and bindings may use C++17.

The shared library exports only what public headers mark with DATAPATH_API (from the generated datapath/export.h); everything else stays hidden. Mark any new public function or class with it. Tests that reach into internals (source/) pass INTERNAL to datapath_add_test so they still link in a shared build.

Cross-compiling for Windows from Linux with mingw-w64 (tests run through Wine if it's installed):

cmake -S . -B build-mingw -DCMAKE_TOOLCHAIN_FILE=cmake/toolchains/mingw-w64.cmake

Testing

Run the whole suite with ctest as shown above before sending a change. Unix-only and Windows-only tests (tests/test_posix.cpp for Linux and macOS, tests/test_windows_security.cpp) build only on their platforms, so a change to a platform backend should be tested on that platform. On Linux, an AddressSanitizer build catches most lifetime bugs in the handler and close paths:

cmake -S . -B build-asan -DCMAKE_BUILD_TYPE=Debug -DCMAKE_CXX_FLAGS="-fsanitize=address -fno-omit-frame-pointer"

Benchmarking

datapath-benchmark local starts an echo server in a second process and runs the client against it:

./build/samples/datapath-benchmark local

On Windows, run build\samples\Release\datapath-benchmark.exe local. Useful variations: * --spin 0 measures without busy-polling. * --load adds a 1 MiB bulk stream on a second connection and reports its throughput. * --clients 8 runs eight concurrent ping-pong connections. * --threads 2 uses two I/O threads per process. * --threads auto uses one I/O thread per physical core (context_options::io_threads = 0). Compare it with --ideal-core off on Windows to see what pairing threads with cores does. * --stress 0 loads every logical core from a separate process; on Linux, --stress-nice N runs that process at nice N to test the priority gap. * --pin C,S pins the client process to logical CPU C and the server process to S. Use it with --stress: without it, each invocation's latency depends on where the scheduler happens to put the two I/O threads (on Irkela, 16 KiB p99.9 was 15 µs with both on the two hyper-threads of one core, ~200 µs on separate cores, and ~1.1 ms when one of them was on core 0), for DataPath and libuv alike. Each run prints which CPUs handled the messages (cpus lines). * --sizes 8,64,4096 picks the message sizes. The default is 8 B to 64 KiB; add 1048576,16777216 to measure bulk-sized messages.

You can also run server <name> and client <name> separately, in two terminals.

Single runs are noisy at microsecond resolution. --runs 5 repeats every size five times and reports the median, plus the lowest and highest p99.9 of any run. samples\benchmark\matrix.cmd (Windows) and samples/benchmark/matrix.sh (Linux) run every option combination that way and collect the output in benchmark-results.txt.

datapath-benchmark-c is the same harness over the C API (datapath.h) instead of the C++ API. It accepts the same options and the matrix scripts include it when it exists. A core that only exports the C API can be compared against these runs.

For stable numbers on Windows, use the High Performance power plan. Run from a foreground console and close CPU-heavy applications.

Comparing with libuv, cpp-ipc and Boost.Interprocess

Configure with -DDATAPATH_BUILD_COMPARE=ON to also build libuv-benchmark; CMake downloads libuv 1.52.1. It runs the same harness over libuv named pipes / Unix sockets: same framing, clock, sizes, --runs, --stress. It also uses the same --spin, --priority and --mmcss policy on its loop thread, so both libraries can be compared with identical settings. libuv itself has none of these, so use --spin 0 --no-mmcss --priority 0 to measure libuv as it ships. The matrix scripts include libuv runs when the executable exists.

The same option also builds cppipc-benchmark (cpp-ipc, pinned commit) and boost-benchmark (Boost.Interprocess message_queue; an installed Boost 1.80+ is used if CMake finds one, otherwise Boost 1.92 is downloaded). On Windows, boost-native-benchmark is the same with BOOST_INTERPROCESS_FORCE_NATIVE_EMULATION, Windows kernel primitives instead of Boost's default spin-lock emulation. They take the same options; --spin 0 --no-mmcss --priority 0 measures each library's own waiting, the defaults add DataPath's spin and priority to the receive thread. cpp-ipc and Boost keep named shared-memory objects (/dev/shm on Linux, C:\ProgramData\boost_interprocess for Boost on Windows); the benchmarks remove theirs on exit, but a killed run leaves them behind.

When you report numbers, lead with p99.9, say which machine, OS and power plan they came from, and give the flags. A p50 improvement that costs tail latency is a regression for this project. Published numbers use worst-case placement: --pin the client and server to different physical cores, on different CCDs and NUMA nodes where the machine has them (methodology).

Python bindings

The bindings live in bindings/python/ (nanobind, built by scikit-build-core from pyproject.toml in the repository root). Build and test them with:

pip install . pytest
pytest bindings/python/tests

For quicker iteration, configure CMake with -DDATAPATH_BUILD_PYTHON=ON; the build tree then has an importable package in build/bindings/python/package, so PYTHONPATH=build/bindings/python/package pytest bindings/python/tests tests it without installing. Release wheels are built by .github/workflows/python.yml with cibuildwheel (settings in pyproject.toml); uploads happen in release.yml (see Releasing).

bindings/python/benchmarks/pingpong.py local measures Python round trips; add --cpp-server build/samples/datapath-benchmark to echo from the C++ server, and --mode callback to receive in callbacks instead of recv().

Versioning

DataPath follows Semantic Versioning: MAJOR changes on any API- or ABI-incompatible change (the shared library's SOVERSION is MAJOR), MINOR on compatible additions, PATCH on compatible fixes. The version lives in CMakeLists.txt (DATAPATH_VERSION_MAJOR/MINOR/PATCH); the Python package reads it from there, and bindings/node/package.json and bindings/rust/Cargo.toml (plus the = dependency in bindings/rust/datapath/Cargo.toml) must carry the same number. Wire-protocol versions are separate and unrelated.

Releasing

  1. Bump the version (see Versioning) in a pull request and merge it.
  2. Tag the merge commit vX.Y.Z and push the tag. .github/workflows/release.yml checks that every package carries that version, builds everything, runs npm publish --dry-run, cargo publish --dry-run and twine check, uploads the Python packages to TestPyPI, and creates a draft GitHub Release with the source tarball and prebuilt C/C++ archives (static and shared, Release and Debug).
  3. Start release.yml by hand on the tag with target release to publish to PyPI, npm and crates.io. Each registry's GitHub environment (testpypi, pypi, npm, crates-io) can require approval. A manual run waits for the tag run to finish.
  4. Publish the draft GitHub Release. C/C++ users consume the release archives (CMake find_package(datapath) or pkg-config) or the tag through FetchContent; there are no vcpkg, Conan or distribution packages.

Pull requests

View this page on GitHub