Comet 软件相对于标准长轮询的优势
我一生都无法弄清楚像 Cometd 或 simple-comet 这样的应用程序的目的,比如使用 php 的简单长轮询请求和无限循环,其中的代码
$time = time();
while(time() - $time < 30) {
if ($query) {
$shapes = ...;
echo json_encode($shapes);
break;
}
usleep(25000);
}
在专为多个请求而设计的网络服务器上运行,例如 lighttpd或 NGIX。
也许我只是错过了理解彗星服务的文档。我知道上面是一个“Comet”请求,但是为什么像 cometd 这样的东西存在,它们在哪些方面做得更好。
I cannot figure out for the life of me the purpose of an application like Cometd or simple-comet over something like a simple longpolling request with php and an infinite loop with code like so
$time = time();
while(time() - $time < 30) {
if ($query) {
$shapes = ...;
echo json_encode($shapes);
break;
}
usleep(25000);
}
running on a webserver that is designed for multiple requests, like lighttpd or NGIX.
maybe I am just miss understanding the documentation of comet services. I know the above is a "Comet" request but why do things like cometd exist, what do they do better.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Cometd 和类似的软件(如 Orbitd)非常适合划分区域责任。我可以让我的 lighttpd 支持的 python 服务专注于做更多涉及的工作,而 comet 服务绑定到消息队列来处理轻消息通知(前批处理请求已完成,您收到了一条新消息等),而 lighttpd 服务器处理数据库请求或处理 POST/PUT/DELETE 请求。
最后一点,Apache 仍然是一个非常流行的 Web 服务器,但如果它试图保持一千个或更多的连接打开,它就会在辉煌中消亡。对于一个拥有一系列 apache 服务器并希望添加 comet 支持的平台,采用开箱即用的解决方案比使用 lighttpd 或 nginx 滚动解决方案更有意义。
Cometd and similar software like orbitd are great for breaking up area's of responsibility. I can have my lighttpd backed python services focus on doing more involved work while the comet service is tied to a message queue to handle light message notifications (ex batch request is finished, you've got a new message, etc ) while the lighttpd servers handle DB requests or process POST/PUT/DELETE requests.
Last point, Apache is still a very popular web server but it will die in a blaze of glory if it tries to hold a thousand or more connections open. For a platform with an array of apache servers that wants to add comet support, it would make sense to go with an out of the box solution versus rolling one with lighttpd or nginx.