Django on GoogleAppEngine: performance

I asked this question a few weeks ago. Today, I actually wrote and released a standard Django application, i.e. a fully functional relational DB-backed (and therefore a fully functional Django admin) included by Google CloudSQL . The only time I had to deviate from doing something in the standard Django way was to send an email (I had to do this using the GAE method). 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 need you to suggest clear steps to improve the response time of the original request when this Django application is cold . I have a simple webapp2 website that doesn’t get into the database, and when it’s cold, the response time is 1.56s . Django alone, when it’s cold, gets into the database with two queries (two count(*) queries on tables containing less than 300 rows), and the response time is 10.73s ! Not recommended for homepage;)

Things that come to mind are to remove middleware classes that I don’t need, and other Django-specific optimizations. However, tips that will improve the situation also from the point of view of GAE will be really useful.

NB I do not want this to become a discussion about the benefits of switching to Django on GAE. I can mention that my personal experience with Django and, as a consequence, development productivity, significantly influenced the adoption of Django, and not other structures. Also, with CloudSQL, it's easy to get away from GAE (hopefully not!), Since Django code will work wherever there is little (or no) change. Related discussions on this topic can be found here and here .

+6
source share
2 answers

I do not have a complete answer, but I am contributing because I want to find a solution. I am currently using the current cron job (I really need the cron job, so it’s not only for saving my application).

I saw how it was discussed on one of the GAE / Python / Django-related mailing lists that the loading time of all Django files is significant compared to webapp, so removing django components that you don’t use from deployment should also improve startup time. I was able to shave about 3 seconds by deleting some parts of the contrib folder. I exclude them in my app.yaml.

My boot time is still about 6 seconds (full application, Django-unreal, HRD). It was more like 4 when my application was easier.

My suspicion is that Django checks all of its models at startup and that the processing time is significant. If you have time with an experiment with an application with absolutely 0 models, I would be curious if this would affect.

I am also curious if your two initial requests have any significant impact.

+2
source

If the instance is not started, for example, after updating the version or if there is no request for 15 minutes, the request initiates the loading of the instance, which takes about 10 seconds. So what you see is normal.

So, if your application has been idle for more than 15 minutes, you will see this behavior. One way is to cron your instance every 10 minutes (although I find that Google doesn't like it).

Update:

You can avoid this by enabling billing, and then in GAE admin in the "Application Settings" section, set the minimum Idle Instances to 1. Note: the min parameter is not available in free applications, only max .

+2
source

Source: https://habr.com/ru/post/912040/


All Articles