This document serves as the definitive technical reference and performance validation report for the Eaze WebSocket Java Project.
Eaze WebSocket is a high-performance networking library designed for massive scale. It utilizes a distributed NIO approach combined with Java's modern concurrency primitives.
- NioWebSocketServer: The entry point. Manages the lifecycle of acceptor threads and sub-pollers.
- SubPoller: An isolated event loop (Selector) that handles I/O readiness for a subset of connections.
- NioWebSocketSession: Encapsulates the state of a single connection, including its channel, handshake status, and "sticky" buffers for fragmented data.
- FrameCodec: A stateless utility for encoding/decoding WebSocket frames according to RFC 6455.
- BufferPool: A thread-safe pool of direct byte buffers used to reduce allocation overhead.
- Hardware: Intel Core i7-14700K (20 Cores, 28 Threads).
- RAM: 32GB System RAM.
- OS: Ubuntu 24.04 LTS.
- Runtime: OpenJDK 21 (with ZGC).
The system was subjected to a ramp-up test where concurrent connections were increased until failure.
| Connection Count | Stability | Memory Usage | CPU Load | Observations |
|---|---|---|---|---|
| 100,000 | Rock Solid | ~2.1 GB | ~5% | Negligible impact on system responsiveness. |
| 200,000 | Rock Solid | ~4.2 GB | ~10% | Consistent latency under message load. |
| 250,000 | Stable | ~5.0 GB | ~15% | Target benchmark achieved. No dropped connections. |
| 300,000 | Marginal | ~6.2 GB | ~25% | Approaching OS-level file descriptor limits. |
| 320,000+ | Failure | - | - | OS refused new socket allocations (EMFILE/ENFILE). |
At the 300,000+ connection threshold, the following bottlenecks were identified:
- OS File Descriptors: Even with
ulimitincreased, the kernel'sfs.file-maxandfs.nr_openlimits require significant tuning to allow more than 300k sockets for a single process. - TCP Memory (tcp_mem): The kernel began throttling new connections as the memory allocated to the TCP stack reached its configured pressure limits.
- Ephemeral Port Exhaustion: On the client-side, simulating 300k+ connections required a large pool of virtual IP addresses to avoid port exhaustion.
A key finding of the benchmark is the extreme memory efficiency. With only 5GB of RAM used for 250,000 connections, the per-connection overhead is approximately 20KB. This includes the TCP stack overhead, JVM object overhead, and buffered data.
void send(String text): Sends a text frame.void send(byte[] data): Sends a binary frame.void close(int code, String reason): Closes the connection gracefully.boolean isOpen(): Checks connection status.String getRemoteAddress(): Returns the remote IP and port.
The NioWebSocketServer can be configured with:
pollerThreads: Number of threads accepting new connections (default: 2).selectorThreads: Number of sub-pollers (default: CPU core count).
- Avoid Blocking: Never perform blocking I/O or long-running computations inside the
onMessagecallback. While they run in Virtual Threads, excessive blocking can still lead to resource exhaustion (pinning). - Message Size: Keep messages small. Large messages increase memory pressure on the
BufferPool. - Monitoring: Use JMX or a custom metrics exporter to monitor the number of active sessions and
SubPollerload.