Google App Engine 中可以进行长轮询吗?
我需要制作需要经常轮询服务器的应用程序,但GAE对请求有限制,因此发出大量请求可能会非常昂贵。是否可以使用长轮询并使请求等待最多 30 秒的更改?
I need to make application that needs to poll server often, but GAE has limitations on requests, so making a lot of requests could be very costly. Is it possible to use long polling and make requests wait for the maxium 30 seconds for changes?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
Google AppEngine 有一个新功能 Channel API,您可以使用它
可以构建一个良好的实时应用程序。
另一个解决方案是使用第三方 Comet 服务器,例如 mochiweb
或用 iframe 模式扭曲。
客户端1,等待事件:
客户端2,发送消息:
要使用带有彗星模式的mochiweb,Richard Jones 写了一篇很好的文章
主题(在谷歌上:理查德琼斯百万用户彗星应用程序)。
Google AppEngine has a new feature Channel API, with that you have
a possibility to build a good realtime application.
Another solution is to use a third part comet server like mochiweb
or twisted with a iframe pattern.
Client1, waiting a event:
Client2, sending a message:
To use mochiweb with comet pattern, Richard Jones has written a good
topic (on google: Richard Jones A Million-user Comet Application).
我们尝试在 App Engine 上实现类似 Comet 的长轮询解决方案,但结果好坏参半。
我看到的问题是长轮询请求之后的请求在长轮询请求后面被序列化(同步)。我可以在 Chrome 中查看跟踪并看到如下时间线:
我使用了wireshark和Chrome/timeline来确认我正在通过与长轮询连接不同的TCP连接向服务器发送修改请求。因此,此同步必须发生在 App Engine 生产服务器上。据我所知,谷歌没有记录服务器行为的细节。
我认为等待通道 API 是我们从 App Engine 获得良好实时行为的最大希望。
We've tried implementing a Comet-like long-polling solution on App Engine, with mixed results.
The problem I'm seeing is that requests following a long-polling one, are getting serialize (synchronized) behind the long-polling request. I can look at a trace in Chrome and see a timeline like this:
I've used wireshark and Chrome/timeline to confirm that I AM sending the modification request to the server on a distinct TCP connection from the long-polling one. So this snychronization must be happing on the App Engine production server. Google doesn't document this detail of the server behavior, as far as I know.
I think waiting for the channel API is the best hope we have of getting good real-time behavior from App Engine.
我认为长轮询是不可能的。 google appengine 的默认请求超时为 30 秒。
在长轮询中,如果消息生成时间超过 30 秒,则会失败。
使用短轮询可能会更好。
另一种方法是“模拟”30 秒限制内的长轮询。为此,如果消息未在(例如 20 秒)内到达,服务器可以发送“令牌”消息而不是普通消息,要求客户端使用它并再次连接。
似乎有功能请求(且已接受)谷歌应用程序引擎进行长轮询
I don't think long polling is possible. The default request timeout for google appengine is 30 seconds.
In long polling if the message takes more than 30 secs to generate, then it will fail.
You are probably better off using short polling.
Another approach is to "simulate" long polling withing the 30 sec limit. To do this if a message does not arrive within, say 20 sec, the server can send a "token" message instead of a normal message, requiring the client to consume it and connect again.
There seems to be feature request (and its accepted) on google appengine for long polling