简体   繁体   English

使用Python中的curl对网站进行压力测试

[英]Stress test a website using curl in Python

I have a Flask application running on port 5000 that supports 7 different endpoints that support GET requests. 我有一个运行在端口5000上的Flask应用程序,该应用程序支持7个支持GET请求的不同端点。 So I can do a 所以我可以做一个

curl http://localhost:5000/get_species_interactions?q=tiger

And it returns a page after some computation. 经过一些计算,它返回一个页面。 There are 6 other such endpoints each with varying degrees of computation at the back end. 还有6个其他此类端点,每个端点在后端具有不同的计算程度。 It works fine with one user but I want to get metrics for how well it can perform under load. 它只能与一个用户一起使用,但是我想获取有关其在负载下的性能指标。 I am trying to stress test this by simulating a large number of requests and I was thinking of using a python script. 我试图通过模拟大量请求来进行压力测试,当时我正在考虑使用python脚本。 The rough algorithm I had in mind is the following: 我想到的粗略算法如下:

 while (num_tests < 1000):
   e = get_random_end_point_to_test() # pick one out of 7 end points
   d = get_random_data_for_get(e) # pick relevant random data to send in curl command
   resp = curl(e/q?d)
   num_tests++

My question is - is this general approach on the right track? 我的问题是-这种一般方法是否正确? Does it simulate a large number of simultaneous users? 它会模拟大量同时用户吗? I was planning to store the amount of time it took to execute each request and compute stats. 我打算存储执行每个请求和计算统计信息所花费的时间。 Otherwise is there a free utility I can use to do this kind of stress test on Mac OS? 否则,有没有免费的工具可以在Mac OS上进行这种压力测试? I saw a tool called siege but its not available on mac easily. 我看到了一个名为siege的工具,但在Mac上不容易使用。

I would suggest Apache jmeter. 我建议使用Apache jmeter。 The tool has everything you need for Stresstests and is good documented online. 该工具包含了Stresstests所需的一切,并且在线记录良好。

You'll need to install Java though 不过您需要安装Java

No, you need to parallelize your requests. 不,您需要并行处理请求。 The libcurl can do this using the multi interface. libcurl可以使用multi接口执行此操作。

Check this out. 看一下这个。 Pythonic interface to libcurl/pycurl . libcurl / pycurl的Pythonic接口

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

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