Powered by Channel
Before i started working on Hub i needed to find the best networking for it. All current solutions are either bloated or not available for all platforms, so i decided to make my own.
Channel: 0 dependencies, under 1000 lines of code, made for modern language
Channel was made in mind that it should be as simple as possible. And how to make it as simple as possible? Ditch the networking!
So at the core Channel is just a routing engine, working as String to Function dictionary with subscriptions and streams support in just 700 lines of code. This allows to use it even without a network, for example inside your server to communicate between different parts of code.
Around 200 lines of code was needed to implement WebSocket client, 150 lines of code for WebSocket server and just 50 for process communication in TypeScript.
So what does this mean?
- It makes Channel easy to implement in different languages
- It makes Channel fast on scripting languages
- It makes Channel binary extremely small
We have a ton of different encoders, which on to use? JSON. It's the only one that is supported by every language. That's why Channel has 0 dependencies in both TypeScript and Swift libraries.
What optimizations was made to make it faster:
Sending 100000 of 100b requests would be much slower than sending a single 1mb request. That's why channel allows to receive batch of requests. When client sends a ton of requests, it will switch to throttle mode, accumulating requests and sending them each 100ms. This allows client to send up to 1 million requests per second and server receiving up to 5 million requests per second (all on a single CPU core)
Sending 100000 of 100b requests would be much slower than sending a single 1mb request. That's why channel allows to receive batch of requests. When client sends a ton of requests, it will switch to throttle mode, accumulating requests and sending them each 100ms. This allows client to send up to 1 million requests per second and server receiving up to 5 million requests per second (all on a single CPU core)
So all of that comparing to Socket.IO:
- Socket.IO doesn't have async/iterator api as it was made when that wasn't even available
- It has A TON of dependencies, making hello world server to use over 44000 lines of code for absolutely no reason
- With that amount of dependencies it's vulnerable to supply chain attacks and bugs
So that's the Channel. It's powering Hub and doing it's job very good!
channel
hub
networking
open-source