简体   繁体   English

Appengine优化

[英]Appengine Optimizations

How can I get the requests of my Google AppEngine application to perform better and faster (ie less load times and less CPU usage)? 如何获得Google AppEngine应用程序的请求,使其执行得更快更好(例如,更少的加载时间和更少的CPU使用率)? I'm specifically referring to imporvements for the server-side portion of the app, and not the client-side. 我专门指的是应用程序的服务器端部分而不是客户端的改进。

Use appengine Appstats to see where actually your application uses more cpu resources.Try to find out the reason for that and look for alternative solution. 使用appengine Appstats可以查看您的应用实际在何处使用更多的CPU资源。尝试找出原因,并寻找替代解决方案。 In python you can do lot of optimisation. 在python中,您可以进行很多优化。 M 中号

  1. Make use of memcache api which makes data fetch easy and fast. 利用memcache api可以轻松快速地获取数据。 Avoid unnecessary fetch() and get(). 避免不必要的fetch()和get()。

  2. Avoid doing a lot of RPCs while using db.reference() property. 在使用db.reference()属性时,避免进行大量的RPC。 Nick's blog on this explains about this. 尼克的博客对此进行了解释。

  3. Modeling in appengine matters a lot in performance. 在appengine中进行建模对性能至关重要。 Make sure you have the right model designed for your application. 确保您具有适合您的应用程序设计的模型。

  4. Avoid doing get and fetch unless until you really need them. 除非真正需要它们,否则避免进行获取和获取。

我建议使用Appstats来查看应用程序中的瓶颈。

I use memcache which significantly increased my app's performance. 我使用内存缓存 ,这大大提高了我的应用程序的性能。 I hope it also can be usable for you. 我希望它也可以为您使用。 When using memcache in combination with a HTTP header setting the cache-control I've gotten significant improvements in response times. 当结合使用memcache和HTTP标头设置cache-control时,我在响应时间方面有了明显的改进。

This is not really an optimization but the choice of framework is really important here. 这并不是真正的优化,但是框架的选择在这里确实很重要。 Most legacy framework in Java and Python(Django,..) are not designed to startup fast because it just isn't important in traditional hosting. Java和Python(Django,..)中的大多数旧式框架都不旨在快速启动,因为它在传统托管中并不重要。 Consider using an App Engine specific framework like Tipfy, Kai, Webapp, ... (Python) or slim3, ... (Java). 考虑使用特定于App Engine的框架,例如Tipfy,Kai,Webapp,...(Python)或slim3,...(Java)。

Ideally, you should organize your data so that each user request needs only one call to the datastore, preferably a db.get because queries are significantly slower. 理想情况下,应该组织数据,以便每个用户请求只需要对数据存储(最好是db.get)的一个调用,因为查询速度明显慢。 To achieve this, you'll often need to denormalize your data, and maintain the different copies in sync using entity groups and transactions. 为此,您通常需要对数据进行非规范化,并使用实体组和事务来同步维护不同的副本。

When making more than one urlfetch or API call, you can speed up the process by making the calls in parallel using the non-blocking(async) syntax. 当进行多个urlfetch或API调用时,您可以通过使用non-blocking(async)语法并行进行调用来加快处理速度。 Caching whenever possible is of course really important too. 当然,尽可能地缓存也是非常重要的。

If you haven't yet, I recommend watching Google's IO talks (2010 & 2011), in particular this year's Scaling App Engine Applications which does a very good job of describing server-side best practices. 如果您还没有的话,我建议您观看Google的IO演讲(2010年和2011年),尤其是今年的Scaling App Engine应用程序 ,它在描述服务器端最佳实践方面做得很好。

One often overlooked aspect is that various Appengine related services support asynchronous processing, for example Datastore: 一个经常被忽视的方面是与Appengine相关的各种服务都支持异步处理,例如数据存储区:

https://cloud.google.com/appengine/docs/java/datastore/async https://cloud.google.com/appengine/docs/java/datastore/async

and URL Fetch: 和网址提取:

https://cloud.google.com/appengine/docs/python/urlfetch/asynchronousrequests https://cloud.google.com/appengine/docs/python/urlfetch/asynchronousrequests

If you have requests that do various tasks you can see if they can be parallelized. 如果您有执行各种任务的请求,则可以查看它们是否可以并行化。

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

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