Google App Engine:Memcache或静态变量? [英] Google App Engine: Memcache or Static variable?

查看:133
本文介绍了Google App Engine:Memcache或静态变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好吧,我想我在这里有一个非常基本的疑问:

我正在GAE(Java)上开发一个应用程序,并对返回的数据存储执行查询很多
的实体,所以我需要缓存它。我使用的是memcache,效果很好,但如果我将实体列表保存在一个静态变量中,整个请求的速度将比使用memcache快两倍。我认为这是因为我不是一直在反序列化实体。

在memcache上使用静态变量会有什么缺点?我不知道我的应用程序在云中是否可以有多个实例,因此我的静态变量有多个实例?



我尝试的实体列表缓存是上周最好的(更高分)帖子。



感谢您的帮助!

解决方案

通过创建应用程序的新实例,App Engine会随着用户数量的增加而进行扩展。正如drudru所说,不同的用户可能会由不同的实例提供服务。一般来说,memcache是​​存储您希望全球一致的最快速的地方。然而,在你的情况下,可能还有一些改进的空间。



你提到你有一个帖子列表,你随机选择5显示给用户。如果2个不同的用户看到不同的5个组合,这有什么关系?无论如何,如果你选择随机的,也许没关系。然后,您可以将完整的帖子列表存储在memcache中,并从memcache中随机取出5个,并将它们存储在一个静态变量中。

第二,你到底在做什么memcaching ,你怎么把它拉出来?你是否在memcache中存储了大量完整的文章,全部获取,然后选择5?也许你可以下载帖子列表,选择5,并只得到你需要的5个?如果你认为反序列化会让你放慢速度,这可能会有所帮助。你在收到邮件后是否正在对邮件进行任何处理?如果是这样,这个处理的结果可以被缓存吗?


Well, I think I have a very basic doubt here:

I'm developing an app on GAE (Java) and performing a query to the datastore that returns a lot of entities, so I need to cache it. I was using memcache and it was working great, but if I keep the list of entities in a static variable, the whole request goes as twice as fast than using memcache. I think that's because I'm not deserializing the entities all the time.

What would be the drawback of using a static variable instead on memcache? I don't know if there could be several instances of my application in the cloud, and thus several instances of my static variable?

The list of entities I'm trying to cache are the best (greater score) posts of the last week. I take that list and choose 5 random posts and show them in a couple of pages.

Thanks for the help!

解决方案

App Engine scales by creating new instances of your application as the number of users hitting it increases. As drudru said, different users might be served by different instances. In general, memcache is the fastest place to store something you want to be globally consistent. However, in your case there may be some room for improvement.

You mention you have a list of posts and you randomly choose 5 to show to users. Does it matter if 2 different users see a different set of 5? If you're choosing random ones anyway, maybe it doesn't matter. Then you could store the full list of posts in memcache, and pull 5 random ones out of memcache and store them in a static variable.

Second, what exactly are you memcaching, and how are you pulling it out? Are you storing a whole bunch of full posts in memcache, getting them all, then choosing 5? Maybe you could just download the list of posts, choose 5, and only get the 5 you need? If you think it's the deserializing that's slowing you down, this might help. Are you doing any processing on the posts after you get them? If so, could the results of that processing be cached?

这篇关于Google App Engine:Memcache或静态变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆