高频 Ajax 和 MySQL 睡眠过载

发布于 2024-08-21 23:18:24 字数 463 浏览 7 评论 0原文

我目前正在开发一个轻型 php 框架,以便与我的网站的一些高请求 ajax 一起使用,并且遇到了一个有趣的问题,让我完全陷入困境。 ajax 用于一系列通知,因此 javascript 每 30 秒发送一次 ajax 请求以获取新信息。这个 ajax 在整个网站的每个页面上都是活跃的,所以我意识到它有很多请求,因为数百个用户在任何给定时刻都在浏览该网站,其中许多用户打开了几个窗口。

语法方面一切都很完美。问题是,当我为社区激活 ajax 时,MySQL 数据库中积累了 30 - 40 个 SLEEP 命令。所有这些似乎都忽略了设置的 10 秒超时。结果,它影响了整个站点的性能。

我的理解是,剩余的睡眠命令是尚未关闭的连接的结果。我使用 MySQLi 面向对象的类,并用我自己的一些函数对其进行了扩展。一切都按照教科书进行,并根据文档进行了双重检查,并且我确保 MySQLi 类的每个小部分都已关闭并发布。

如果有人对这种效果有任何智慧或经验,我将不胜感激。

I am currently working on a light php framework to use with some high request ajax for my site, and have run into an interesting problem that has me completely stumped. The ajax is for a series of notifications, so the javascript sends off an ajax request for new information every 30 seconds. This ajax is active on every page of the entire site, so I realize its a lot of requests as several hundred users are browsing the site at any given moment, many with several windows open.

Syntax wise everything is perfect. The problem is, when I activated the ajax for my community, there is a build up of 30 - 40 SLEEP commands in the MySQL database. All of which seem to ignore the set timeout of 10 seconds. It effects the entire site's performance as a result.

My understanding is that left over sleep commands are the result of a connection that hasn't been closed. I am use the MySQLi object oriented class and have extended it with a few functions of my own. Everything is by the text book and double checked against the documentation, and I've made sure that every little piece of the MySQLi class is closed and released.

If anyone has any wisdom or experience with this type of effect, I would be most grateful for any advice.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

柠栀 2024-08-28 23:18:24

您是否尝试过推送方法与当前的拉/轮询方法?看看 Comet:

然而,它也有一些缺点,主要是你必须保持一个开放的连接,并且一些浏览器限制你可以保持的连接数量。以下文章讨论了使用 Comet 的优缺点,并建议采用混合轮询方法:

这是一个 stackoverflow 问题,也讨论了 comet:


Have you tried a push approach versus your current pull/polling approach? Take a look at Comet:

However, there are some downsides, the main one being you have to maintain an open connection, and some browsers limit the number of connections you can maintain. The following article talks about the pros and cons of using Comet and suggests a hybrid-polling approach:

Here is a stackoverflow question that talks about comet also:


~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文