Python脚本负载测试网页

发布于 2024-10-01 22:51:00 字数 299 浏览 5 评论 0原文

我想对网页进行测试加载。我想在 python 中使用多线程来完成它。 第一个 POST 请求将登录用户(设置 cookie)。

然后我需要知道服务器可以容纳多少个用户同时执行相同的 POST 请求。 所以我正在考虑生成在循环中发出请求的线程。

我有几个问题: 1. CPU 是否可以同时运行 1000 - 1500 个请求?我的意思是它不会减慢系统速度从而不再可靠吗? 2. 带宽限制如何?为了使该测试可靠,渠道应该有多好?

托管测试站点的服务器是 Amazon EC2 脚本将从另一台服务器(亚马逊也是)运行。

谢谢!

I want to do a test load for a web page. I want to do it in python with multiple threads.
First POST request would login user (set cookies).

Then I need to know how many users doing the same POST request simultaneously can server take.
So I'm thinking about spawning threads in which requests would be made in loop.

I have a couple of questions:
1. Is it possible to run 1000 - 1500 requests at the same time CPU wise? I mean wouldn't it slow down the system so it's not reliable anymore?
2. What about the bandwidth limitations? How good the channel should be for this test to be reliable?

Server on which test site is hosted is Amazon EC2 script would be run from another server(Amazon too).

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

煞人兵器 2024-10-08 22:51:01

cPython 在运行多个线程时不会利用多核。这意味着,基本上,您将只有一个核心来执行测试工作。

有专门的工具可以做您想做的事。让我建议两个:

FunkLoad 是一个功能和负载 Web 测试器,用 Python 编写,其主要用例是:

  • Web 项目的功能测试,以及回归测试。
  • 性能测试:通过加载Web应用程序并监控
    它可以帮助您查明您的服务器的瓶颈,并提供详细的信息
    绩效评估报告。
  • 加载测试工具以暴露粗略测试中未出现的错误,
    例如容量测试或寿命测试。
  • 压力测试工具压垮Web应用程序资源并进行测试
    应用程序的可恢复性。
  • 通过编写任何 Web 重复任务的脚本来编写 Web 代理,例如检查是否
    一个网站还活着。

Tsung 是一个开源多协议分布式负载测试工具

Tsung的目的是模拟
用户为了测试可扩展性
和基于IP的性能
客户端/服务器应用程序。你可以
用它来进行负载和压力测试
您的服务器。许多协议都有
已经实施和测试,并且它
可以很容易地扩展。网络DAV、LDAP
并添加了 MySQL 支持
最近(实验性的)。

它可以分布在多个
客户端机器并且能够
模拟数十万
虚拟用户同时(甚至
如果你有足够的硬件的话数百万
...)。


如果您决定编写自己的工具,您可能需要使用 Python 的 多处理模块 因为它可以让您使用多个核心。您还应该看看Twisted,因为它可以让您轻松处理多个套接字,同时处理有限数量的线程。这比为每个套接字生成一个新线程要好得多。

您使用 Amazon EC2,因此我建议使用 Tsung。您可以租用十几台多核服务器几个小时,并使用 Tsung 运行一些非常重的负载测试。在这种配置中它可以很好地扩展。

至于带宽,通常不是问题,但这取决于应用程序。在执行负载测试时,您必须密切监视您的所有资源。

cPython does not take advantage from multiple cores when running multiple threads. It means, that basically, You will only have one core doing the testing job.

There are dedicated tools to do what You want to do. Let me suggest two:

FunkLoad is a functional and load web tester, written in Python, whose main use cases are:

  • Functional testing of web projects, and thus regression testing as well.
  • Performance testing: by loading the web application and monitoring
    your servers it helps you to pinpoint bottlenecks, giving a detailed
    report of performance measurement.
  • Load testing tool to expose bugs that do not surface in cursory testing,
    like volume testing or longevity testing.
  • Stress testing tool to overwhelm the web application resources and test
    the application recoverability.
  • Writing web agents by scripting any web repetitive task, like checking if
    a site is alive.

Tsung is an open-source multi-protocol distributed load testing tool

The purpose of Tsung is to simulate
users in order to test the scalability
and performance of IP based
client/server applications. You can
use it to do load and stress testing
of your servers. Many protocols have
been implemented and tested, and it
can be easily extended. WebDAV, LDAP
and MySQL support have been added
recently (experimental).

It can be distributed on several
client machines and is able to
simulate hundreds of thousands of
virtual users concurrently (or even
millions if you have enough hardware
...).


If You decide to write Your own tool, You will probably want to use Python's multiprocessing module as it would let You use multiple cores. You should also take a look on Twisted as it would let You easily handle multiple sockets while a limited number of threads. That would be much better than spawning a new thread for each socket.

You work with Amazon EC2, so I would recommend using Tsung. You can rent a dozen of multicore servers for a few hours and run some really heavy load tests with Tsung. It scales very well in this kind of configuration.

As for the bandwidth, it's usually not a problem, but it depends on the application. You will have to monitor all Your resources closely while performing a load test.

陌上芳菲 2024-10-08 22:51:01

变量太多。 同时 1000...不。在同一秒……可能。带宽很可能是瓶颈。这个问题最好通过实验来解决。

too many variables. 1000 at the same time... no. in the same second... possibly. bandwidth may well be the bottleneck. this is something best solved by experimentation.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文