Skip to content

7. Example

Joaquim Rocha edited this page Aug 8, 2020 · 1 revision

Problem

Suppose that you want to stress test the simple app on jjmrocha/load-testing-playground.

With the following OpenAPI Specification

Templates

First we create the templates (maybe by using beast template as described here)

For GET /apps/{app_id}

method: GET
endpoint: "http://127.0.0.1:8080/apps/{{ .Data.APP_ID }}"
headers:
    User-Agent: Beast/1

For PUT /apps/{app_id}

method: PUT
endpoint: "http://127.0.0.1:8080/apps/{{ .Data.APP_ID }}"
headers:
    User-Agent: Beast/1
    Content-Type: application/json
request-body: >
    {
       "app-id": {{ .Data.APP_ID }},
       "name": "{{ .Data.NAME }}"
    }

Data File

New we need to create a CSV file with test data, we must take attention to match the column names with our parameters (you can find more information here)

APP_ID,NAME
101,App 101
102,App 102
103,App 103
104,App 104
105,App 105
106,App 106
107,App 107
108,App 108
109,App 109
110,App 110
111,App 111
112,App 112
113,App 113
114,App 114
115,App 115
116,App 116
117,App 117
118,App 118
119,App 119
120,App 120

Testing

We can now use our templates to test the App, using the command beast run (detailed explanation can be found here)

Test PUT /apps/{app_id}

First we add data by invoking the endpoint PUT /apps/{app_id}

beast run -n 100 -data apps.csv apps_put.yaml
===== System =====
Operating System: darwin
System Architecture: amd64
Logical CPUs: 4
===== Test =====
Request template: apps_put.yaml
Sample Data: apps.csv
Number of requests: 100
Number of concurrent requests: 1
===== Preparing =====
- Loading data file
- Loading request template
- Generating requests
===== Executing =====
2020/06/01 00:23:52 [#...................] 5%
2020/06/01 00:23:52 [##..................] 10%
2020/06/01 00:23:52 [###.................] 15%
2020/06/01 00:23:52 [####................] 20%
2020/06/01 00:23:52 [#####...............] 25%
2020/06/01 00:23:52 [######..............] 30%
2020/06/01 00:23:52 [#######.............] 35%
2020/06/01 00:23:52 [########............] 40%
2020/06/01 00:23:52 [#########...........] 45%
2020/06/01 00:23:52 [##########..........] 50%
2020/06/01 00:23:52 [###########.........] 55%
2020/06/01 00:23:52 [############........] 60%
2020/06/01 00:23:52 [#############.......] 65%
2020/06/01 00:23:52 [##############......] 70%
2020/06/01 00:23:53 [###############.....] 75%
2020/06/01 00:23:53 [################....] 80%
2020/06/01 00:23:53 [#################...] 85%
2020/06/01 00:23:53 [##################..] 90%
2020/06/01 00:23:53 [###################.] 95%
2020/06/01 00:23:53 [####################] 100%
===== Stats =====
Executed requests: 100
Time taken to complete: 291.731259ms
Requests per second: 342.7812
Avg response time: 2.917312ms
===== Status 201 =====
20 requests, with avg response time of 3.309653ms
And the following distribution:
- The fastest request took 1.986986ms
- 20% of requests under 2.251492ms
- 40% of requests under 2.491213ms
- 60% of requests under 3.056758ms
- 80% of requests under 3.378098ms
- The slowest request took 9.560662ms
===== Status 200 =====
80 requests, with avg response time of 2.819227ms
And the following distribution:
- The fastest request took 2.08909ms
- 20% of requests under 2.304433ms
- 40% of requests under 2.581948ms
- 60% of requests under 2.751686ms
- 80% of requests under 3.09457ms
- The slowest request took 4.508564ms

Because our data file only contains 20 app-ids only 20 requests received the status 201 the remaining received 200.

Test GET /apps/{app_id}

We can now test the GET endpoint.

beast run -n 1000 -c 10 -data apps.csv apps_get.yaml
===== System =====
Operating System: darwin
System Architecture: amd64
Logical CPUs: 4
===== Test =====
Request template: apps_get.yaml
Sample Data: apps.csv
Number of requests: 1000
Number of concurrent requests: 10
===== Preparing =====
- Loading data file
- Loading request template
- Generating requests
===== Executing =====
2020/06/01 00:27:19 [#...................] 5%
2020/06/01 00:27:19 [##..................] 10%
2020/06/01 00:27:20 [###.................] 15%
2020/06/01 00:27:20 [####................] 20%
2020/06/01 00:27:20 [#####...............] 25%
2020/06/01 00:27:20 [######..............] 30%
2020/06/01 00:27:20 [#######.............] 35%
2020/06/01 00:27:20 [########............] 40%
2020/06/01 00:27:20 [#########...........] 45%
2020/06/01 00:27:20 [##########..........] 50%
2020/06/01 00:27:20 [###########.........] 55%
2020/06/01 00:27:20 [############........] 60%
2020/06/01 00:27:20 [#############.......] 65%
2020/06/01 00:27:21 [##############......] 70%
2020/06/01 00:27:21 [###############.....] 75%
2020/06/01 00:27:21 [################....] 80%
2020/06/01 00:27:21 [#################...] 85%
2020/06/01 00:27:21 [##################..] 90%
2020/06/01 00:27:21 [###################.] 95%
2020/06/01 00:27:21 [####################] 100%
===== Stats =====
Executed requests: 1000
Time taken to complete: 18.089105597s
Requests per second: 552.8189
Avg response time: 18.089105ms
===== Status 200 =====
1000 requests, with avg response time of 18.089105ms
And the following distribution:
- The fastest request took 12.401348ms
- 20% of requests under 14.993723ms
- 40% of requests under 15.72778ms
- 60% of requests under 16.65737ms
- 80% of requests under 18.194041ms
- The slowest request took 1.334541048s

Clone this wiki locally