Skip to content

CMake Configuration Guide ​

Overview ​

UVHTTP supports configuring various compile-time constants through CMake, allowing you to adjust the library's behavior and performance to suit your needs.

Configuration Methods ​

1. Basic Configuration ​

Edit the option() or set() configuration constants in CMakeLists.txt, then run make build:

bash
make build

Preconfigure the build in CMakeLists.txt:

cmake
set(UVHTTP_MAX_HEADER_NAME_SIZE 512 CACHE STRING "Max HTTP header name size")
set(UVHTTP_MAX_HEADER_VALUE_SIZE 8192 CACHE STRING "Max HTTP header value size")

Configurable Constants ​

ConstantDefaultDescriptionRecommended
UVHTTP_MAX_HEADER_NAME_SIZE256Maximum HTTP header name length256-512
UVHTTP_MAX_HEADER_VALUE_SIZE4096Maximum HTTP header value length4096-8192
UVHTTP_MAX_HEADERS64Maximum number of HTTP headers32-128
UVHTTP_MAX_URL_SIZE2048Maximum URL length2048-4096
UVHTTP_MAX_PATH_SIZE1024Maximum path length512-2048
UVHTTP_MAX_METHOD_SIZE16Maximum HTTP method length16
UVHTTP_MAX_BODY_SIZE1048576Maximum request body size (bytes)Adjust per requirements

Connection Management ​

ConstantDefaultDescriptionRecommended
UVHTTP_MAX_CONNECTIONS_DEFAULT2048Default maximum number of connections1024-4096
UVHTTP_MAX_CONNECTIONS_MAX10000Maximum recommended number of connections10000-100000
UVHTTP_BACKLOG8192TCP backlog size1024-8192
UVHTTP_CONNECTION_TIMEOUT_DEFAULT60Connection timeout (seconds)30-120
UVHTTP_TCP_KEEPALIVE_TIMEOUT60TCP keepalive timeout (seconds)30-120

Buffer Management ​

ConstantDefaultDescriptionRecommended
UVHTTP_INLINE_HEADERS_CAPACITY32Inline header capacity16-64
UVHTTP_INITIAL_BUFFER_SIZE8192Initial buffer size (bytes)8192-16384
UVHTTP_READ_BUFFER_SIZE16384Read buffer size (bytes)16384-65536

Static File Serving ​

ConstantDefaultDescriptionRecommended
UVHTTP_STATIC_MAX_CACHE_SIZE1048576Static file cache size (bytes)Adjust per memory
UVHTTP_STATIC_MAX_PATH_SIZE1024Maximum static file path length512-2048
UVHTTP_STATIC_MAX_FILE_SIZE10485760Maximum static file size (bytes)Adjust per requirements
UVHTTP_STATIC_SMALL_FILE_THRESHOLD4096Small file threshold (bytes)4096-8192

WebSocket ​

ConstantDefaultDescriptionRecommended
UVHTTP_WEBSOCKET_DEFAULT_MAX_FRAME_SIZE16777216Maximum WebSocket frame size (bytes)Adjust per requirements
UVHTTP_WEBSOCKET_DEFAULT_MAX_MESSAGE_SIZE67108864Maximum WebSocket message size (bytes)Adjust per requirements
UVHTTP_WEBSOCKET_DEFAULT_RECV_BUFFER_SIZE65536WebSocket receive buffer size (bytes)32768-131072
UVHTTP_WEBSOCKET_DEFAULT_PING_INTERVAL30WebSocket ping interval (seconds)10-60
UVHTTP_WEBSOCKET_DEFAULT_PING_TIMEOUT10WebSocket ping timeout (seconds)5-30

Asynchronous File Operations ​

ConstantDefaultDescriptionRecommended
UVHTTP_ASYNC_FILE_BUFFER_SIZE65536Async file buffer size (bytes)32768-131072
UVHTTP_ASYNC_FILE_MAX_CONCURRENT64Maximum concurrent file reads32-128
UVHTTP_ASYNC_FILE_MAX_SIZE10485760Maximum async file size (bytes)Adjust per requirements

Performance Optimization ​

ConstantDefaultDescriptionRecommended
UVHTTP_SENDFILE_CHUNK_SIZE65536sendfile chunk size (bytes)32768-131072
UVHTTP_SENDFILE_TIMEOUT_MS30000sendfile timeout (milliseconds)10000-60000
UVHTTP_STATIC_MAX_CACHE_SIZE10485760Static file cache size (bytes, 10MB)5242880-52428800
UVHTTP_LRU_CACHE_BATCH_EVICTION_SIZE2LRU cache batch eviction size1-10
UVHTTP_ZEROCOPY_MIN_BODY4096Minimum response body size (bytes) using the zero-copy writev send path4096-8192

Rate Limiting ​

ConstantDefaultDescriptionRecommended
UVHTTP_RATE_LIMIT_MAX_REQUESTS1000000Maximum number of rate-limit requestsAdjust per requirements
UVHTTP_RATE_LIMIT_MAX_WINDOW_SECONDS86400Maximum rate-limit time window (seconds)Adjust per requirements
UVHTTP_RATE_LIMIT_MIN_TIMEOUT_SECONDS10Minimum rate-limit timeout (seconds)5-30

Other ​

ConstantDefaultDescriptionRecommended
UVHTTP_CLIENT_IP_BUFFER_SIZE64Client IP buffer size64
UVHTTP_IP_OCTET_MAX_VALUE255Maximum IP octet value255

Configuration Examples ​

Example 1: High Concurrency Scenario ​

Edit CMakeLists.txt, add or modify the following configuration, then run make build:

bash
make build

Example 2: Large File Transfer ​

Edit CMakeLists.txt, add or modify the following configuration, then run make build:

bash
make build

Example 3: Memory-Constrained Environments ​

Edit CMakeLists.txt, add or modify the following configuration, then run make build:

bash
make build

Example 4: WebSocket Optimization ​

Edit CMakeLists.txt, add or modify the following configuration, then run make build:

bash
make build

Notes ​

  1. Memory Impact: Increasing buffer and cache sizes increases memory usage
  2. Performance Trade-off: Larger buffers can improve performance but increase memory usage
  3. Platform Limitations: Some values are constrained by operating system limits (such as the number of file descriptors)
  4. Test Verification: Conduct thorough performance testing after modifying configuration
  5. Documentation Updates: If you change default values, please update the relevant documentation

Verifying Configuration ​

After compilation, you can verify your configuration in the following ways:

bash
# Build the project
make build

# View macro definitions in the compile commands
grep UVHTTP_MAX_HEADER_NAME_SIZE build/CMakeCache.txt

# Run tests to verify
./dist/bin/uvhttp_unit_tests

Released under MIT License