从SQL DB代替聊天应用程序的文件轮询会提高性能吗? [英] Will polling from a SQL DB instead of a file for chat application increase performance?

查看:79
本文介绍了从SQL DB代替聊天应用程序的文件轮询会提高性能吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个聊天应用程序,很想使用SQL db。

I'm working on a chat application which I would love to use a SQL db for.

我的问题是,经过几次Google搜索,我发现有人从一个站点告诉我,使用DB会比使用普通文件(例如Text或JSON文件)要慢得多,但是在其他一些站点上,人们却说完全相反。我不了解你们,但是在为用户创建网络应用程序时,用户永远是第一位的。

My problem is, after a few google searches, i have people telling me from one site, that using a DB would be much slower then using a normal file (e.g Text or JSON file), but then on some other sites, people are saying the complete opposite. And I don't know about you guys, but when it comes to creating web apps for users, the users always come first.

我想尽可能多地使用SQL DB:1.)我对它有很好的经验,并且2.)它使我可以使应用程序变得很多更酷(更多功能)。但是如果这样做会减慢用户端的运行速度(明显的滞后),那么它就不行了。

So as much as I'd love to use a SQL DB as 1.) I have good experience with it and 2.) it allows me to make the application much more cooler (more features). but if it would slow things down on the users end (a noticeable lag), then its a no-no.

无论哪种方式,我将使用AJAX和PHP连续轮询服务器以检查文件/数据库(以获取新消息,联系请求等)。

Either way, I will be "polling" the server continuously with AJAX and PHP to check the file/DB (for new messages, contact requests, ect ect).

此外,以防万一,您想知道,该应用程序将不会像一对一聊天,它将具有房间,多个用户可以在其中加入并与所有加入的用户进行交谈。这些用户还可以请求与另一个用户进行私人聊天,

Also, incase your wondering, the application wont be like a 1-to-1 chat, it will have "rooms" where multiple users can join and talk with all users joining in. The users will also be able to request a "private chat" with another user, where a 1-to-1 connection opens up.

那么,关于性能,MySQL数据库还是无聊的TEXT / JSON / OTHER文件?

So, MySQL Database OR a boring TEXT/JSON/OTHER file, in regards to performance?

哦,还有一件事,我不想使用任何第三方库或API。讨厌依靠别人的工作(被压倒很多次)。

Oh, one more thing, I don't want to use any third party libraries or APIs. Hate relying on other peoples work (been let down to many times).

推荐答案

如果您要实现IRC克隆,我认为您选择了所有错误的工具。

If you're looking to implement an IRC clone, I think you've chosen all the wrong tools.

执行此操作的最佳方法是编写一个处理内存中所有内容的自定义HTTP服务器。没有数据库,没有文件的持续轮询。当消息到达时,您只需在正确的内存列表中循环,然后将消息分发给其他用户。对于浏览器到服务器的连接,我建议 Comet (使用Web套接字支持它们的浏览器,如果您愿意的话。)

The best way to do this would be to write a custom HTTP server that handles everything in memory. No databases, no constant polling of files. When a message arrives, you simply loop through the correct in-memory list and dispatch the message to other users. For the browser to server connection, I suggest "Comet" (with web sockets for browsers that support them, if you're feeling up to it).

PHP可能不是这种选择的语言,因为几乎所有工作都是由PHP完成的基于传统的简短隔离请求。对于长时间运行的实时服务多个客户端的过程,我建议使用Python或Node.js之类的东西。

PHP likely isn't the language of choice for this, because pretty much all work done with PHP is based on traditional short, isolated requests. For a long-running process which serves multiple clients in real time, I'd suggest something like Python or Node.js.

这篇关于从SQL DB代替聊天应用程序的文件轮询会提高性能吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆