Best Method of Channel Pooling in Google App Engine

你说的曾经没有我的故事 提交于 2019-12-02 15:59:06

Here's what I'd do (I'm actually considering writing this library after seeing your question. I need it too):

Create a taskpool module with the following API.

client_id, token = taskpool.get()

# Setup a heartbeat in the client JS, maybe every minute. 
# Also call this every time the client indicates presence
taskpool.ping(client_id)

taskpool.release(client_id)

Implementation:

  • Store the client_id and token in an entity, with a status indicating whether it's being used, last ping time, and creation time. Let the client_id be the key. Also consider using NDB. Free memcaching.

get() checks if there are unused tokens and returns one if it finds it. Otherwise create a new one, store and return it.

ping() updates the last ping time for that token. Instead of polling, let the client send in a ping every [heartbeat] time.

release() marks the token as unused.

Run a task / cron every [heartbeat] seconds to find the tokens which haven't gotten a ping in a while - and set them as unused.

When clients report a closed token, perform a get().

Keep in mind, though, that a loss in security is a by-product of any kind of token pooling. If a malicious client has held on to a token and stopped sending heartbeats, it might later be able to listen in on the messages being passed to the new client once the token is re-purposed. This isn't a problem if you're on a fully public site, but keep it in mind anyway.

I will update this answer if and when I write this up as a library.

er0

According to the Google App Engine support team, channel tokens may not be reused. Reusing them is not expected to work.

Can Google App Engine Channels be reused?

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!