Siege

Siege Basics

Siege is a tool that is used to make requests to a site. It is commonly used for load testing

Advanced Usage

Siege can use a file with URLs in it to test.

This can read basic variables and carry out POST requests. I have not found a way of getting dynamic araibles varaibles to be read, so I put together the following script to generate them

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/usr/bin/env bash
readonly DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )";
cd $DIR;
set -e
set -u
set -o pipefail
standardIFS="$IFS"
IFS=$'\n\t'
echo "
===========================================
$(hostname) $0 $@
===========================================
"

# The number of requests to make this can be changed by passing in a number as an agrument to the script
numberToTest=${1:-10}
# The base URL for the instance to test
baseUrl=http://www.example.com
# request path to test
requestPath=/rest/default/my/custom/api
# The product ID we are going to buy - make sure this exists and has plenty of stock before starting
productId=306
# The type of order id that is being used, either int64 or uuid
orderType=uuid
# The urls file we are going to write
siegeFile=/tmp/urls.txt
counter=0;

# These are variables that will be used in every request
echo "
BASE_URL=${baseUrl}
REQUEST_PATH=${requestPath}
PRODUCT_ID=${productId}
" > ${siegeFile}

echo "
Generating urls.txt file
"

while [ ${numberToTest} -gt ${counter} ]
do
    # These are the per request variables that we are going to use
    counter=$((counter+1));
    customerId=`uuidgen`
    if [[ ${orderType} == 'int64' ]]
    then
        orderId=`shuf -i 1-100000 -n 1`
    else
        orderId=`uuidgen | tr -d -`
    fi
    echo "
EMAIL_${counter}=customer${counter}@example.com
ID_${counter}=${customerId}
ORDER_ID_${counter}=${orderId}
\${BASE_URL}\${REQUEST_PATH} POST {\"order_id\":\"\${ORDER_ID_${counter}}\",\"phone_number\":\"0123456789\",\"partner_id\":12,\"products\":[{\"qty\":2,\"id\":\"\${PRODUCT_ID}\",\"configurable_options\":[],\"custom_options\":[]}],\"customer_details\":{\"email_address\":\"\${EMAIL_${counter}}\",\"customer_identifier\":\"\${ID_${counter}}\",\"first_name\":\"John\",\"last_name\":\"Smith\"}}
" >> ${siegeFile}
done

echo "
Done:

Running siege

siege -c ${numberToTest} -r1 -v -f ${siegeFile} --content-type \"application/json\"
"
siege -c ${numberToTest} -r1 -v -f ${siegeFile} --content-type "application/json"
echo "
----------------
$(hostname) $0 completed
----------------
"