Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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/. 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.

It seems to be generating a large overhead (5-6kb/second), which I would like to reduce if possible. 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. The server would then use the channel API to "spread the word" to all other relevant clients. Hope this makes some sense!

Any ideas?

like image 661
gibbutz Avatar asked Mar 07 '26 17:03

gibbutz


1 Answers

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.

As sje397 mentions, the Channel API currently does not support general broadcast -- you would need to implement your own. 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? 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. If you need to query the datastore, you'll probably be over that.

like image 152
Robert Kluin Avatar answered Mar 09 '26 07:03

Robert Kluin