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

标签 python multithreading performance google-app-engine python-2.7

我在 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/

相关文章:

python - 仅在函数运行时显示 Gtk Spinner

python - Pygame screen.fill() 没有正确填充颜色

java - Wicket 和多线程业务对象

linux - 有多少个进程可以在后台并行运行

multithreading - Racket refresh-now, thread, and yield

java - 谷歌 Collection ( Guava 图书馆): ImmutableSet/List/Map and Filtering

performance - 如何减少 JMeter 日志?

python - Standard scaler 和 MinMaxScaler 之间的区别

python - dict.__setitem__(key, x) 是否比 dict[key] = x 慢(或快),为什么?

python - 异常处理 - 通过嵌套或循环再次运行函数?