1
0
mirror of https://github.com/coturn/coturn.git synced 2025-08-07 06:47:07 +02:00
coturn/man/man1
Copilot 99984fbccd
Add configurable CPU count option for containerized environments (#1717)
This PR adds a new `--cpus` configuration option to address CPU
detection issues in virtualized and containerized environments where
`_SC_NPROCESSORS_CONF` and `_SC_NPROCESSORS_ONLN` return host CPU counts
instead of allocated container CPUs.

## Problem
In containerized deployments, coturn detects the host's CPU count (e.g.,
128 CPUs) instead of the container's allocated CPUs (e.g., 2 CPUs). This
causes the server to create excessive relay threads and database
connections, leading to resource exhaustion and performance issues.

## Solution
Added a new `cpus` configuration option that allows manual override of
CPU detection:

### Command Line Usage
```bash
turnserver --cpus 2
```

### Configuration File Usage
```ini
# Override system CPU count detection for containers
cpus=2
```

## Key Features
- **Backward Compatible**: No changes needed for existing deployments
- **Input Validation**: Values must be between 1 and 128 with proper
error handling
- **Comprehensive Documentation**: Updated man pages and example config
files
- **Both Interfaces**: Works via command line and configuration file

## Testing
The implementation has been thoroughly tested:

```bash
# Container with 2 allocated CPUs on 128-CPU host
$ turnserver --cpus 2
INFO: System cpu num is 128       # Host detection
INFO: System enable num is 128    # Host detection  
INFO: Configured cpu num is 2     # Override applied
INFO: Total General servers: 2    # Correct thread count
```

-  Command line option: `--cpus 8` creates 8 relay servers
-  Config file option: `cpus=6` creates 6 relay servers  
-  Error handling: Invalid values show appropriate errors
-  Default behavior: Without option, uses system detection
-  RFC5769 tests: All protocol tests still pass

## Files Modified
- `src/apps/relay/mainrelay.c` - Core implementation
- `src/apps/relay/mainrelay.h` - Added configuration flag
- `examples/etc/turnserver.conf` - Added documentation and example
- `man/man1/turnserver.1` - Updated man page

This change directly addresses the resource consumption issues in
containerized environments while maintaining full backward
compatibility.

Fixes #1628.
2025-07-10 15:37:02 +02:00
..
coturn.1 initial code import 2014-04-20 21:10:18 +00:00
turnadmin.1 Regenerate manual pages from README files (#1117) 2022-12-06 17:04:13 -08:00
turnserver.1 Add configurable CPU count option for containerized environments (#1717) 2025-07-10 15:37:02 +02:00
turnutils_natdiscovery.1 new link for natdiscovery to turnutils, and newly generated man pages 2016-09-04 06:10:26 +02:00
turnutils_oauth.1 Add turnutils_oauth to README.turnutils 2016-09-07 15:28:27 +02:00
turnutils_peer.1 initial code import 2014-04-20 21:10:18 +00:00
turnutils_stunclient.1 initial code import 2014-04-20 21:10:18 +00:00
turnutils_uclient.1 initial code import 2014-04-20 21:10:18 +00:00
turnutils.1 Fix typos (#1345) 2024-01-15 18:31:16 -08:00