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

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

问题描述

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

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

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

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?

我尝试缓存的实体列表是上周最好的(得分更高的)帖子.我拿了这个列表,随机选择了 5 个帖子,然后在几页中展示.

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.

感谢您的帮助!

推荐答案

App Engine 通过随着访问它的用户数量的增加而创建应用程序的新实例来扩展.正如 drudru 所说,不同的用户可能由不同的实例提供服务.一般来说,memcache 是存储你想要全局一致的东西的最快的地方.但是,就您而言,可能存在一些改进空间.

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.

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

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.

其次,你的内存缓存究竟是什么,你是如何把它拉出来的?您是否将一大堆完整的帖子存储在内存缓存中,获取所有帖子,然后选择 5 个?也许您可以直接下载帖子列表,选择 5 个,然后只获取您需要的 5 个?如果您认为是反序列化减慢了您的速度,这可能会有所帮助.收到帖子后,您是否对其进行了任何处理?如果是这样,是否可以缓存该处理的结果?

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天全站免登陆