python - 改进获取时间和该函数的性能

标签 python performance google-app-engine

我正在使用过滤其 name 属性的查询来搜索 Final 模型(定义如下)。此查询在开发服务器上执行大约需要2200毫秒。我怎样才能加快速度?这是一个AppStats screenshot .

我也在created字段上进行过滤,但这花费了超过10000毫秒,所以我现在删除了查询的这一部分。

class Final(db.Model):
    name = db.StringProperty()     # 7 characters long
    author = db.StringProperty()
    rating = db.FloatProperty()
    created = db.DateTimeProperty()

# this is the important part of the request (AppStats shows that these two
# queries take about 2200ms each).

 query = Final.all()
 query2 = Final.all()
 query.filter('name = ', link1)
 query2.filter('name = ', link2)
 aa = query.fetch(10000)
 bb = query2.fetch(10000)

最佳答案

虽然 David 的建议很好,但优化开发服务器的速度可能不是一个好主意。开发服务器的性能并不能反射(reflect)生产服务器的性能,并且基于开发服务器运行时的优化在生产中可能效果不佳。

一般来说,您可以假设开发服务器的性能会随着记录的添加而降低,但在生产中绝对不是这种情况,您的查询运行时间仅取决于结果集的大小。如果您可以减少生产中示例数据集的大小,这可能是加快开发速度的最佳选择。

关于python - 改进获取时间和该函数的性能,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3301607/

相关文章:

Python:回顾n天滚动标准差

google-app-engine - Go,Google Cloud Appengine 本地包

python - 类型错误 : 'int' object does not support item assignment error

mysql - 是否有用于在 MySQL 中进行调试、分析和跟踪的好工具?

performance - 在 Three.js 中高效渲染数以万计的可变大小/颜色/位置的球体?

performance - IIS 与 Kestrel 性能比较

python - 谷歌应用引擎上的 mimetypes.mime_guess() 行为异常

python-2.7 - 从数据存储区读取(跨组)实体时发生 TransactionFailedError(争用过多...)

python - 在绘图之前如何将模块转换为列表或数组?

Python 为 S3 Post 生成的签名