最好通过 keys_only=True 然后 get_multi 查询还是只是完整查询? [英] Is it best to query by keys_only=True then get_multi or just full query?

查看:15
本文介绍了最好通过 keys_only=True 然后 get_multi 查询还是只是完整查询?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将 NDB 与 python 2.7 一起使用,并打开线程安全模式.

I am using NDB with python 2.7 with threadsafe mode turned on.

我知道使用 NDB 查询实体不使用本地缓存或内存缓存,而是直接进入数据存储,与通过键名获取不同.(如果这个前提不正确,剩下的问题可能是多余的.)

I understand that querying for entities with NDB does not use local cache or memcache but goes straight to the datastore unlike getting by key name. (The rest of the question might be redundant if this premise is not correct.)

因此,一个好的范例是只使用 keys_only=True 进行查询,然后使用 get_multi 来获取完整的实体吗?

Therefore would a good paradigm be to only query with keys_only=True and then do a get_multi to obtain the full entities?

好处是keys_only=True 查询比keys_only=False 快得多,get_multi 可能只是命中memcache &通过调用 get_multi,您的实体现在保存在内存缓存中,以防您需要再次执行查询.

The benefits would be that keys_only=True queries are much faster than keys_only=False, get_multi could potentially just hit memcache & by calling get_multi your entities are now saved in memcache in case you need to do the query again.

缺点是你现在有一个 RPC 查询调用 + get_multi 调用,我认为你可以在一个 get_multi 中调用实体的数量是有限的,因此你的有效查询大小可能会受到限制.

The drawbacks are that you now have an RPC query call + get_multi call and I think there is a limit to how may entities you can call in one get_multi therefore your effective query size might be limited.

你怎么看?我们应该只使用 keys_only=True 查询然后执行 get_multi 吗?是否存在某些最小和最大查询大小限制,使这种技术不如仅执行返回完整实体的查询有效?

What do you think? Should we only ever query using keys_only=True then perform get_multi? Are there certain minimum and maximum query size limits that make this technique not as effective as just doing a query that returns the full entities?

推荐答案

这已被广泛研究.请参阅 http://code.google.com/p/appengine-ndb-experiment/issues/detail?id=118

This has been extensively researched. See http://code.google.com/p/appengine-ndb-experiment/issues/detail?id=118

这篇关于最好通过 keys_only=True 然后 get_multi 查询还是只是完整查询?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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