通过Javascript持续查询服务器 - 好主意? [英] Constantly Querying Server via Javascript - Good Idea?
问题描述
我的问题很简单:这样做有什么问题吗?我正在每个请求中调用一小段文本,并且请求可能一次只能在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屋!