应用引擎优化
如何让 Google AppEngine 应用程序的请求更好更快地执行(即更少的加载时间和更少的 CPU 使用率)?我特别指的是应用程序服务器端部分的改进,而不是客户端。
How can I get the requests of my Google AppEngine application to perform better and faster (i.e. less load times and less CPU usage)? I'm specifically referring to imporvements for the server-side portion of the app, and not the client-side.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
一个经常被忽视的方面是,各种 Appengine 相关服务都支持异步处理,例如数据存储区:
https ://cloud.google.com/appengine/docs/java/datastore/async
和网址提取:
https://cloud.google.com/appengine/docs/python/urlfetch/asynchronousrequests
如果您有执行各种任务的请求,您可以查看它们是否可以并行化。
One often overlooked aspect is that various Appengine related services support asynchronous processing, for example Datastore:
https://cloud.google.com/appengine/docs/java/datastore/async
and URL Fetch:
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.
使用 appengine Appstats 查看您的应用程序实际上在哪里使用了更多 cpu 资源。尝试找出原因并寻找替代解决方案。
在Python中你可以做很多优化。 M
利用memcache api,这使得
数据获取简单快捷。避免
不必要的 fetch() 和 get()。
避免在执行大量 RPC 时
使用 db.reference() 属性。
Nick 的博客对此进行了解释。
appengine 中的建模对于性能非常重要。确保您拥有为您的应用程序设计的正确模型。
除非您真正需要它们,否则请避免执行 get 和 fetch。
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.
In python you can do lot of optimisation. M
Make use of memcache api which makes
data fetch easy and fast. Avoid
unnecessary fetch() and get().
Avoid doing a lot of RPCs while
using db.reference() property.
Nick's blog on this explains about this.
Modeling in appengine matters a lot in performance. Make sure you have the right model designed for your application.
Avoid doing get and fetch unless until you really need them.
我建议使用 Appstats 来查看应用中的哪些位置瓶颈。
I'd recommend using Appstats to see where in your app there's bottlenecks.
这并不是真正的优化,但框架的选择在这里非常重要。 Java 和 Python 中的大多数遗留框架(Django,..)都不是为了快速启动而设计的,因为它在传统托管中并不重要。考虑使用 App Engine 特定框架,例如 Tipfy、Kai、Webapp ... (Python) 或 slim3, ... (Java)。
理想情况下,您应该组织数据,以便每个用户请求只需要对数据存储进行一次调用,最好是 db.get,因为查询速度要慢得多。为了实现这一点,您通常需要对数据进行非规范化,并使用实体组和事务来保持不同副本的同步。
当进行多个 urlfetch 或 API 调用时,您可以使用非阻塞(异步)语法并行进行调用,从而加快这一过程。尽可能缓存当然也非常重要。
如果您还没有看过,我建议您观看 Google 的 IO 演讲(2010 年和 2011 年),特别是今年的 扩展 App Engine 应用程序 在描述服务器端最佳实践方面做得非常好。
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. Consider using an App Engine specific framework like Tipfy, Kai, Webapp, ... (Python) or 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. 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. 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.
我使用 memcache,它显着提高了我的应用的性能。我希望它也能为你所用。当将 memcache 与设置缓存控制的 HTTP 标头结合使用时,我在响应时间上得到了显着的改进。
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.