Chapter 18: System Initialization and Server Settings
This chapter describes process initialization, socket options, backpressure, capacity, metrics, and graceful shutdown as separate configuration areas.
1. ServerSetting handles process-level initialization
ServerSetting configures signal defaults and the framework logger. Socket options, backpressure, HTTP limits, Worker queue limits, and graceful shutdown belong to each server instance.
2. Initialize signals and logging
stt::file::LogFile log(16384);
if(!log.openFile("logs/sttnet.log", "yyyy-mm-ddThh:mi:ss.sss", " "))
return 1;
// "Chinese" selects Chinese framework messages; other values select English.
stt::system::ServerSetting::init(&log, "English");init() combines setExceptionHandling() and setLogFile(). The logger lifetime extends beyond the network server lifetime.
3. Socket options
ServerSocketOptions options;
options.tcp_no_delay = true;
options.keep_alive = true;
options.keep_alive_idle_seconds = 60;
options.keep_alive_interval_seconds = 10;
options.keep_alive_probe_count = 3;
options.listen_backlog = 4096;
server.setSocketOptions(options);4. Memory, backpressure, and task limits
| Setting | Protection |
|---|---|
setMaxPendingWriteBytes | Caps per-connection memory held for slow clients |
setWriteBudgetPerEvent | Prevents one connection from monopolizing writes |
setMaxHttpHeaderBytes | Rejects oversized HTTP headers |
setMaxPendingWorkerTasks | Rejects work instead of growing an unbounded queue |
setGracefulShutdownTimeout | Bounds close-time draining |
5. Metrics snapshot
const ServerMetricsSnapshot m = server.getMetrics();
std::cout << "connections=" << m.active_connections << '
'
<< "http_requests=" << m.parsed_http_requests << '
'
<< "pending_write_bytes=" << m.pending_write_bytes << '
'
<< "worker_rejections=" << m.worker_task_rejections << '
';6. Framework capacity is not an OS limit
HttpServer(100000, ...) does not raise Linux file-descriptor limits. Actual capacity also depends on ulimit -n, systemd LimitNOFILE, kernel backlogs, and ephemeral ports.