问题标签 [polling]
For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.
jquery - 长时间轮询时,为什么我的其他请求需要这么长时间?
客户端发出 2 个并发请求。(1 需要 60 秒 - 长轮询)和另一个不是长轮询 - 应该立即返回。当我不进行长时间轮询时,它确实会立即返回。但是,一旦我开始对另一个线程进行长轮询,另一个线程就需要永远执行。
Firebug 显示请求正在等待 10-50 秒。在服务器上,我分析了从 php 脚本开始到返回客户端的所有请求,它显示每个请求只用了 300 毫秒或更短的时间。
这个问题大约在我开始进行长轮询(与其他 XHR 请求)的同时开始。我对这两个请求都使用了 jquery。
服务器显示它的负载非常轻。CPU 和内存少于 2%。8 个进程用完了 15 个进程。(它似乎与那个数字 8 相差不大,即使我运行了更多的 ajax 请求)。我猜每个进程可以同时运行多个 ajax 线程。
我确保在所有进程执行完毕后立即退出。如果 prstat -J 下仍有 7 个未使用的进程,我看不到进程池是如何用完的。此外,问题有时会间歇性地发生。Firefox 应该能够处理 2 个并发 ajax 请求。我不明白问题是什么。
c# - C# 轮询 TCP 服务器
大家好 - 我想知道是否有人可以帮助我 - 我需要经常轮询 TCP 服务器并请求接收一些实时数据。
我知道我需要创建一个线程才能与服务器对话,但我不确定如何经常进行此轮询。
任何帮助,将不胜感激...
php - 通过 TCP/IP 接收输入并使用它来更新 HTML
这必须是一个常见问题解答,所以有人可以将我定向到“傻瓜网络编程”URL吗?
当事件发生时,服务器希望将信息推送到客户端或向所有人广播——而不是客户端不断地轮询服务器“以防万一”。客户端然后更新浏览器页面显示。
我怎么做?(告诉你这是一个 n00b 问题)
我是否应该有一个线程在套接字上接收信息,然后将其写入浏览器显示(PHP)可以使用 HTML 刷新标记处理的数据库,还是什么?
很抱歉听起来这么笨。
c++ - Asynchronous I/O on Mac OS X
Meaning the C10K problem, what is the best way to do asynch I/O on Mac OS X (assume to use on Mac and iPhone/iPad)?
On Linux our choice is epoll, on Windows is I/O Completion Ports.
Top priority is performance and scalability (thousands of connections).
UPDATE
OK. As Darwin is BSD-like system, my common idea is to use kqueue. Is this a right direction? It would be nice to hear from someone experienced in this area.
Thanks
bash - 检测进程何时完成(但未退出)
我有一个在 unix 中运行的程序(我无法控制),完成后打印“成功完成”但不退出。我想自动检测进程何时完成(通过检查命令的输出),以便我可以终止进程并继续执行其他活动。之所以复杂,是因为我希望能够同时运行多个这些脚本。(我需要做的一项活动需要使用各种输入调用脚本,但是每次脚本运行都需要一段时间才能返回,所以我想并行执行)
有没有人做过类似的事情?我可以将命令的 stderr 和 stdout 输出重定向到一个具有随机文件名的临时文件,然后将该文件拖尾并通过管道传输到 grep 以获取结束条件(即某些日志行)。问题是,tail -f 肯定会继续运行,因此它永远不会退出。我应该投票吗?如果是这样,最好的方法是什么?
xml - 弥补 XML 文件的缺点之一
我正在使用 XML 文件来存储我的程序、服务将读取和应用的一组规则。显然,当我向 XML 文件添加新规则时,我将不得不退回服务以使更改生效。
如果我的 XML 规则文件发生更改,有没有一种方法可以让我每隔 30 秒左右“轮询”一次 XML 文件以避免不得不退回我的服务?
谢谢
terminology - 轮询和拉取有什么区别?
轮询和拉取(如果有的话)有什么区别?
javascript - 如何使我的 javascript 聊天轮询脚本更高效?
出于某种原因,对新聊天消息的检查会导致浏览器(在某种程度上是服务器)负载比我预期的要大。任何人都可以看到我可以提高效率以减轻负载的任何方法吗?
java - Waiting for invokeLater() to be called
Is there a more elegant way to do what I'm doing below? That is, is there a more elegant way than polling and sleeping, polling and sleeping, and so on to know when a Runnable.run()
method has been called via invokeLater()
?
java - Watching a variable for changes without polling
I'm using a framework called Processing which is basically a Java applet. It has the ability to do key events because Applet can. You can also roll your own callbacks of sorts into the parent. I'm not doing that right now and maybe that's the solution. For now, I'm looking for a more POJO solution. So I wrote some examples to illustrate my question.
Please ignore using key events on the command line (console). Certainly this would be a very clean solution but it's not possible on the command line and my actual app isn't a command line app. In fact, a key event would be a good solution for me but I'm trying to understand events and polling beyond just keyboard specific problems.
Both these examples flip a boolean. When the boolean flips, I want to fire something once. I could wrap the boolean in an Object so if the Object changes, I could fire an event too. I just don't want to poll with an if() statement unnecessarily.
Running this outputs:
On some forums people suggested using an Observer. And although this decouples the event handler from class being observed, I still have an if() on a forever loop.
Running this outputs:
I'd be ok if the if() was a NOOP on the CPU. But it's really comparing every pass. I see real CPU load. This is as bad as polling. I can maybe throttle it back with a sleep or compare the elapsed time since last update but this is not event driven. It's just less polling. So how can I do this smarter? How can I watch a POJO for changes without polling?
In C# there seems to be something interesting called properties. I'm not a C# guy so maybe this isn't as magical as I think.