4 ms·
Nchan is about 12K lines of C, I'd say 2-5K of that is dealing with Nginx guts. To get rid of Nginx entirely, you'd need to add an event loop, forking and multi
by slact 11y ago
Nchan is about 12K lines of C, I'd say 2-5K of that is dealing with Nginx guts. To get rid of Nginx entirely, you'd need to add an event loop, forking and multiprocess management, config parsing and reloading, and shared memory allocation code. That's not a simple task, but it's certainly possible. The reason I built this on top of Nginx is precisely because I didn't want to handle those other things. Besides, nginx these days is a hulking scalable monster. What's the bother?
If you really don't want an nginx dependency, I'd say you're better off rolling your own pubsub server in Node.
- geekuillaume 11y agoOkay, thanks for the information. The problem with doing the pubsub in NodeJS entirely is the way NodeJS handle connections. Each is separated and is accompanied by a big overhead from NodeJS. What would be great is a way to interact with the pubsub server not by config but with an API. This would allows, for example, the execution of middlewares when a user publishes a message (to filter them or something else). Right now, I'm using two websockets, one to Nginx PushStream only to receive messages and another to the NodeJS server to publish messages. The NodeJS server is used to parse the messages, format them, authenticate the user and apply the middlewares before publishing the message to Redis. Then, each NodeJS get the message from Redis and POST it to Nginx. The problem here is that there is two sockets for each user and the complexity involved with the communication between Nginx and NodeJS. That's why a really performant standalone websocket engine with an extensive API would be awesome.
- slact 11y ago> the execution of middlewares when a user publishes a message (to filter them or something else) You can do that with nchan: https://nchan.slact.net/details#authenticate-with-nchan_authorize_request https://nchan.slact.net/details#authenticate-with-nchan_auth... > Right now, I'm using two websockets, one to Nginx PushStream only to receive messages and another to the NodeJS server to publish messages. You can also multiplex several websockets into one for the client. I can't offer you a standalone server, but I can offer some pretty fancy features : )
- geekuillaume 11y agoI saw this feature, but I think there is limitation preventing me to use it, tell me if I'm wrong ;) - I cannot use this to make a call each time a message is published on a pubsub websocket - I cannot modify the message sent by the user (to add user information for example) Also, what do you mean by multiplexing websockets ?
- slact 11y agoThat's correct, that feature is for authentication only. I may add a feature to replace the message with the back end response. By multiplexing I mean that a single websocket (or any other) subscriber can subscribe to multiple channels.