Django on GoogleAppEngine:性能howto [英] Django on GoogleAppEngine: performance howto

查看:158
本文介绍了Django on GoogleAppEngine:性能howto的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

几周前我询问了这个问题。今天我实际上已经编写并发布了一个标准的Django应用程序,即由 Google CloudSQL 。唯一不得不偏离标准Django方式的事情是发送电子邮件(必须以GAE方式)。我的设置是 GAE 1.6.4 Python2.7 Django 1.3 app.yaml 中使用以下内容:

 库: 
- name:django
version:1.3

然而,我确实需要你建议明确的可操作步骤,以改善此Django应用程序在寒冷时响应初始请求的响应时间。我在GAE上有一个简单的 webapp2 网站,它不会击中数据库,而当 cold 响应时间是 1.56s 。 Django的一个是 cold ,用2个查询(两个 count(*)查询每个包含少于300行的表)访问数据库,并且响应时间是 10.73s !不鼓励主页;)

我想到的是删除中间件类,需要和其他Django特定的优化。然而,从GAE的角度来看,改善事情的提示也是非常有用的。



NB 我不希望这会成为讨论在GAE上参加Django的优点。我可以提到,我个人的Django专业知识以及由此产生的开发生产力在采用Django方面确实承担了很大的作用,而不是其他框架。而且,对于CloudSQL,很容易从GAE(希望不是!)中移开,因为Django代码在其他任何地方都可以工作,只需很少(或不进行)修改。有关此主题的相关讨论可在此处找到此处

解决方案

我没有一个完整的答案,但我在贡献,因为我也想找到解决方案。我目前正在使用正在运行的cron作业(我实际上需要cron作业,所以它不仅仅是为了让我的应用程序保持活跃状态​​)。



我已经在讨论过GAE / Python / Django相关的邮件列表之一,与web应用程序相比,装载所有Django文件所需的时间很长,因此,删除部署中未使用的django组件也应该可以缩短启动时间。我可以通过删除contrib文件夹的某些部分来削减大约3秒。我将它们排除在我的app.yaml中。



我的启动时间仍在6秒左右(完整应用程序,Django-nonrel,HRD)。当我的应用程序更简单时,它曾经更像4。



我怀疑Django在启动时验证了所有模型,并且处理时间很长。如果您有时间尝试使用绝对为0的应用程序,我会好奇它是否会产生任何影响。



我也很好奇你的两个初始查询会产生重大影响。

I asked this question a few weeks ago. Today I have actually written and released a standard Django application, i.e. a fully-functional relational DB-backed (and consequently fully-functional Django admin) enabled by Google CloudSQL. The only time I had to deviate from doing things the standard Django way was to send email (had to do it the GAE way). My setup is GAE 1.6.4, Python2.7, Django 1.3 using the following in app.yaml:

libraries:
- name: django
  version: "1.3"

However I do need you to suggest clear actionable steps to improve to the response time of the initial request when cold of this Django app. I have a simple webapp2 web site on GAE, which does not hit the DB, and when cold the response time is of 1.56s. The Django one, when cold, hits the DB with 2 queries (two count(*) queries over tables containing less than 300 rows each), and the response time is of 10.73s! Not encouraging for a home page ;)

Things that come to mind are to remove the middleware classes I don't need and other Django-specific optimisations. However tips that improve things also from a GAE standpoint would be really useful.

N.B. I don't want this to become a discussion about the merits of going for Django on GAE. I can mention that my personal Django expertise, and resulting development productivity, did bear considerably in adopting Django as opposed to other frameworks. Moreover with CloudSQL, it's easy to move away from GAE (hopefully not!) as the Django code will work everywhere else with little (or no) modifications. Related discussions about such topic can be found here and here.

解决方案

I don't have a full answer but I'm contributing since I'd like to find a solution as well. I'm currently using a running cron job (I actually need the cron job, so it's not only for keeping my app alive).

I've seen it discussed in one of the GAE/Python/Django related mailing lists that just the time required for loading up all the Django files is significant when compared to webapp, so removing django components that you don't use from deployment should improve your startup time as well. I've been able to shave off about 3 seconds by removing certain parts of the contrib folder. I exclude them in my app.yaml.

My startup time is still around 6 seconds (full app, Django-nonrel, HRD). It used to be more like 4 when my app was simpler.

My suspicion is that Django verifies all its models on startup, and that processing time is significant. If you have time with experimenting with an app with absolutely 0 models, I'd be curious if it made any impact.

I'm also curious as to whether your two initial queries make any significant impact.

这篇关于Django on GoogleAppEngine:性能howto的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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