简体   繁体   English

引擎,python27的性能下降

[英]Appengine, performance degradation with python27

I wanted to test python27 on appengine so I have migrated my app from python25. 我想在appengine上测试python27,所以我从python25迁移了我的应用程序。 Performance got more than 2x slower for every request! 每个请求的性能都要慢2倍! Then I've returned to python25 and performance is again as it was before. 然后我又回到了python25,性能再次像以前一样。 Here is a picture: 这是一张图片:

在此输入图像描述 (milliseconds/request) (cgi handler python 27, then python25) (毫秒/请求)(cgi处理程序python 27,然后是python25)

My app uses Werkzeug , Jinja2 , and memcache is used quite alot. 我的应用程序使用WerkzeugJinja2 ,并且使用了很多memcache。 What reasons can cause such a dramatic decrease in performance? 什么原因会导致性能急剧下降? Or is it just because python2.7 on appengine is still in beta? 或者仅仅是因为appengine上的python2.7还处于测试阶段?

Some details about application: 关于申请的一些细节:

It is quite simple online shop. 这是一个非常简单的网上商店。 There are some deferred tasks with pdf generation however these don't affect overall graph much because the front page gets most hits. 有一些延迟的任务与pdf生成,但这些不会影响整体图形,因为首页获得最多的命中。 Nearly everything is memcached. 几乎所有内容都是memcached。 It takes up to ~0.8 sec with empty cache to load a page with python 2.5. 使用python 2.5加载页面时,空缓存需要约0.8秒。 Non-cached pages takes long to load mainly because there are many db queries. 非缓存页面加载时间很长,主要是因为有很多数据库查询。 Cached pages load in 60~100 ms. 缓存页面加载时间为60~100 ms。 Average load time is ~150 ms. 平均加载时间约为150毫秒。 With python 2.7 performance is terrible. 用python 2.7表现很糟糕。 Non-cached pages takes 2+ secs to load. 非缓存页面需要2秒以上才能加载。 Cached pages load in 200+ ms. 缓存页面加载时间超过200毫秒。

Unfortunately I don't have any profiling data and I can't tell what exactly slows things down in python 2.7. 不幸的是,我没有任何分析数据,我无法分辨python 2.7中究竟是什么减慢了。

My numbers for page-load time are collected from live page which serves ~10 req/sec and 1 resident python25 instance easily deals with this load. 我的页面加载时间数据是从实时页面收集的,该页面提供~10 req / sec和1个常驻python25实例,可以轻松处理此负载。

I have also tested python 2.7 with wsgi and threadsafe:yes , but performance improved just a little compared to python 2.7 and cgi. 我还用wsgi和threadsafe:yes测试了python 2.7 threadsafe:yes ,但与python 2.7和cgi相比,性能提升了一点点。

Somewhere on Usenet I read a statement like this from Google "he Python 2.7 runtime is slower than the Python 2.5 runtime in some cases and faster in others. We aren't publicizing the reasons why at this point.". 在Usenet的某个地方,我从Google那里读到了这样一句话:“在某些情况下,Python 2.7运行时比Python 2.5运行时慢,而在其他情况下则更快。我们现在还没有公开原因。” Seems nobody has found so far a scenario where 2.7 is faster than 2.5 thus ... 似乎到目前为止没有人发现2.7比2.5更快的情况因此......

I read into this 我读到了这个

  1. Google is aware of a preformace issue. 谷歌知道一个预先形成的问题。
  2. They not sure how to handle it. 他们不确定如何处理它。

My profiling indicates that python 2.7 multithreaded applications spend ca. 我的分析表明python 2.7多线程应用程序花费大约。 35 % of their time in {method 'acquire' of 'thread.lock' objects} - and seemingly that happens in googles RPC code. 他们35%的时间都在{method 'acquire' of 'thread.lock' objects} - 而且似乎是在谷歌的RPC代码中发生的。 There are also indication that importing has serious locking issues. 还有迹象表明导入存在严重的锁定问题。

Basically you can't do anything about it except waiting for the AppEngine to fix it. 除了等待AppEngine修复它之外,基本上你无能为力。 See also this comprehensive documentation about the slowdown. 另请参阅有关减速的综合文档

Factors which almost certainly don't play a significant role in this are: 几乎肯定不会在这方面发挥重要作用的因素是:

  • uploading pyc files (the GAE infrastructure does that for you) 上传pyc文件(GAE基础设施为您做到这一点)
  • the server provisioning (GAE is such a massive scale and even in closed beta 2.7. was slow) 服务器配置(GAE规模如此之大,甚至在封闭式测试版2.7中也很慢)
  • WSGI vs. CGI (wouldn't explain such a huge performance hit) WSGI与CGI(不会解释如此巨大的性能影响)

The ugly thing is that Google did a massive price hike in two steps but told us "by using multithreaded python 2.7 you can run so much more effective that the new prices don't look so bad". 丑陋的是,谷歌在两个步骤中进行了大规模的价格上涨,但告诉我们“通过使用多线程python 2.7,你可以运行更高效,新价格看起来不那么糟糕”。 Unfortunately the Python 2.7. 不幸的是Python 2.7。 runtime is still labeled "experimental" and doesn't deliver production quality performance. 运行时仍然标记为“实验性”,并且不提供生产质量性能。

Python 2.7 support is still experimental. Python 2.7支持仍然是实验性的。 One aspect of being new and experimental is that it hasn't had the kind of performance baking and tuning that Python 2.5 has. 新的和实验性的一个方面是它没有Python 2.5具有的那种性能烘焙和调整。

Did you migrated your application to use WSGI instead of CGI when run on python 2.7? 在python 2.7上运行时,您是否将应用程序迁移到使用WSGI而不是CGI?

It is possible that CGI interface is just a wrapper around WSGI that is enabled for 2.7 now. CGI接口可能只是现在为2.7启用的WSGI的包装器。

By swtiching to python2.7 my app performance under load is 3x worse. 通过切换到python2.7,我的应用程序在负载下的性能差3倍。

With 2.5: 用2.5:

Connection Times (ms) min mean[+/-sd] median max Connect: 36 48 15.4 41 109 Processing: 685 3010 1893.3 2657 9255 Waiting: 685 3009 1893.3 2656 9255 Total: 725 3058 1900.5 2711 9333 连接时间(ms)min mean [+/- sd]中位数最大连接数:36 48 15.4 41 109处理:685 3010 1893.3 2657 9255等待:685 3009 1893.3 2656 9255总计:725 3058 1900.5 2711 9333

Percentage of the requests served within a certain time (ms) 50% 2711 66% 3287 75% 3896 80% 4521 90% 6146 95% 7078 98% 7934 99% 8413 100% 9333 (longest request) 在特定时间内服务的请求百分比(毫秒)50%2711 66%3287 75%3896 80%4521 90%6146 95%7078 98%7934 99%8413 100%9333(最长要求)

With 2.7: 用2.7:

Connection Times (ms) min mean[+/-sd] median max Connect: 35 46 11.4 41 96 Processing: 1076 7614 4190.5 6711 32284 Waiting: 1075 7614 4190.5 6711 32283 Total: 1124 7660 4195.5 6764 32353 连接时间(ms)min mean [+/- sd] max maximum连接:35 46 11.4 41 96处理:1076 7614 4190.5 6711 32284等待:1075 7614 4190.5 6711 32283总计:1124 7660 4195.5 6764 32353

Percentage of the requests served within a certain time (ms) 50% 6764 66% 7790 75% 8751 80% 9392 90% 10844 95% 13139 98% 25219 99% 27259 100% 32353 (longest request) 在特定时间内服务的请求百分比(毫秒)50%6764 66%7790 75%8751 80%9392 90%10844 95%13139 98%25219 99%27259 100%32353(最长请求)

A quote from google itself 来自谷歌本身的一句话

Experimental! 实验!

The Python 2.7 runtime is an experimental, innovative, and rapidly changing new feature for App Engine. Python 2.7运行时是App Engine的实验性,创新性和快速变化的新功能。 Unfortunately, being on the bleeding edge means that we may make backwards-incompatible changes. 不幸的是,处于前沿意味着我们可能会做出向后不兼容的变化。 We will inform the community once the Python 2.7 runtime is no longer experimental. 一旦Python 2.7运行时不再是实验性的,我们将通知社区。

They haven't really made it for production use yet , Its like beta testing . 它们还没有真正用于生产用途,它就像beta测试一样。

So keep your application in python2.7 till the experimental phase is over. 因此,请将您的应用程序保存在python2.7中,直到实验阶段结束。

You can also try uploading only the compiled .pyc files because python27 runtime supports bytecode upload 您还可以尝试仅上载已编译的.pyc文件,因为python27运行时支持字节码上载

As far as I know, Python 2.7 should be faster than 2.5. 据我所知,Python 2.7应该比2.5快。 However, there are some factors that can influence speeds: 但是,有一些因素会影响速度:

  • The way the binary is compiled; 二进制编译的方式;
  • Whether your libraries (such as Memcache) are compiled as C(++) or Python. 您的库(例如Memcache)是编译为C(++)还是Python。 A C++ module is, of course, faster than the Python equivalent; 当然,C ++模块比Python等效模块更快;
  • The server it's on - I haven't ever used App Engine but I'd assume that a server only runs either Python 2.5 or Python 2.7, since mixing them would be a waste of resources. 它所使用的服务器 - 我从未使用过App Engine,但我认为服务器只运行Python 2.5或Python 2.7,因为混合使用它们会浪费资源。 If the 2.7 servers are used a lot more than the 2.5 servers and App Engine hasn't compensated for this, you'll notice the performance go down as well. 如果使用的2.7服务器比2.5服务器多得多,并且App Engine没有对此进行补偿,您会发现性能也会下降。

These are the first 3 things that I came up with, but there are a lot of factors. 这是我提出的前三件事,但有很多因素。 Even the weather could in theory affect performance. 即使是天气也可能在理论上影响性能。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM