Rails 2017 年想实现 Web 内的聊天,用什么技术方案比较好?

steveltn · January 22, 2017 · Last by huacnlee replied at February 08, 2017 · 3087 hits

如题,现在有个 Rails app,想做类似 Gmail 或 Facebook 里的聊天功能。目前同时在线大约 50 人左右,不过希望将来能方便的 scale。

目前看了几个方案:

1) ActionCable 这个方案实现起来应该是最简单的。但是考虑 scalability,不知道将来能否方便的 scale。另外,ActionCable 的信息可能会出现顺序错乱的问题。

2) RabbitMQ 性能应该没问题,维护起来可能要比方案 (1) 麻烦一点。

3) 现成的服务 看到一个 Twilio。比较担心的问题就是在墙外,是不是能在墙内可靠使用?没有找到国内的类似服务。

4) Faye 这个是可以自己 host server 的,不知道是不是比 RabbitMQ 好用?

有有经验的同学分享一点心得吗?谢谢。

量不多,用什么搞都可以的。

之前我用 Action Cable 加一个 Comment 结构的表搞过一个简单的聊天。

我们用 Actioncable 实现了类似于 Whatsapp 类的聊天功能,不是非常的难。人不多的话没什么问题。scale 的话也没什么问题,但如果人多的话我不会选择用 Actioncable,太吃资源

如果没有群聊,ejabberd 是我的首选,微信类似的群聊用 ejabberd 实现起来反而麻烦。

谢谢各位。暂时决定先用 ActionCable 来实现一个原型了。如果遇到性能问题再往 Ejabberd 迁移。

业务没被验证前,ActionCable 就可以了。做大了用 XMPP 定制。

AnyCable looks lovely and it'll be interesting to follow the new Rack specification. But Action Cable should work out-of-the-box with no additional servers or setups required beyond Puma. If there are options available that fulfill that criteria and are drop-in replacements, awesome, let's look at that. Also happy to accommodate whatever AnyCable might need, but haven't seen any requests.

So let's wait to see some real approaches that need the existing server extracted before we venture down that path.

Whatever benchmarks that were done against 5.0.0 should take another go against 5.0.1. Tons of Action Cable fixes for both performance and stability. But regardless of what that changes, the overall story will remain the same. Ruby is never going to win any Hello World shoot-out against C++ or microframeworks. That's as true for a regular 200 OK request as it is for a websockets connection. That doesn't mean we shouldn't seek to improve performance, and options like AnyCable might do so dramatically, just that we should have realistic expectations of where things go.

For Basecamp 3, which Action Cable was developed for and extracted from, our main issue has been less raw websocket performance and more just doing the work that is needed across that wire. Kinda like how doing 2,000 req/sec on a "Hello World" 200 OK is a bit irrelevant compared to building a real app. It's extremely unlikely that the overhead of your underlying server is going to be the bottleneck. It's more likely to be your application logic.

All depends on your use case, of course. And happy to see others push the performance of Action Cable further. As-is, it's plenty good enough to run a major app like Basecamp 3.

by @dhh

https://groups.google.com/d/msg/rubyonrails-core/PSbhfZ2LCWo/XQAnkP2CEQAJ

You need to Sign in before reply, if you don't have an account, please Sign up first.