解决方法,而不是使用websockets/ajax-long-pulling [英] Workaround instead of using websockets / ajax-long-pulling

查看:53
本文介绍了解决方法,而不是使用websockets/ajax-long-pulling的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的站点通过每5秒发出一次AJAX请求来检查数据库中是否有过期的提醒.有人告诉我这不理想,因为有太多的AJAX调用,一个人说,如果有很多人打开并打开了多个选项卡,这就像DDOS在自己的网站上一样.

My site checks the database for overdue reminders by making an AJAX request every 5 seconds. I've been told this is not ideal because of too many AJAX calls, one person said it's almost like DDOSing your own site if there are many people on with several tabs open etc.

替代方法是使用websockets或ajax-long-pulling.我无法使用websocket,因为我的共享托管不具备该功能.由于连接受限,Ajax长拉并不理想.

The alternatives are using websockets or ajax-long-pulling. I can't use websockets because my shared hosting doesn't have that capability. Ajax-long-pulling is not ideal because of limited connections.

所以我想到的一种解决方法是在服务器上有一个仅存储令牌的文件.浏览器每5秒钟通过一个隐藏的i帧读取此文件,并且如果数据库中发生了一些相关更改,令牌也会更改,这表示浏览器发送AJAX请求以获取新的提醒.

So a workaround I thought of would be to have a file on the server which simply stores a token. The browser reads this file via a hidden i-frame every 5 seconds, and if something relevant changes in the database the token is changed and this signals the browser to send an AJAX request to get the new reminders.

这是否是一种可行的解决方法,可以大大减少服务器上的负载,因为它只是读取文件而不会每5秒进行一次AJAX调用?

Would that be a feasible workaround to significantly reduce the load on the server since it's not making so many AJAX calls every 5 seconds since it's just reading the file instead?

推荐答案

有人说这几乎就像..."-那个人是您网站所在主机的系统管理员吗?

"one person said it's almost like ..." - was that person the system administrator of the host where your site runs?

因为我的共享托管服务器不具备此功能"-如果编写大量代码比转换Web提供商要便宜,那么您确实需要研究一下管理托管服务器的方式.

"because my shared hosting doesn't have that capability" - if writing lots of code is cheaper than switching web providers then you really need to look at your at the way you manage your hosting.

由于连接受限,Ajax长拉并不理想"-您认为同一个问题不适用于websocket吗?

"Ajax-long-pulling is not ideal because of limited connections" - and you think the same problem would not apply to websockets?

您似乎正在尝试解决一个未知的问题.而且您似乎无法评估所做的任何更改是否会产生预期的效果.

You seem to be trying to fix a problem you don't know exists. And you don't seem to be in a position to evaluate whether any changes you make will have the desired effect.

打折彗星和网络套接字后,减少对服务器的影响的唯一选择是减少轮询的频率.但是您的下一步应该是建立一种能力,以评估设施当前对服务器产生的影响以及如果您更改行为会如何变化.在共享主机上,这可能非常棘手-充其量您可能会看到其他租户产生的大量噪音,但是如果您确实在消耗大量资源,那么我很有信心,一个称职的托管服务提供商会提醒您这一点.

After discounting comet and websockets, your only option for reducing the impact on the server is to reduce the frequency of polling. But your next step should be to get establish a capability to assess what impact the facility currently has on the server and how that changes if you change the behaviour. This can be rather tricky on a shared host - at best you're going to see a lot of noise generated by other tenants, but if you really were consuming a lot of resources, I'm quite confident that a competent hosting provider would be alerting you to this.

这篇关于解决方法,而不是使用websockets/ajax-long-pulling的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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