gpt4 book ai didi

python - 在运行 Python 2.7 的 Google App Engine 中获取 Thread.Lock 需要 50% 的响应时间

转载 作者:太空宇宙 更新时间:2023-11-03 11:33:52 25 4
gpt4 key购买 nike

我在 GAE 上使用 python27,希望减少应用程序的响应时间。

根据 cProfile,运行 1.6M 函数调用(似乎非常高)需要 40 秒(显然太长)。我现在能找到的唯一线索是“{method 'acquire' of 'thread.lock' objects}”需要 40 秒中的 20 秒。 (注意:在 app.yaml 中将 threadsafe 设置为 false 或 true 似乎没有太大效果。)

关于我哪里出错或接下来要调查哪里的任何想法?我知道获取锁所花费的大量时间可能只是症状而不是原因,但如果是这样,我如何才能找到根本原因?在 cProfile 中为我的函数列出的所有其他时间和 ncall 似乎都是合理的。

我还想知道这是否是由于 GAE 在 2011 年底的 2.7 中遇到的性能问题:

作为引用,这里是一个示例 cProfile 输出(删除了行):

Profile data:
1662549 function calls (1652247 primitive calls) in 39.545 seconds
Ordered by: cumulative time
ncalls tottime percall cumtime percall filename:lineno(function)
[lines removed]
10816 19.245 0.002 19.245 0.002 {method 'acquire' of 'thread.lock' objects}
[lines removed]

在此先感谢您提供的任何帮助!

最佳答案

如果您的应用程序的 RPC 非常繁重(对 datastore/urlfetch 等进行长时间调用),那么您会注意到在 thread.lock.acquire() 中等待花费了大量时间。

您可能想要启用 AppStats在您的应用程序中,查看每个 rpc 花费了多长时间。

关于python - 在运行 Python 2.7 的 Google App Engine 中获取 Thread.Lock 需要 50% 的响应时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10270625/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com