Google App Engine.如何使用Memcache或数据存储区执行同步操作?

Google App Engine.如何使用Memcache或数据存储区执行同步操作?

问题描述:

我的主要目标是能够拥有一些同步方法,直到完成后,其他线程才可以访问该方法. 如果我有普通的VM-我会将此方法标记为已同步. 但是在GAE中,我有多个实例. 我所读到的所有帖子都说我应该使用内存缓存或数据存储. 但是到底如何呢?

My main goal is to be able to have some synchronized method that shouldn't be accessed by other threads until it is finished. If I had usual VM - I would mark this method as synchronized. But in GAE I have multiple instances. All posts that I read about this say that I should use memcache or datastore. But how exactly ?

通常,答案是重新设计该函数,因此不需要全局同步.即使您设法进行同步,也只有一个瓶颈.

Usually the answer is redesign the function so it doesn't need to be globally synchronized. Even if you manage to synchronize it, it's a single bottleneck.

您最好是在后端上实现它;您可以指定一个后端,并使您的函数调用对后端的请求.您也可以将Memcache或数据存储区用作信号灯,但是所有这些都会使您的性能降低.

You're probably best off to implement it on a backend; you can specify a single backend, and make your function call a request to the backend. You can also use memcache or the datastore as semaphore, but all of those are going to give you poor performance.