基准django应用程序 [英] benchmarking django apps

查看:153
本文介绍了基准django应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有兴趣测试我的django应用程序的性能,走什么是获得逐行性能数据的最佳方法?

I'm interested in testing the performance of my django apps as I go, what is the best way to get line by line performance data?

注意:Googling这可以让许多人对django本身进行基准测试。我不是在寻找django的基准,我试图测试我写的django应用程序的性能:)

note: Googling this returns lots of people benchmarking django itself. I'm not looking for a benchmarks of django, I'm trying to test the performance of the django apps that I'm writing :)

谢谢!

编辑:通过逐行我只是指定个人功能,数据库调用等,以确定瓶颈在非常细微的层次上

edit: By "line by line" I just mean timing individual functions, db calls, etc to find out where the bottlenecks are on a very granular level

推荐答案

这有两层。我们有大部分的#1到位我们的测试。我们即将从#2开始。

There's two layers to this. We have most of #1 in place for our testing. We're about to start on #2.


  1. Django是孤立的。普通的Django单元测试在这里工作得很好。创建一些循环使用(少于6个)典型用例的测试。获取此信息,发帖等收集时间数据。这不是真正的网络性能,但它是一个易于使用的测试场景,您可以使用它进行调优。

  1. Django in isolation. The ordinary Django unit tests works well here. Create some tests that cycle through a few (less than 6) "typical" use cases. Get this, post that, etc. Collect timing data. This isn't real web performance, but it's an easy-to-work with test scenario that you can use for tuning.

您的整个网络堆栈。在这种情况下,您需要一个运行Squid,Apache,Django,MySQL的常规服务器。您需要第二台计算机通过urllib2执行客户端练习您的网站,执行少数(少于6个)典型用例。获取此信息,发帖等收集时间数据。这仍然不是真正的网络性能,因为它不是通过互联网,而是尽可能接近于没有一个非常精细的设置。

Your whole web stack. In this case, you need a regular server running Squid, Apache, Django, MySQL, whatever. You need a second computer(s) to act a client exercise your web site through urllib2, doing a few (less than 6) "typical" use cases. Get this, post that, etc. Collect timing data. This still isn't "real" web performance, because it isn't through the internet, but it's as close as you're going to get without a really elaborate setup.

请注意,#2(端到端)包含大量的缓存用于性能。如果您的客户端脚本正在做类似的工作,缓存将是非常有益的。如果您的客户端脚本每次都执行独特的事情,缓存就不太有用了。

Note that the #2 (end-to-end) includes a great deal of caching for performance. If your client scripts are doing similar work, caching will be really beneficial. if your client scripts do unique things each time, caching will be less beneficial.

最难的部分是确定典型工作负载是什么。这不是功能测试,所以工作量不一定包括所有内容。此外,您的客户端运行的并发会话越多,变得越慢。不要试图优化您的服务器,当您的测试客户是处理中最慢的部分。

The hardest part is determining what the "typical" workload is. This isn't functional testing, so the workload doesn't have to include everything. Also, the more concurrent sessions your client is running, the slower it becomes. Don't struggle trying to optimize your server when your test client is the slowest part of the processing.

编辑

如果逐行表示分析,那么您必须运行一个Python分析器。

If "line-by-line" means "profiling", well, you've got to get a Python profiler running.

https://docs.python.org/library /profile.html

请注意,Django ORM层中有大量缓存。所以运行一个视图功能六次以获得有意义的一组测量是不明智的。您必须运行典型操作集,然后在配置文件中找到热点。

Note that there's plenty of caching in the Django ORM layer. So running a view function a half-dozen times to get a meaningful set of measurements isn't sensible. You have to run a "typical" set of operations and then find hot-spots in the profile.

通常,您的应用程序易于优化 - 您不应该做得太多。你的观点功能应该很短,没有处理能力。您的表单和模型方法的功能类似,应该很短。

Generally, your application is easy to optimize -- you shouldn't be doing much. Your view functions should be short and have no processing to speak of. Your form and model method functions, similarly, should be very short.

这篇关于基准django应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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