Automating Distributed Performance Testing with a Bash Script: A Step-by-Step Guide
In the ever-evolving world of software development, ensuring the efficiency and reliability of applications under varying loads is critical. Performance testing plays a crucial role in this, helping teams measure system behavior under stress and identify potential bottlenecks before they affect users.
Automating performance testing through scripting, particularly using tools like Bash, offers several advantages. It enables repeatable, consistent test execution, saving time and reducing human error. This article delves into an automated performance testing approach using a Bash script.
Whether you're a seasoned QA engineer or someone new to performance testing, understanding and leveraging automation will help you optimize testing efficiency and provide deeper insights into system performance.
1. Creating the Header for the Output File:
echo "timeStamp,elapsed,label,responseCode,responseMessage,threadName,dataType,success,bytes,grpThreads,allThreads,Latency,SampleCount,ErrorCount" > result.jtl
2. Setting the Path to JMeter:
JMETER_PATH="/path to /bin/jmeter"
3. Defining Iterations and Batch Size:
iterations=2
batch_size=2
start_user=9840XXXXXX
4. Starting the Main Loop for Iterations:
for ((iteration=1; iteration<=iterations; iteration++)); do
5. Inner Loop for User Simulation:
for ((j=0; j<batch_size; j++)); do
6. Performing Login:
start_time=$(date +%s%3N) login_response=$(curl --location 'BASE_URL_LOGIN' \
token=$(echo $login_response | grep -o '"token":"[^"]*' | cut -d'"' -f4)
领英推荐
7. Logging the Login Result:
elapsed_time=$(($end_time - $start_time)) echo "$start_time,$elapsed_time,Login,$response_code,OK,Thread-$j,text,$success,$bytes,$batch_size,$batch_size,$latency,1,0" >> result.jtl
8. Booking Request:
book_response=$(curl --location 'FULL_URL' \
9. Logging the Booking Result:
echo "$start_time,$elapsed_time,Book,$response_code,OK,Thread-$j,text,$success,$bytes,$batch_size,$batch_size,$latency,1,0" >> result.jtl
10. Confirmation:
confirm_response=$(curl --location 'FULL_URL' \
11. Logging the Confirmation Result:
echo "$start_time,$elapsed_time,Confirm,$response_code,OK,Thread-$j,text,$success,$bytes,$batch_size,$batch_size,$latency,1,0" >> result.jtl
12. Generating the HTML Report:
$JMETER_PATH -g result.jtl -o /c/apache-jmeter-5.6.3/path to output folder
Check below image for full script from Login, booking to Confirmation:
Follow For More !! Thanks
Quality Assurance Engineer at EPAM Systems
6 个月Why do you need to use Bash if you're already using JMeter? Using JMeter's HTTP Request sampler (https://jmeter.apache.org/usermanual/component_reference.html#HTTP_Request) provides more control over how the test is being executed, you can configure JMeter to behave like a real browser (https://portal.perforce.com/s/article/How-to-make-JMeter-behave-more-like-a-real-browser-1707509382226) when it comes to downloading embedded resources, respecting Cache-Control headers, sending headers like User-Agent, performing authentication, recording protocol-based metrics like connect time and latency, using client-side certificates, etc.