Django Node.js 套接字.io
我正在尝试制作一个实时消息应用程序。将有 2 个不同的服务器(node.js 和 django),当一个用户向另一个用户发送消息时,消息将存储在数据库中,node.js 会向接收者发送一条消息,例如“您有新消息!”。为此,我计划调用 node.js 提供的 url。所以node.js和django会互相交互。向指定客户端发送消息的最佳方式是什么? (我将客户及其 ID 保存在关联数组中。)
您对此有何看法?它有效还是您建议更好的方法来做到这一点?
I am trying to make a realtime messaging application. There will be 2 distinct server(node.js and django) and when a user sends message to another user message will be stored in database than node.js will send a message to receiver like "You have new Message!". For that i am planing to call url which node.js serve. So node.js and django will interact each other. And what is best way send message to specifig client ? (I keep clients with their id's in a assosicative array.)
what do you think about that? is it efficent or do you suggest better way to do this ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
现在我更了解你想要做什么,这是我的答案,请记住,这仅反映我的观点,我敢打赌许多其他人会对此争论。
这一切都取决于您期望应用程序中有多少流量。如果它不是一个高流量的应用程序,那么与开发的效率相比,运行时的效率是微不足道的,因此选择您感觉最舒服的技术。
如果您的目标确实是高流量应用程序,那么我认为这种设置不是一个好的设置。
首先,虽然服务器之间基于 http 的通信可能看起来很舒服,但您正在处理 http 通过 tcp 的开销(因为 http 是基于 tcp 的)。因此,常规 tcp 套接字可以更好地扩展,但另一方面,如果您用 python 编写套接字服务器,那么您可以从与 django 相同的进程运行它,然后将其用作 django 中的对象(您正在进入该领域此处的线程)。但是,如果您有一些网络实例,那就有问题了,这又取决于您期望的流量。
至于您选择实现消息传递服务器,我从未测试过node.js,但我相信在基准测试中它无法与用erlang或Java NIO编写的东西进行比较。例如:JAVA AIO (NIO.2) VS NODEJS
Now that I understand more about what you're trying to do, here my answer, just keep in mind that this only reflects my opinion, and I bet that many others would argue about it.
It all matter on how much traffic you expect to have in your application. If it's not a high traffic application, then efficiency in run-time is insignificant when compared to that of the development, and so choose the technology you feel most comfortable with.
If though you do aim for high traffic application, then I believe that this setup is not a good one.
First of all while http based communication between servers might seem comfortable, you are dealing with the overhead of http over tcp (since http is based on tcp). And so regular tcp sockets scale better, but on the other hand if you write the sockets server in python than you can run it from the same process as the django and then just use it as an object from django (you're entering the realm of threads here). But that's problematic if you have a few web instances, again depends on how much traffic you expect.
As for your choice for implementing the messaging server, I've never tested node.js but I believe that in benchmark tests it won't compare for something written in erlang or Java NIO. For example: JAVA AIO (NIO.2) VS NODEJS