Logo_mezon_light.pngmezon

Engineering the future: how mezon-sock-c is built for 1M + CCU

Engineering the future: how mezon-sock-c is built for 1M + CCU

๐Ÿš€๐„๐๐†๐ˆ๐๐„๐„๐‘๐ˆ๐๐† ๐“๐‡๐„ ๐…๐”๐“๐”๐‘๐„: ๐‡๐Ž๐– ๐Œ๐„๐™๐Ž๐-๐’๐Ž๐‚๐Š-๐‚ ๐ˆ๐’ ๐๐”๐ˆ๐‹๐“ ๐…๐Ž๐‘ ๐Ÿ๐Œ+ ๐‚๐‚๐”๐Ÿš€


When we set out to build the next generation of our socket gateway, we didn't just want it to work - we wanted it to be unbreakable . To hit 1 Million Concurrent Users (CCU) on a single cluster, standard high-level languages weren't enough. We went "to the metal" with C and a modern asynchronous architecture.


1๏ธโƒฃ ๐ข๐จ_๐ฎ๐ซ๐ข๐ง๐ : ๐“๐ก๐ž ๐Š๐ž๐ซ๐ง๐ž๐ฅ ๐‘๐ž๐ฏ๐จ๐ฅ๐ฎ๐ญ๐ข๐จ๐ง ๐Ÿง

We ditched the overhead of traditional epoll. By using io_uring , we minimize expensive syscalls and context switches. Our worker threads "talk" to the Linux kernel via shared memory rings, allowing us to process thousands of I/O events per microsecond with near-zero CPU waste.


2๏ธโƒฃ ๐’๐ก๐š๐ซ๐๐ž๐ ๐“๐ก๐ซ๐ž๐š๐-๐’๐š๐Ÿ๐ž ๐“๐ซ๐š๐œ๐ค๐ž๐ซ ๐Ÿงฉ

Managing 1M user states is a locking nightmare. We solved this by sharding our Session Registry and Presence Tracker across 1024+ internal buckets. This allows our 8-core (or 64-core!) workers to update user status and room memberships simultaneously without fighting over a single global lock.


3๏ธโƒฃ ๐™๐ž๐ซ๐จ-๐‚๐จ๐ฉ๐ฒ ๐๐ซ๐จ๐ญ๐จ๐›๐ฎ๐Ÿ & ๐‚๐ฎ๐ฌ๐ญ๐จ๐ฆ ๐๐ฎ๐Ÿ๐Ÿ๐ž๐ซ๐ข๐ง๐  โšก

Data doesn't move unless it has to. By using Protobuf-C and mimalloc (Microsoft's high-performance allocator), weโ€™ve eliminated heap fragmentation. We use a reference-counted broadcast system, meaning a single 1KB message is packed once and referenced across thousands of client write-queues.


4๏ธโƒฃ ๐๐จ๐ซ๐ข๐ง๐ ๐’๐’๐‹ & ๐’๐ž๐œ๐ฎ๐ซ๐ž ๐‡๐š๐ง๐๐ฌ๐ก๐š๐ค๐ž๐ฌ ๐Ÿ”

Security shouldn't be a bottleneck. By integrating Googleโ€™s BoringSSL , we perform high-speed TLS handshakes and JWT HS256 verification in the same event loop. Weโ€™ve even optimized the JWT decoding to use constant-time comparisons to prevent timing attacks while maintaining massive throughput.


5๏ธโƒฃ ๐“๐ก๐ž "๐‡๐จ๐ฆ๐ž ๐’๐ก๐š๐ซ๐" ๐Ž๐ฉ๐ญ๐ข๐ฆ๐ข๐ณ๐š๐ญ๐ข๐จ๐ง ๐Ÿ 

One of our biggest wins: The Home Shard Principle . We map a sessionโ€™s entire membership list to a specific shard based on their ID. This turned the "Disconnect All" operation from a slow $O(N)$ brute-force search into a lightning-fast $O(1)$ lookup.


๐“๐ก๐ž ๐‘๐ž๐ฌ๐ฎ๐ฅ๐ญ?

Low latency, predictable tail-latencies (p99), and a memory footprint so small it makes VM-based languages look like dinosaurs. ๐Ÿฆ–

We're pushing the boundaries of what a real-time gateway can do. Stay tuned for the benchmark reports!


#LinuxKernel#io_uring#DistributedSystems#BackendEngineering#HighPerformanceComputing#WebSockets#Networking#MezonSock#CProgramming

------------------------------------------------

MEZON - YOUR CLAN, YOUR WORLD!

A product proudly developed by the engineers at NCCPLUS.

๐ŸŒ Website: https://mezon.ai/

๐Ÿ“ง Email: hello@mezon.vn

๐Ÿ“ž Hotline: 024.6687.4606

๐Ÿ“ฒ Available on App Store & Google Play