RTMP Server
A lightweight RTMP live streaming server written in pure PHP, with no third-party streaming service dependencies. Deploy your private live streaming platform out of the box.
Automatically enables epoll event-driven I/O on Linux, easily handling 20,000+ concurrent connections in a single process. Falls back to select mode on Windows for compatibility.
ποΈ System Architecture
γPublishingγOBS/FFmpeg
β
RTMP Push(1935) / HTTP-FLV Push(8501)
β
βΌ
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β RTMP Origin Server (Core) β
β β
β π₯ Stream Ingest RTMP / HTTP-FLV dual-protocol publishing, link authentication β
β π Protocol Conv RTMP / HTTP-FLV β HTTP-FLV / WebSocket-FLV / HLS / fMP4 / MP4 β
β πΎ Live Recording ββββββββββββββββ¬βββββββββββββββ¬βββββββββββββββ β
β β FLV Record β fMP4 Segs β HLS Segs β Three independent parallel tasks β
β β (real-time) β (real-time) β (real-time) β β
β ββββββββββββββββ΄βββββββββββββββ΄βββββββββββββββ β
β π€ Live Output HTTP-FLV(8501) / WebSocket-FLV / HLS Live / fMP4 Live β
β π¦ VOD Production fMP4 segments generated in real-time β auto-merged into complete MP4 after stream ends β
β π Static Serving Origin server built-in HTTP service (port 80), direct static file access (for low-concurrency scenarios) β
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β
βββββββββββββββββββββββββΌββββββββββββββββββββββββ
β β β
βΌ βΌ βΌ
HTTP-FLV(8501) HLS(TS/m3u8) fMP4(segments)
Real-time Stream Static Files Static Files
β β β
β β β
βΌ βΌ βΌ
βββββββββββββββββββ βββββββββββββββββββββββββββββββββββββββββββββββββββ
β FLV Gateway β β Static File Gateway Cluster β
β Cluster β β π― Hosting: HLS / fMP4 / MP4 / FLV / Webβ
β β β β
β βββββββββββββ β β βββββββββββββ βββββββββββββ βββββββββββββ β
β β Tier 1 β β β β Node 1 β β Node 2 β β Node 3 β β
β β (8080) β β β β (8100) β β (8101) β β (8102) β β
β βββββββ¬ββββββ β β βββββββ¬ββββββ βββββββ¬ββββββ βββββββ¬ββββββ β
β β β β β β β β
β βββββββ΄ββββββ β β βΌ βΌ βΌ β
β βΌ βΌ βΌ β β ββββββββββββββββββββββββββββββββββββββββ β
β βββββ βββββ ββββββ β β Clients β β
β βSubβ βSubβ βSubββ β β HLS Player / MSE Player / VOD / ffplay β β
β βGW β βGW β βGW ββ β ββββββββββββββββββββββββββββββββββββββββ β
β βββ¬ββ βββ¬ββ βββ¬βββ β β
β β β β β βββββββββββββββββββββββββββββββββββββββββββββββββββ
β βΌ βΌ βΌ β
β ββββββββββββββββ β
β β Clients β β
β β FLV Player / ffplay β
β ββββββββββββββββ β
βββββββββββββββββββ
Architecture Overview
Origin Server: The sole stream production node, supporting RTMP and HTTP-FLV dual-protocol publishing. Handles ingest, multi-protocol repackaging. FLV recording, fMP4 segmentation, and HLS segmentation run as three fully independent parallel tasks with zero blocking.
Origin Static Capability: The origin server includes a built-in HTTP service (default port 80) for direct static file access. No additional gateway deployment needed for low-concurrency scenarios β ready to use out of the box.
-
Live Recording Mechanism:
- FLV Recording: Saves raw streams in real-time, producing a complete FLV file after the stream ends
- fMP4 Segmentation: Generates audio/video fMP4 segments in real-time (supports both merged and separate segment formats), auto-merged into a complete MP4 after the stream ends
- HLS Segmentation: Generates TS segments + m3u8 index in real-time (mobile compatible)
-
Independent Toggles: Each recording task can be independently enabled/disabled in
server.php
-
FLV Live Gateway Cluster: A pure stream relay service. Pulls HTTP-FLV streams from upstream, caches GOP keyframes for instant playback on new connections, and distributes to end clients or downstream gateways.
- Unlimited Cascade: Tier 1 β Tier 2 β Tier 3 β ... β Clients
- Horizontal Scaling: Deploy multiple gateway instances at the same tier, distribute traffic via load balancing
- Linux epoll High Performance: Single process handles 20,000+ concurrent connections, Windows falls back to select model
-
Static File Gateway Cluster (Recommended): Lightweight HTTP static file server, unified hosting for all static resources.
- Supported Protocols: HLS (.m3u8/.ts), fMP4 (.m4s/.mp4), MP4 VOD files, FLV recording files, Web player pages
- Horizontal Scaling: Deploy multiple gateway instances at the same tier, linearly increasing concurrency capacity
- Vertical Scaling: Multi-tier traffic distribution via reverse proxies such as Nginx
- Linux epoll High Performance: Single process handles 20,000+ concurrent connections, Windows falls back to select model
- Best Practice: Point HLS/fMP4/MP4 playback paths to this gateway cluster for static resource read-write separation
-
Deployment Recommendations:
- Low Concurrency (< 500 concurrent): Use the origin server's built-in HTTP service directly, no additional gateways needed
- Medium Concurrency (500 β 5,000 concurrent):
- Origin + single-tier gateway cluster (FLV Gateway or Static File Gateway)
- A single gateway process is usually sufficient, no multi-instance needed
- High Concurrency (> 5,000 concurrent):
- Origin focuses on "publishing, protocol conversion, live recording"
- FLV Gateway Multi-tier Cluster: Tier 1 β Tier 2 β Clients
- Static File Gateway Multi-tier Cluster: Tier 1 β Tier 2 β Clients
- Each tier supports horizontal scaling, linearly increasing concurrency capacity
β¨ Features
- π₯ Dual-Protocol Publishing: Full implementation of standard RTMP push/pull + HTTP-FLV push/pull, compatible with mainstream streaming tools
- π‘ HTTP-FLV / WebSocket-FLV: Low-latency browser streaming solution, supports direct playback via ffplay and other players
- π§© HLS Auto-Segmentation: Real-time m3u8 + TS generation, full platform mobile compatibility
- π¦ fMP4 Real-time Segmentation + Auto-Merge: Generates fMP4 segments in real-time during live streaming, auto-merged into complete MP4 after stream ends
- π¬ Dual fMP4 Format Support: Supports both merged audio/video segments and separate audio/video segments
- πΎ FLV Independent Recording: Saves raw FLV streams in real-time, decoupled from fMP4/MP4
- ποΈ Independent Task Toggles: FLV recording, fMP4 segmentation, and HLS segmentation can each be independently enabled/disabled
- π₯οΈ Built-in Multiple Web Players: Ready to use out of the box, supports FLV/HLS/MP4/Merged fMP4/Separate fMP4 playback
- π Cascading FLV Streaming Gateway: Unlimited tier relay, GOP-cached instant startup, auto-reconnect on stream loss, designed for high-concurrency live scenarios
- π Static File Gateway: Unified hosting for HLS/fMP4/MP4 recorded resources and playback pages, designed for high-concurrency VOD scenarios
- ποΈ Cross-Platform Playback Compatibility: Supports ffplay, VLC, browsers, mobile players, and other mainstream playback terminals
- π³ Docker One-Click Deployment: Quickly spin up a test environment
- β‘ Native Pure PHP Implementation: No third-party streaming software dependencies
π Requirements
- PHP >= 8.1 (CLI mode only)
- Required extension:
sockets - Recommended extension:
event(significantly improves concurrency on Linux by automatically enabling epoll)
π Quick Start
1. Install
composer create-project xiaosongshu/rtmp_server
2. Configure Recording Toggles (server.php)
// Three independent recording task toggles, enable/disable as needed
define('FLV_TO_RECORD', true); // Enable real-time FLV raw file recording
define('FLV_TO_MP4', true); // Enable real-time fMP4 segmentation and MP4 merging
define('FLV_TO_HLS', true); // Enable real-time HLS (TS) segmentation
3. Start Origin Server
php server.php
4. Access Playback (use origin directly for low-concurrency scenarios)
# Player page access (origin built-in HTTP service)
http://127.0.0.1/index.html # FLV live page
http://127.0.0.1/play.html # HLS live page
http://127.0.0.1/mp4.html # MP4 VOD page
http://127.0.0.1/play_merge.html # fMP4 segment VOD page (supports merged/separate formats)
5. Medium/High Concurrency: Deploy Static File Gateway Cluster (Recommended)
Use Case: High-concurrency access for HLS(.ts/.m3u8), fMP4(.m4s/.mp4), MP4 VOD files, and Web pages.
A single gateway process on Linux handles 20,000+ connections. For higher loads, scale horizontally with multiple instances.
# Start single instance (handles high concurrency directly under epoll)
php fileGateway.php 0.0.0.0 8100
# γHorizontal ScalingγMulti-instance deployment (for extreme concurrency or multi-server load balancing)
php fileGateway.php 0.0.0.0 8100
php fileGateway.php 0.0.0.0 8101
php fileGateway.php 0.0.0.0 8102
# Linux/macOS background running
php fileGateway.php 0.0.0.0 8100 > /dev/null 2>&1 &
# Vertical Scaling: Multi-tier distribution via Nginx reverse proxy
# Tier 1 Nginx -> Tier 2 fileGateway (8100/8101/8102) -> Tier 3 fileGateway ...
Access examples (via Static File Gateway):
http://127.0.0.1:8100/play.html # Access HLS player page via gateway
http://127.0.0.1:8100/hls/live/stream/index.m3u8 # Access HLS stream via gateway
6. Medium/High Concurrency: Deploy FLV Live Gateway Cluster
A single FLV gateway process on Linux stably supports nearly 20,000 concurrent viewers.
# Tier 1 Gateway: Pull from origin
php flvGateway.php 8080 http://ORIGIN_IP:8501
# Horizontal Scaling: Deploy multiple instances at the same tier
php flvGateway.php 8081 http://ORIGIN_IP:8501
php flvGateway.php 8082 http://ORIGIN_IP:8501
# Vertical Scaling: Multi-tier cascade
php flvGateway.php 8080 http://ORIGIN_IP:8501 # Tier 1
php flvGateway.php 8081 http://127.0.0.1:8080 # Tier 2 (pulls from Tier 1)
php flvGateway.php 8082 http://127.0.0.1:8081 # Tier 3 (pulls from Tier 2)
7. Stop Service
| OS | Command |
|---|---|
| Windows | Ctrl + C |
| Linux/macOS | kill -9 PID |
π§ Port Configuration (Modify in server.php)
| Port | Protocol | Purpose |
|---|---|---|
| 1935 | RTMP | RTMP publishing and playback |
| 8501 | HTTP/WebSocket | HTTP-FLV publishing/playback / WS-FLV live streaming |
| 80 | HTTP | Static file service + Web player pages |
π FLV Streaming Gateway (High-Concurrency Live Distribution)
Gateway Introduction
A lightweight stream distribution component supporting unlimited cascade deployment. Pulls HTTP-FLV from upstream origin/gateway, caches stream headers and GOP keyframes for instant startup on new connections, and replicates stream data to downstream clients or sub-gateways. Designed for medium to high-concurrency live scenarios, supports both horizontal and vertical scaling.
Gateway Core Capabilities
- π‘ Multi-stream concurrent relay in a single instance, handling different channel distributions simultaneously
- π Unlimited cascade, Tier 1 β Tier 2 β Tier 3 chained expansion
- β‘ GOP pre-caching, no keyframe wait for new connections, instant playback
- π Automatic reconnection on upstream stream loss, transparent to end users
- π Built-in runtime statistics, outputs viewer count and traffic every 10 seconds
- π Horizontal Scaling: Add gateway processes/instances at the same tier, linearly increasing concurrency
- π Vertical Scaling: Multi-tier cascade, distributing single-point pressure
- π§ Adaptive I/O: Linux auto-enables epoll, single process 20,000+ concurrent; Windows falls back to select for compatibility
FLV Gateway Startup Commands
# γHorizontal ScalingγSingle tier, multiple instances
php flvGateway.php 8080 http://ORIGIN_IP:8501
php flvGateway.php 8081 http://ORIGIN_IP:8501
php flvGateway.php 8082 http://ORIGIN_IP:8501
# γVertical ScalingγMulti-tier cascade
php flvGateway.php 8080 http://ORIGIN_IP:8501 # Tier 1
php flvGateway.php 8081 http://127.0.0.1:8080 # Tier 2
php flvGateway.php 8082 http://127.0.0.1:8081 # Tier 3
# γCombined ScalingγMulti-tier + multi-instance per tier
# Tier 1 Gateway Cluster
php flvGateway.php 8080 http://ORIGIN_IP:8501
php flvGateway.php 8081 http://ORIGIN_IP:8501
# Tier 2 Gateway Cluster (pulls from Tier 1)
php flvGateway.php 8180 http://127.0.0.1:8080
php flvGateway.php 8181 http://127.0.0.1:8081
Gateway Playback URL Format
http://GATEWAY_IP:PORT/{app}/{channel}.flv
Example:
# Tier 1 Gateway
http://127.0.0.1:8080/live/stream.flv
# Tier 2 Gateway
http://127.0.0.1:8081/live/stream.flv
Debug Logging
Add $gateway->debug = true; in the gateway startup script to enable full detailed runtime logs.
π Static File Gateway fileGateway.php (High-Concurrency VOD Resource Hosting)
Gateway Introduction
A lightweight HTTP static file server for unified hosting of all static resources. This is the recommended playback method for file-based protocols such as HLS, fMP4, and MP4. Supports horizontal and vertical scaling to handle large-scale VOD concurrency.
Core Capabilities
- π Unified hosting for all static resources (recorded files + playback pages)
- π Horizontal Scaling: Multi-instance deployment with load-balanced traffic distribution
- π Vertical Scaling: Multi-tier cascade (e.g., Nginx + fileGateway + backend storage)
- π Built-in access logs for statistical analysis
- π Pure PHP implementation, lightweight with no dependencies
- π§ Adaptive I/O: Linux epoll, single process 20,000+ concurrent; Windows select compatible
- π‘ Best Practice: Point HLS/fMP4/MP4 playback paths to this gateway cluster, letting the origin server focus solely on writing files β achieving read-write separation
Startup Commands (Multi-process/Multi-instance Distribution)
# Basic startup (host current directory, port 8100)
php fileGateway.php 0.0.0.0 8100
# γHorizontal ScalingγMulti-instance deployment
php fileGateway.php 0.0.0.0 8100
php fileGateway.php 0.0.0.0 8101
php fileGateway.php 0.0.0.0 8102
# Linux/macOS background multi-instance
php fileGateway.php 0.0.0.0 8100 > /dev/null 2>&1 &
php fileGateway.php 0.0.0.0 8101 > /dev/null 2>&1 &
php fileGateway.php 0.0.0.0 8102 > /dev/null 2>&1 &
Nginx Reverse Proxy Configuration Example
upstream filegateway_cluster {
# Horizontal Scaling: multiple fileGateway instances
server 127.0.0.1:8100;
server 127.0.0.1:8101;
server 127.0.0.1:8102;
}
server {
listen 80;
server_name media.example.com;
location ~* \.(m3u8|ts|mp4|m4s|flv|html|css|js)$ {
proxy_pass http://filegateway_cluster;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
}
}
Access URL Format
http://GATEWAY_IP:PORT/{relative_file_path}
Example:
# Web player pages (accessed via static gateway)
http://127.0.0.1:8100/index.html # FLV live page
http://127.0.0.1:8100/play.html # HLS live page
http://127.0.0.1:8100/mp4.html # MP4 VOD page
http://127.0.0.1:8100/video.html # FLV VOD page
http://127.0.0.1:8100/play_merge.html # fMP4 segment VOD page
# Recorded resource access
http://127.0.0.1:8100/hls/live/stream/index.m3u8
http://127.0.0.1:8100/mp4/live/stream/output_merge/init.mp4
http://127.0.0.1:8100/mp4/live/stream/output_merge/stream_full.mp4
http://127.0.0.1:8100/flv/live/stream/20240101_120000.flv
π‘ Publishing Guide
The project supports both RTMP and HTTP-FLV mainstream publishing protocols, compatible with OBS, FFmpeg, and various streaming tools.
1. RTMP Publishing
URL Format
rtmp://127.0.0.1:1935/{app}/{channel}
-
app: e.g.,live -
channel: e.g.,stream - Only alphanumeric characters supported
Publishing Examples
-
OBS Studio
- Download and install OBS Studio
- Settings β Stream β Server:
rtmp://127.0.0.1:1935/live - Stream Key:
stream - Start Streaming
FFmpeg Loop Publishing
ffmpeg -re -stream_loop -1 -i "video.mp4" -vcodec h264 -acodec aac -f flv rtmp://127.0.0.1:1935/live/stream
2. HTTP-FLV Publishing
URL Format
http://127.0.0.1:8501/{app}/{channel}
-
appandchannelfollow the same rules as RTMP, alphanumeric only
Publishing Examples (FFmpeg)
# Local FLV file publishing
ffmpeg -re -i test.flv -c:v libx264 -c:a aac -f flv http://127.0.0.1:8501/live/stream
# Local MP4 file loop publishing
ffmpeg -re -stream_loop -1 -i video.mp4 -c:v libx264 -c:a aac -f flv http://127.0.0.1:8501/live/stream
You can also use the built-in client pusher provided by this project (FLV/MP4 static files only):
php pusher.php test.flv http://127.0.0.1:8501/live/stream 1.0 --no-reconnect
or
php pusher.php test.mp4 http://127.0.0.1:8501/live/stream 1.0 --no-reconnect
πΊ Playback URL Summary & Tools
Live Streaming URLs
| Protocol | URL | Description | Distribution Recommendation |
|---|---|---|---|
| RTMP | rtmp://127.0.0.1:1935/live/stream |
Native RTMP players, ffplay supported | Direct from origin |
| HTTP-FLV | http://127.0.0.1:8501/live/stream.flv |
Low-latency browser playback, ffplay | Distribute via FLV Gateway Cluster |
| WebSocket-FLV | ws://127.0.0.1:8501/live/stream.flv |
WebSocket streaming playback | Distribute via FLV Gateway Cluster |
| HLS | http://{fileGateway_IP}:8100/hls/live/stream/index.m3u8 |
Preferred for Android/iOS mobile | Must distribute via fileGateway |
VOD Playback URLs (After Recording Completes)
| File Type | Access URL (must go through fileGateway) | Description |
|---|---|---|
| Merged MP4 VOD | http://{fileGateway_IP}:8100/mp4/live/stream/output_merge/stream_full.mp4 |
|
| Merged fMP4 Segment VOD (MSE) | http://{fileGateway_IP}:8100/mp4/live/stream/output_merge/init.mp4 |
|
| Separate Audio/Video fMP4 VOD | http://{fileGateway_IP}:8100/mp4/live/stream/output_separate/audio_init.mp4 |
|
| Raw FLV VOD | http://{fileGateway_IP}:8100/flv/live/stream/20240101_120000.flv |
For high-concurrency scenarios: You must use the Static File Gateway Cluster (e.g.,
127.0.0.1:8100/8101/8102), distributing traffic via load balancing to achieve static resource read-write separation.
Web Player Pages
| Page Purpose | Access URL (recommended via fileGateway) | Description |
|---|---|---|
| FLV Live Playback | http://{fileGateway_IP}:8100/index.html |
HTTP-FLV low-latency live |
| HLS Live Playback | http://{fileGateway_IP}:8100/play.html |
HLS mobile-compatible live |
| Merged MP4 VOD | http://{fileGateway_IP}:8100/mp4.html |
Complete MP4 file VOD |
| Raw FLV VOD | http://{fileGateway_IP}:8100/video.html |
FLV native file VOD |
| fMP4 Segment VOD | http://{fileGateway_IP}:8100/play_merge.html |
Supports both merged and separate segment playback |
Command-Line Playback Tools (ffplay)
The project is fully compatible with ffplay player, can directly pull various stream URLs:
# Play RTMP stream
ffplay rtmp://127.0.0.1:1935/live/stream
# Play origin HTTP-FLV stream
ffplay http://127.0.0.1:8501/live/stream.flv
# Play FLV gateway relayed stream
ffplay http://127.0.0.1:8080/live/stream.flv
# Play HLS stream
ffplay http://127.0.0.1:8100/hls/live/stream/index.m3u8
# Play VOD FLV/MP4 files
ffplay http://127.0.0.1:8100/flv/live/stream/20240101_120000.flv
ffplay http://127.0.0.1:8100/mp4/live/stream/output_merge/stream_full.mp4
πΎ Live Recording Details
Recording Mechanism (Three Independent Parallel Tasks)
When publishing begins, the origin server simultaneously starts three independent parallel recording tasks with zero blocking:
βββββββββββββββββββββββββββββββββββββββββββββββββββ
β RTMP / HTTP-FLV Dual-Protocol Ingest β
βββββββββββββββββββββββ¬ββββββββββββββββββββββββββββ
β
βββββββββββββββββββββββΌββββββββββββββββββββββββββββ
β β β
βΌ βΌ βΌ
βββββββββββββββββ βββββββββββββββββ βββββββββββββββββ
β FLV Recording β β fMP4 Segments β β HLS Segments β
β (real-time) β β (real-time) β β (real-time) β
βββββββββ¬ββββββββ βββββββββ¬ββββββββ βββββββββ¬ββββββββ
β β β
βΌ βΌ βΌ
βββββββββββββββββ βββββββββββββββββ βββββββββββββββββ
β Complete FLV β β fMP4 Segments β β TS Segments β
β (stream ends) β β (during live)β β + m3u8 index β
βββββββββββββββββ βββββββββ¬ββββββββ βββββββββββββββββ
β
β Auto-merge after stream ends
βΌ
βββββββββββββββββ
β Complete MP4 β
β (VOD playback)β
βββββββββββββββββ
Task Independence
| Recording Task | Real-time | Output | Purpose | Toggle |
|---|---|---|---|---|
| FLV Record | Yes | Complete FLV file | Raw format backup, VLC/ffplay | FLV_TO_RECORD |
| fMP4 Segs | Yes | fMP4 segments β merged MP4 | Browser MSE playback, VOD | FLV_TO_MP4 |
| HLS Segs | Yes | TS segments + m3u8 | Mobile compatibility, HLS live | FLV_TO_HLS |
π Project Directory Structure
rtmp_server/
βββ flv/ # FLV raw recording files (FLV_TO_RECORD)
βββ mp4/ # MP4/fMP4 transcoded output (FLV_TO_MP4)
βββ hls/ # HLS TS segments + m3u8 index (FLV_TO_HLS)
βββ MediaServer/ # RTMP core protocol, publish/play session logic
βββ Root/ # Low-level async I/O, Socket event-driven (includes epoll adaptive)
βββ SabreAMF/ # AMF0/AMF3 codec
βββ server.php # Origin server entry point
βββ fileGateway.php # Static file gateway (epoll supported, 20k+ concurrent)
βββ flvGateway.php # FLV live gateway (epoll supported, 20k+ concurrent)
βββ pusher.php # FLV Static File Push Client
βββ *.html # Web player pages
βββ README.md
π Concurrency Performance Benchmarks
All tests below were conducted in the same Docker container environment with ulimit -n 65535, using the same stress test script with 20,000 concurrent clients, each pulling streams for 5 seconds.
Origin Server (RTMP Origin)
Current container pids.max: unknown
Starting batch: 1000 clients (total 20 batches)
All clients started, waiting for completion...
===== Results =====
Success: 17,330
Failed: 2,670
FLV Live Gateway
Current container pids.max: unknown
Starting batch: 1000 clients (total 20 batches)
All clients started, waiting for completion...
===== Results =====
Success: 19,923
Failed: 77
Static File Gateway
Concurrency: 20,000
Duration per client: 5s
Batch size: 1000
===== Results =====
Success: 20,000
Failed: 0
Notes:
- The origin server handles RTMP/HTTP-FLV dual-protocol publishing, multi-protocol repackaging, and other business logic, yet a single process still stably achieves 17,330 successful connections. Minor failures are due to instantaneous port collisions during testing.
- FLV Gateway, focused purely on stream relay, achieves a 99.6% success rate (19,923/20,000), approaching the single-machine TCP port pool limit.
- Static File Gateway is extremely lightweight, achieving 20,000 concurrent connections with zero failures.
- All components adapt to the operating system: epoll is automatically enabled on Linux, breaking through the traditional select 1024 limit.
β FAQ
1. How can a single process support 20,000+ concurrent connections?
-
Linux: When the server detects the
eventextension is installed, it automatically enables the epoll event-driven model, no longer constrained by the traditionalselect1024 file descriptor limit. A single process easily handles 20,000+ connections. -
Windows: Since the
eventextension is unavailable, it automatically falls back toselectmodel, with limited connections per process (~256). Deploying multiple instances is recommended. - Performance Test: In a Docker container (ulimit -n 65535), the Static File Gateway achieved 20,000 concurrent with zero failures, FLV Gateway achieved 99.6% success rate.
2. How can gateways support even higher concurrency?
| Scaling Method | Description | Example |
|---|---|---|
| Single Process High Performance | Linux epoll mode, single process handles 20k+ | One fileGateway process handles 20,000 static requests |
| Horizontal Scaling | Multiple instances at the same tier, load balanced | 3 fileGateway instances β 60,000+ concurrent |
| Vertical Scaling | Multi-tier cascade | Tier 1 β Tier 2 β Tier 3... |
| Combined Scaling | Horizontal + Vertical combined | 3 instances per tier Γ 3 tiers = theoretically 180,000+ concurrent |
3. When do I need to deploy gateways?
| Concurrency Scenario | Deployment Plan |
|---|---|
| Low (< 500) | Origin server only, built-in HTTP service directly exposed |
| Medium (500 β 5,000) | Origin + single-tier gateway (1-2 instances) |
| High (> 5,000) | Origin + multi-tier gateway cluster (each tier horizontally scalable) |
4. What's the difference between FLV Gateway and Static File Gateway?
| Gateway Type | Purpose | Resource Types Handled | Scaling Method |
|---|---|---|---|
| FLV Live Gateway | Live stream distribution | HTTP-FLV real-time streams | Horizontal + Vertical, cascade supported |
| Static File Gateway | Static resource hosting | HLS/fMP4/MP4/FLV static files + Web pages | Horizontal + Vertical, can integrate with Nginx |
5. How to verify gateway concurrency capacity?
# Use built-in stress test script (20,000 concurrent)
sh play.sh
# Or use ab (Apache Bench) to test Static File Gateway
ab -n 10000 -c 500 http://127.0.0.1:8100/index.html
# Use wrk to test FLV Gateway
wrk -t4 -c1000 -d30s http://127.0.0.1:8080/live/stream.flv
Toolkit
The protocol conversion functionality of this project has been extracted into a standalone toolkit xiaosongshu/flv2mp4, available at https://github.com/2723659854/flv2mp4. It supports FLV, MP4, HLS transcoding, FLV and File gateways, as well as an FLV static file push client.
π License
This project is limited to learning and technical research use. Commercial deployment risks are borne by the user.
β οΈ Disclaimer
- Some open-source code originates from the open-source community. If copyright is involved, please contact the author for removal.
- This project is fully open-source and free, intended only for technical exchange.
- The author assumes no joint liability for any legal consequences arising from commercial or illegal use by users.
π§ Contact
- π¬ Email: 2723659854@qq.com
- π GitHub: 2723659854
Top comments (0)