简体   繁体   English

Google App Engine:浏览器到服务器的持久连接

[英]Google App Engine: Browser to Server persistent connection

I've been playing around with the Google App Engine channel API to create a real-time multiplayer game similar to http://rawkets.com/ . 我一直在使用Google App Engine渠道API来创建类似于http://rawkets.com/的实时多人游戏。 Since this API is basically "one way" (doesn't enable a persistent browser-to-server connection), I am just issuing new AJAX POST requests (JQuery) at about 30/second. 由于这个API基本上是“单向”(不支持持久的浏览器到服务器连接),我只是以大约30 /秒的速度发布新的AJAX POST请求(JQuery)。

It seems to be generating a large overhead (5-6kb/second), which I would like to reduce if possible. 它似乎产生了很大的开销(5-6kb /秒),如果可能的话我想减少。 Ideally I would like to create only one connection that lasts a bit less than 30 seconds (the appengine request timeout) and continues to send fresh data every 30 milliseconds for the duration of the connection. 理想情况下,我只想创建一个持续时间少于30秒的连接(appengine请求超时),并在连接期间每30毫秒继续发送新数据。 The server would then use the channel API to "spread the word" to all other relevant clients. 然后,服务器将使用通道API将“传播单词”传播给所有其他相关客户端。 Hope this makes some sense! 希望这有一定道理!

Any ideas? 有任何想法吗?

There are two major problems with creating long-lived connections yourself. 自己创建长期连接有两个主要问题。

  1. You can't stream output from the server, it will be buffered then sent when the handler exits . 您不能从服务器流输出,它将被缓冲,然后在处理程序退出时发送
  2. Your app will not be auto-scaled if your requests do not return in under 1,000ms . 如果您的请求未在1,000毫秒内返回,您的应用将不会自动调整

As sje397 mentions, the Channel API currently does not support general broadcast -- you would need to implement your own. 正如sje397所提到的,Channel API目前不支持普通广播 - 您需要实现自己的广播。 However, if you are just trying to push to several nearby players, implementing your own solution may not be an issue. 但是,如果您只是想向附近的几个玩家推送,那么实施您自己的解决方案可能不是问题。

What are you attempting to do every 30ms? 你每30ms试一次做什么? You'll need a very well thought-out design, just reading and setting a value in memcache is going to consume close to half of that time . 你需要一个经过深思熟虑的设计,只需在memcache中读取和设置一个值就可以消耗近一半的时间 If you need to query the datastore, you'll probably be over that . 如果您需要查询数据存储区,那么您可能已经完成了

Broadcast doesn't work too well using the built-in channel API (although they have said on the mailing list that something is in the works). 使用内置的通道API,广播效果不佳(尽管他们已经在邮件列表中说某些内容正在进行中)。

You might want to check out a third-party 'real' websockets provider. 您可能想要查看第三方“真正的”websockets提供程序。 For example, http://pusherapp.com . 例如, http://pusherapp.com

This simply isn't how HTTP works - it sounds like what you want is closer to the (forthcoming) websockets API, which isn't widely supported in browsers yet, or supported at all by App Engine. 这根本不是HTTP的工作原理 - 它听起来像你想要的更接近(即将出现的)websockets API,它在浏览器中尚未广泛支持,或者App Engine完全支持。

Still, 30 requests per second per client seems particularly absurdly high - there's no way a single user on a keyboard can generate that many events. 尽管如此,每个客户端每秒30个请求似乎特别荒谬 - 键盘上的单个用户无法生成那么多事件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM