Ajax high frequency and MySQL sleep overload

I am currently working on a lightweight php framework to use with some high ajax request for my site and ran into an interesting problem that completely surpassed me. Ajax is designed for a series of notifications, so javascript sends an ajax request for new information every 30 seconds. This ajax is active on every page of the entire site, so I implement a lot of requests, as several hundred users browse the site at any time, many of them open several windows.

The syntax is wise, everything is perfect. The problem is that when I activated ajax for my community, a command of 30-40 SLEEP is created in the MySQL database. All of them seem to ignore the set timeout of 10 seconds. As a result, this affects the entire performance of the site.

I understand that the remaining sleep commands are the result of a connection that was not closed. I use the object-oriented MySQLi class and have expanded it with several of my functions. Everything is in the tutorial and double checked for documentation, and I made sure that every small part of the MySQLi class is closed and released.

If anyone has any wisdom or experience with such an effect, I would be very grateful for any advice.

+4
source share
1 answer

Have you tried using the push approach against your current pull / poll approach? Take a look at the comet:

However, there are some drawbacks, the main one being maintaining an open connection, and some browsers limit the number of connections you can support. The following article talks about the pros and cons of using a comet and suggests a hybrid survey approach:

Here is a stackoverflow question that also talks about comets:


+1
source

Source: https://habr.com/ru/post/1301479/


All Articles