Untitled
user_1673309
plain_text
2 years ago
2.2 kB
5
Indexable
#!/bin/bash # Calculate the delay (in microseconds) between each request to achieve approximately 500 TPS delay_microseconds=$((1000000 / 500)) # Set the duration of the script in seconds (30 minutes) duration=1800 # API endpoint api_endpoint="http://example.com/api" # Initialize variables for tracking TPS total_requests=0 # Get the start time start_time=$(date +%s) echo "Start time: $(date -u -d @$start_time +'%Y-%m-%d %H:%M:%S')" # Loop to send requests while true; do # Get the current time in seconds since the script started current_time=$(date +%s) # Check if the duration has passed if [ $((current_time - start_time)) -ge $duration ]; then break fi # Record the start time of the request in microseconds request_start_time=$(date +%s%N) # Send the request # Send the request curl --location --request POST 'https://test-cxs.globe.com.ph/v1/partners/ocsp/oauth2/token?grant_type=client_credentials' \ --header 'Authorization: Basic M2oxOXZhY2J2bzM2anFnZHNyY2ZkNnNpbTE6MWxmNjI1dXVzZjlrYm5uaGptMnVpbm1mc2E2ZnFuNGdlcDFuNW1lMzZvZTQ4bmpiOWg5Zw==' \ --header 'Content-Type: application/x-www-form-urlencoded' >/dev/null 2>&1 & # Record the end time of the request in microseconds request_end_time=$(date +%s%N) # Calculate the time taken for this request in microseconds request_time_microseconds=$((request_end_time - request_start_time)) # Calculate the delay needed to achieve the desired TPS remaining_delay=$((delay_microseconds - request_time_microseconds)) if [ $remaining_delay -gt 0 ]; then # Sleep for the remaining delay usleep $remaining_delay fi total_requests=$((total_requests + 1)) done # Calculate the achieved TPS achieved_tps=$(awk "BEGIN { printf \"%.2f\", $total_requests / $duration }") # Get the end time end_time=$(date +%s) echo "End time: $(date -u -d @$end_time +'%Y-%m-%d %H:%M:%S')" echo "Burst requests completed." echo "Total requests sent: $total_requests" echo "Total duration: $duration seconds" echo "Achieved TPS: $achieved_tps transactions per second"
Editor is loading...