通过Javascript持续查询服务器 - 好主意? [英] Constantly Querying Server via Javascript - Good Idea?

查看:178
本文介绍了通过Javascript持续查询服务器 - 好主意?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个小型网站,拥有约5-10名管理员。我设置了监控每个管理员正在做什么(添加项目,删除项目等)。我在管理面板中列出了列出了集体行政部门执行的前10项活动。今天我决定每30秒自动更新一次。



我的问题很简单:这样做有什么问题吗?我正在每个请求中调用一小段文本,并且请求可能一次只能在3台或4台计算机上运行(反映并发管理员登录的数量)。



$ $ $ $ $ $ $ $ $ $($)$($)$($)

function activity(){
$(#recent_activity)。load(../ home / login #recent_activity .data);
}

每个请求产生以下(或类似 - 只有10行)。

 < table> 
< tbody>
< tr>
< td>< p> jsampson< / p>< / td>
< td>< p>注销< / p>< / td>
< td>< p> 28分27秒前< / p>< / td>
< / tr>
< tr>
< td>< p> jdoe< / p>< / td>
< td>< p>登录< / p>< / td>
< td>< p> 29分45秒前< / p>< / td>
< / tr>
< / tbody>
< / table>


解决方案

3-4个用户每30秒不是很很多即使是300个用户也不会太多。



您可能需要查看以下问题:





您也可以缓存此值,并且建议特别是如果生成页面的查询在计算上很重,但当然要考虑到在显示最近的内容中想要什么样的滞后。


I've got a small website that has about 5-10 administrators. I've set it up to monitor what each administrator is doing (adding items, removing items, etc). I had a list within our admin-panel that shows the previous 10 activities performed by the collective administration. Today, I decided to make this self-updating every 30 seconds.

My question is simple: is there any problem doing this? I'm calling a small bit of text with each request, and the request is likely only running on 3 or 4 computers at a time (reflecting the number of concurrent-administrators logged in).

  $(document).ready(function(){
    setInterval("activity()", 30000);
  });

  function activity() {
    $("#recent_activity").load("../home/login #recent_activity .data");
  }

Produces the following (or similar - only with 10 rows) with each request.

<table>
  <tbody>
    <tr>
      <td><p>jsampson</p></td>
      <td><p>logged out</p></td>
      <td><p>28 minutes 27 seconds ago</p></td>
    </tr>
    <tr>
      <td><p>jdoe</p></td>
      <td><p>logged in</p></td>
      <td><p>29 minutes 45 seconds ago</p></td>
    </tr>
  </tbody>
</table>

解决方案

3-4 users every 30 seconds isn't very much at all. Even 300 users at that rate wouldn't be much at all.

You may want to check into these questions:

You can cache this as well, and it would be advisable especially if the query to generate the page is computationally heavy, but of course take into account what kind of lag you want in the most recent content being displayed.

这篇关于通过Javascript持续查询服务器 - 好主意?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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