Python script to simulate multiple concurrent requests to web application
I first created this script to heavy test the web application hosted in elastic beanstalk.
Why python? Just for fun :)
Let’s begin
First, define a main function for the python script
1 | import datetime |
Then create a function to perform http requests
1 | ... |
If you don’t understand why need the cookie, you can refer Session hijacking: facebook.com example.
Note that the above function http_test()
actually perform POST login, GET sales report, POST sales report
Now in your main
function, replace # http requests goes here
with http_test()
Make the python script executable
1 | chmod +x http_requests.py |
if you run this script, means 1 client with 20 (for loop) x 3 requests, which equals to 60 requests one after one.
What if want to make it 100 concurrent connections?
Simply create another shell script, let’s name it run.sh
1 | for i in {1..100} |
also make it executable
1 | chmod +x run.sh |
Then run it
1 | ./run.sh |
Now you can simulate 100 concurrent connections with each 60 requests.
You can download the scripts here:
References: