2
First of all I need to inform the current situation.
I own a website, there is an ajax Polling, which requests every 5 seconds to get notifications and the like.
The entire site is supported by two servers, one for NGINX and one for Mysql. However, it is mainly due to the "loop de requisições
" the server easily reaches 500 to 1500 requests per second. Number that for me is extremely high. The maximum number of connections with Mysql opened simultaneously is 50, which for me was somewhat impressive, although the limit is much higher than that. Remember that static content (CSS, JS, IMG) is cached by external CDN, so this number of requests DO NOT include such files, I have already monitored this as well! The average response time is 200ms up to 800ms, the average being 700ms, according to New Relic.
The problem is most often the problem is that the user opens several tabs, including me. I confirmed this when including in the logs the time of each user.
This way, a same user can make instead of 1 request every 5 seconds, make 5 or 20 requests every 5 seconds, simply because each tab will "duplicate" the amount of requests.
This not only increases the requests but also causes the tabs to be out of sync, as each tab has "your time" to update, one may have updated while the other may not.
I wanted to know if there is any way to share the information received from AN AJAX between open tabs, so that only one request would be able to meet all open windows. In the same way that only one window would be responsible for updating all content, resulting in only one request every 5 seconds, instead of each tab making requests every 5 seconds.
Thought-out solution...
A request saves in a "persistent" way the changes, including the time that the last query was performed (or defined by some expiration date). When another tab is executed it will check first if the last query was performed another 5 seconds ago. If not, it would take the data that has already been defined by the ajax of another tab, which have been saved, which are updated.
I thought of using the Cookie
for this, but I do not know if the cookie
is able to be accessed in another tab when defined by another, without the need to refresh the page, I believe not. In addition the Cookie will add one more data to send to each request, some unnecessary bytes.
At this very moment I’m seeing the store js., maybe above the need, because I believe it is accessible by another tab without updating the page.
Is there any more efficient way to do this "ajax sharing" between tabs?
That would be a temporary measure. I’m thinking of using Websockets for this, using Ably.io or Pusher, however I don’t know how efficient it would be, since PHP would only run a Curl to send the notifications.
I hadn’t considered pausing the request when it wasn’t visible.
– Inkeliz