我需要的应用程序,需要经常轮询服务器,但GAE对请求的限制,因此使得大量的请求可能是非常昂贵的。是否有可能使用长轮询和请求等待最多30秒进行更改?Google App Engine中可以进行长时间轮询吗?
回答
谷歌AppEngine上有一个新的功能频道API,与你有 一个possibility to build a good realtime application。
另一种解决方案是使用一个第三部分彗星服务器像了Mochiweb 或具有IFRAME图案扭曲。
客户端1,等待一个事件:
client1 --Iframe Pattern--> Erlang/Mochiweb(HttpLongPolling):
客户机2,发送消息:
client2 --XhrIo--> AppEngine --UrlFetch--> Erlang/Mochiweb
使用带有彗星图案了Mochiweb,理查德·琼斯写了一个良好的 主题(在谷歌:理查德琼斯百万用户彗星应用程序)。
我不认为长轮询是可能的。 google appengine的默认请求超时时间为30秒。 在长时间轮询中,如果消息的生成时间超过30秒,则会失败。 你可能使用短轮询更好。
另一种方法是“模拟”长轮询withing的30秒的限制。要做到这一点,如果消息没有到达,例如20秒,服务器可以发送一个“令牌”消息,而不是正常的消息,要求客户端使用它并再次连接。
似乎有feature request(和它的接受)在谷歌AppEngine上的长轮询
Google App Engine现在拥有Channel API来支持长轮询。 – 2012-12-18 10:04:09
@检查问题发布和回答的时间,然后长轮询是不可能的。 – naikus 2012-12-19 10:57:50
哎呀,我的坏... – 2012-12-29 10:06:55
我们试图实现在App Engine类似彗星的长轮询的解决方案,但结果喜忧参半。
def wait_for_update(request, blob):
"""
Wait for blob update, if wait option specified in query string.
Otherwise, return 304 Not Modified.
"""
wait = request.GET.get('wait', '')
if not wait.isdigit():
return blob
start = time.time()
deadline = start + int(wait)
original_sha1 = blob.sha1
try:
while time.time() < deadline:
# Sleep one or two seconds.
elapsed = time.time() - start
time.sleep(1 if elapsed < 7 else 2)
# Try to read updated blob from memcache.
logging.info("Checking memcache for blob update after %.1fs",
elapsed)
blob = Blob.cache_get_by_key_name(request.key_name)
# Detect changes.
if blob is None or blob.sha1 != original_sha1:
break
except DeadlineExceededError:
logging.info("Caught DeadlineExceededError after %.1fs",
time.time() - start)
return blob
我看到的问题是,下面的请求长轮询之一,越来越连载(同步)长轮询请求后面。我可以在Chrome浏览器中查看一个跟踪并看到如下时间线:
- 请求1发送。 GET(未修改)blob(等到更改)。
- 请求2发送。修改blob。
- 充满后超时,请求1点返回(数据未修饰的)。
- 请求2在服务器上得到处理,并返回成功。
我已经使用wireshark和Chrome /时间线来确认我AM发送修改请求到服务器上的一个独立的TCP连接从长轮询之一。因此,这种同步必须在App Engine生产服务器上进行。就我所知,Google没有记录服务器行为的这些细节。
我认为等待渠道API是我们获得App Engine良好实时行为的最大希望。
- 1. 避免对Heroku和Google App Engine等服务进行轮询?
- 2. Google App Engine Cron时间表和长度
- 3. 'Google App Engine'远比'Google Compute Engine'贵吗?
- 4. 长时间在App Engine中的cron
- 5. 使用EventMachine的Rails应用程序是否可以进行长时间轮询?
- 6. Geocell和Google App Engine空间查询
- 7. Google云端硬盘可以与Google App Engine UserService集成吗?
- 8. Google App Engine超时?
- 9. 我可以在Google App Engine中使用JPA 2.0吗?
- 10. 我可以在Google App Engine中使用TA-Lib吗?
- 11. 我可以在Google App Engine中使用JavaCompiler吗?
- 12. 我可以在Google App Engine中使用Django的邮件API吗?
- 13. 在Google App Engine中,类可以是Expando和Polymodel吗?
- 14. 我可以在Google App Engine应用程序中使用facelets吗?
- 15. Google App Engine适合我吗?
- 16. 在Google App Engine上计算的最长时间
- 17. Google App Engine HRD迁移需要多长时间?
- 18. Google App Engine:查询用户?
- 19. Google App Engine地理查询
- 20. 以编程方式修改Google App Engine中的cron时间表
- 21. 在Google App Engine中以1秒的精度跟踪时间
- 22. 访问Google App Engine中Google电子表格的超时时间
- 23. 用ajax和servlets进行长时间轮询
- 24. 可从Google App Engine项目执行
- 25. Java中Google App Engine中的SQL查询?
- 26. 通过Google App Engine上的密钥ID进行过滤查询
- 27. Tweepy Streaming API可以在Google App Engine上使用吗?
- 28. 我可以使用Google App Engine处理数据吗?
- 29. 我可以在Google App Engine上实例化2个memcache类吗?
- 30. Google App Engine/GWT插件可以使用多模块项目吗?
渠道API尚未公开。以下是另外两种可供选择的服务: http://beaconpush.com http://pubnub.com – 2010-09-01 23:04:29
注意:Channel API将于2017年10月停止使用并关闭。 – Suma 2017-07-28 11:32:21