Django 中的性能、负载和压力测试

Performance, load and stress testing in Django

我正在研究 Django 应用程序的不同类型的测试。我知道如何在 Django 中进行功能和单元测试以及如何应用不同的方法论,但现在我面临新的挑战,我需要知道如何做:

知道它们之间的区别但我不知道哪个是最好的方法,哪个是最好的包,或者我可以从哪里得到一些文档 关于它。

所以我的问题是,我如何开始在 Django 应用程序中进行这些类型的测试,或者我在哪里可以获得一些关于它的好文档?

谢谢

Load Testing and Stress Testing 基本上是性能测试 sub-types 其中:

  • 负载测试:将系统置于预期负载下,以查看响应时间或吞吐量等性能指标是否符合预期/SLAs
  • 压力测试:正在确定系统边界 and/or 瓶颈,即您开始“正常”负载测试并增加负载,直到监控的指标超过可接受的阈值或错误开始发生(无论先发生什么)

另外,请注意 Soak Testing - when you put the system under a prolonged load to see if it is capable of handling sustained concurrent usage. The majority of bottlenecks 在浸泡测试阶段被发现。


关于“我该怎么做”:

  1. 首先你需要一个性能测试工具。鉴于 pythondjango 标签,我的期望是你找到 Locust tool interesting as you will be able to write your tests in some form of Python language. You can also consider Grinder where you can write tests in Jython (Java bindings for Python) language so you won't have to learn the new tool from scratch. Other free and open source load testing tools are listed and compared in the Open Source Load Testing Tools: Which One Should You Use?

  2. 下一步将创建一个负载测试场景。您需要尽可能地模拟真实的应用程序使用情况,也就是说,您需要使用真实的浏览器正确模拟真实的用户以及所有相关的东西,例如:

    • cookies
    • headers
    • 缓存
    • 思考时间
    • AJAX 请求
    • 嵌入式资源处理(图像、脚本、样式、字体)
  3. 一旦您完成测试并确信它正在做它应该做的事情,您就可以 运行 它与更多的用户一起使用,看看您的应用程序如何在负载下表现,将 increasing/decreasing 负载与变化的 metrics/resources 用法相关联