-
-
Notifications
You must be signed in to change notification settings - Fork 604
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Option to use Nats server as PUB/SUB broker #273
Conversation
what are the pros and cons using NATS? |
@Raerten I forgot to mention that using Nats as broker will be optional of course. Redis Engine will work the same way as now without changes. The reason why I think it's useful is because Nats is simple to configure in cluster mode and it's very performant. For applications that only need fast PUB/SUB this can be a nice option. |
I'm just using pub and sub ... wondering the performance redis vs nats |
@maurodelazeri hi, Nats is insanely fast in terms of publish speed:
And a bit slower in terms of subscription performance:
I was comparing single instance of Redis vs single instance of Nats. This is a bit unfair as Nats utilizes many CPU cores on machine while Redis runs on on single CPU core. With sharded Redis on each of my 4 cores I could get better results with Redis of course. Though I suppose performance is not what we should look at here actually. There are some other benefits like easy clustering and cluster-aware client. Another concern is that adding more options for scalability can help with better adoption of Centrifugo in general. Looks like Centrifugo users mostly use unreliable PUB/SUB features only. Nats is pretty popular in Go community, maybe I am a bit biased because of this fact. So I want to collect feedback on this before moving further. |
@FZambia that sounds amazing, I def will spend some time testing this... |
@maurodelazeri hm interesting - never heard of that Redis fork before! Are you using it as Centrifugo engine or just as part of your other applications? |
@FZambia I'm using as engine... there are an extensive discussion here https://news.ycombinator.com/item?id=19368955 I have implemented some low latency systems with nng, that's definitely going to be much faster than nats, not sure if you know this project... it is an evolution of http://zeromq.org/ an integration would be awesome https://nanomsg.github.io/nng/ |
Thanks for the link! Yeah, actually in its early days Centrifugo (when it was written in Python) used ZeroMQ for PUB/SUB layer, but then it's evolutionarily came to Redis (don't remember exact reasons - but it definitely allowed to improve system observability and understanding and opened a road to recovery and presence features). Now with recent changes in Centrifuge library it's pretty simple to experiment with any PUB/SUB technology. I've heard about Mangos - but one thing bothers me is the fact that in Mangos PUB/SUB messages are being filtered on receiver side - that means that if we have several nodes then published messages will be sent to each of them even if there are no subscribers. Maybe this is not a big problem for many use cases though. If I have time I can try to prototype this - though not in near future I suppose. |
@FZambia you are right, the project still does not support server side filtering nanomsg/nng#587 but like he said, that's not a "problem" besides the fact of the bandwidth... |
I use NATS and would be interested in see the proof of concept. |
Btw is it NATS or NATS streaming. If it's NATS streaming then there is a grpc integration. So every service maps to a NATS topic. Why is this cool ? |
I just checked the code. Wondering if this impacts the client code written in other languages ? For example I use dart in order to talk to centrifugal from Flutter in one of my prototypes. Also where is the durability. It's using only NATS and not NATS streaming. Am confused where messages are stored when you have a cluster. |
@gedw99 this is Nats, not Nats Streaming. Centrifugo semantics does not fit well to Nats Streaming, of course my first attempt was to add Nats streaming backend but it seems that Nats streaming and Centrifugo were invented for slightly different purposes so I did not find a good way to combine them without many changes in how Centrifugo works. This pr introduces Nats for scalable but unreliable messaging - this can be OK for apps which do not need message any delivery guarantees - i.e. sth like real-time stock info, real-time charts, games. Though if we combine this with Redis Engine possibilities we get the same message delivery guarantees as we have with plain Redis Engine (history is kept in Redis while PUB/SUB works over Nats). This is possible due to recent changes in Centrifuge library (btw you also took part in that issue and pointed me to Event Sourcing there - centrifugal/centrifuge#12 - it's now even more like event sourcing). I quickly sketched a small note on Medium for Centrifuge library users about pluggable components. At moment Nats team works on Nats v2 - I'd like to see what they end up with before moving with Nats in Centrifugo. But you can already just checkout this branch ant test it out if you want - maybe you will have feedback on this. |
All Centrifugo and Centrifuge library will work with this as they currently work with Memory or Redis engines - i.e. the same way without any changes. It's a bit costly to change client API for us as one change must be reflected in many client libraries - Javascript, Java, Swift, Dart, Go. But in this case no changes needed - we just replace one of server components of Centrifugo. |
Got it. Thanks Alex. Very interesting. Yeah I saw the JetStream proposal for NATS V2. https://github.com/liftbridge-io/liftbridge My only risk is redis. Single CPU. It's 2019 and a 48 core server is normal and a 24 core ARM server is normal ( packet & scaleway data centers for example ). It's a huge SPOP ( single point of performance ) bottleneck. There is a redis clone written in golang that is multicore.
Maybe you saw it ? https://github.com/tidwall/redcon That Dev is reliable and running production stuff on top of redcon. It's API compatible. |
I don't agree with this concern as I know how fast can be Redis - we just serve 450k connections with single Redis core. As Centrifugo has client side sharding - there is no bottleneck, it's very simple to utilize all cores running multiple Redis instances - at work we have 10 shards and lot of room to grow. Yeah, I've heard about Redcon - though I suppose it's not feature rich and as far as I remember it uses epoll in single thread. I had report recently from Centrifugo user about succesfull use of KeyDB (see recent discussion on HN here) - it's multithreaded and full featured. |
Thanks for the feedback. I support gnats / NATS with redis backing. Also i like the idea of being able to use all the NATS functionality on top. Security rules for example are extensive for NATS. I have not had time yet to look at this code ! Hoping to have a play next week. |
Still considering adding this feature, if someone wants it to be merged - please write your thoughts on how this can be useful for you. I am a bit skeptical here because adding Nats as custom broker can be a new dependency we need to support/update and I don't really want to just add it without real use case scenario. |
Hey @FZambia We spoke on Telegram. My use case it to run on rasp pi servers on premise, and scaleway in the cloud. Both are ARM. Does NATS broker mean that i dont need Redis though as i doubt i can get it running on ARM ? |
@joeblew99 https://redis.io/topics/ARM - looks like Redis works just fine on ARM btw |
@FZambia ARM !! Wow you made my day. thanks for checking this out ! So we can use Centrifugo today without NATS on Rasp PI then. It will make the project much easier. I will still try using NATS to see how it feels. Will Redis still be needed if we use NATS ? I am not sure. |
Yeah, waiting for feedback
For presence and history/recover features - yes. For unreliable PUB/SUB only - no. |
Hi @FZambia is there any updates on this? As you mentioned, nats option will be nice when history-recovery is not necessary. By the way, thanks for this amazing project 🙏 |
@BatuhanK I slowed down this a bit due to pure understanding on how this will help Centrifugo users. Nats in quite popular in Go community but I am not sure it's widespread enough outside Go to be generally useful. Do you personally already have Nats in your infrastructure? What kind of setup are you using then - I need this information to understand how real Nats production system now configured, which options Centrifugo should support from start to fit user needs? I am not rushing with this as adding one more dependency to external system will cause more maintenance overhead for me so decision must be weighted. |
@FZambia Please consider interop with NATS Streaming (STAN) if possible. It will allow switch out redis completely for history/recovering. But as i understood - centrifuge api doesnt allow that? |
@ReDev1L hi, I'd really like to interop, and I danced around this several times, but it's a bit different model from what Centrifugo does. Centrifugo multiplexes multiple subscriptions to same channel to one to broker, with STAN/Liftbridge/Kafka/Pulsar every streaming (i.e. with message recovery) subscription must be separate object for each client subscription. It will work but it does not fit current internal Centrifugo interfaces and logic. I will continue to think whether it's possible to fit that model, maybe with more radical changes inside Centrifugo. BTW current Redis approach seems to fit better for most Centrifugo use cases (scales much better, especially for cases when many subscribers use the same channel with recovery on). But extending current model to fit streaming brokers is really interesting to me anyway. |
If I understood correctly from commitI can use nats with Centrifugo now?
|
@subhendukundu I think you are expecting a bit different from this integration. Nats integration in Centrifugo case only uses Nats as broker, there is nothing related to Nats recently added WebSocket protocol. It's just an option to scale Centrifugo to many nodes with at most once message delivery guarantees.
In publishing performance most probably, in other aspects - no. As I said this is just an extra option to scale Centrifugo PUB/SUB without Redis.
No, my main focus is on Redis.
Don't understand question – if someone wants to use NATS WebSockets then it's possible without Centrifugo involved.
Centrifugo with Nats integration not released yet, but docs for upcoming version already exist: https://centrifugal.github.io/centrifugo/server/engines/#nats-broker |
This makes so much clear (Sorry for the confusion). |
In Centrifugo integration with Nats recovery won't work. Recovery only available with Memory and Redis engines. |
Is there a way we can achieve it? |
No, not at moment. Maybe in future with https://github.com/nats-io/jetstream – this needs research though. Could you provide more info about your use case and requirements? Do you want to replace Redis? Why? |
The use case I am trying to do is a realtime chat app without a database (like Snapchat but no data storage). Two options are best so far according to me.
Now with centrifugo, I haven't tried this scenario. What do you feel a better option for this case? |
This is a proof of concept of using Nats server instead of Redis for PUB/SUB part of Centrifugo. I am still considering is it worth adding this or not, any feedback is welcome.