Skip to content

Commit c002eda

Browse files
author
Manuel Schmid
committed
db-defaults und zum Teil Test-Skripts ergänzt
1 parent 8464eff commit c002eda

File tree

17 files changed

+141
-13
lines changed

17 files changed

+141
-13
lines changed

.gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
*.db
21
*.zip
2+
__pycache__/

Assignment5/manuel/Dockerfile

+5-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,11 @@ RUN gpg --no-default-keyring --keyring /usr/share/keyrings/k6-archive-keyring.gp
1010
RUN echo "deb [signed-by=/usr/share/keyrings/k6-archive-keyring.gpg] https://dl.k6.io/deb stable main" > /etc/apt/sources.list.d/k6.list
1111
RUN apt update && apt install -y k6
1212

13+
# Create tests folder and declare as volume
14+
RUN mkdir /tests
15+
VOLUME /tests
16+
1317
# Change into root folder and start console
14-
WORKDIR /root
18+
WORKDIR /tests
1519
ENTRYPOINT /bin/bash
1620

Assignment5/manuel/README.md

+30-11
Original file line numberDiff line numberDiff line change
@@ -28,37 +28,56 @@ In my project, I found the best open model tools to be **Gatling** and **k6**. T
2828

2929
```console
3030
docker build -t <NAME> .
31-
docker run -v "$(pwd):/root" -it --rm <NAME>
31+
docker run --network=host -v "$(pwd):/tests" -it --rm <NAME>
3232
```
3333
* The container opens a console, see the "Running the tests" section below for details how to run the tests
3434
* In theory, for k6, the k6 container provided by grafana (`docker pull grafana/k6`) can also be used but our container
3535
also contains the R environment for generating the plots
36-
* Note that this solution mounts this folder in the container so all results will be available locally too. However,
37-
they will all be owned by root. To own them after being done, simply use `chown -R <USER>:<GROUP> .`
36+
* Note that this solution mounts this folder in the container's "/tests" directory, so all results will be available locally too. However, they will all be owned by root. To own them after being done, simply use `chown -R <USER>:<GROUP> .`
37+
* The test scripts accept the host as an argument (k6's "-e" option), *localhost* won't work because that refers to the container's environment. However, using the `--network=host` option as shown above but this will only work on Linux.
38+
Alternatively use a manual setup or use the "host.docker.internal" address (see [here](https://stackoverflow.com/questions/24319662/from-inside-of-a-docker-container-how-do-i-connect-to-the-localhost-of-the-mach)). Even better is executing the load generator and the target on different machines and then use proper host names or IP adresses.
3839

3940
### Manual setup
4041

4142
* Install k6 as described [here](https://k6.io/docs/getting-started/installation/)
42-
* Note the "Troubleshooting" section below, sometimes there might be an error because of a missing directory which is not created by gpg by default
43+
* Note the "Troubleshooting" section below, sometimes there is an error because of a missing gpg directory which is not created by default
4344
4445
## Running the tests
4546

4647
We conducted our tests for our implementations of Assignment 3 and 4. (**TODO**: Maybe add impl 2 ?)
4748
First, we'll briefly describe the folder structure:
4849

49-
* The **impl** folder simply contains our solutions for Assignments 3 and 4. For Assignment 4, this is
50+
* The **impls** folder simply contains our solutions for Assignments 3 and 4. For Assignment 4, this is
5051
necessary, because we forgot to submit that one... (and for completeness, Assignment 3 is there as well).
51-
* The **test-scripts** folder contains the test scripts for our Assignment 3 and 4 Roary implementations.
52-
* The **raw-results** folder contains the *k6* metric logs for our test results
53-
* The **plots** folder contains an R script for generating plots from the raw results and the generated plots.
52+
* The **db-defaults** folder contains instructions and default database files for the tests.
53+
* The **scripts** folder contains test scripts and R scripts for plot generation.
54+
* The **results** folder contains raw *k6* CSV logs and the generated plots.
5455

55-
In order to run the tests for an implementation, first setup the implementation as specified in the *impl* folder.
56-
Then run the test as follows:
56+
In general, for both assignments we provide the following test parameters:
57+
58+
* **HOST**: Specifies the target host (e.g. "localhost:8080")
59+
* **MODE**: *count* (run a fixed number of requests), *duration* (run for a fixed number of time) and *rate* (run a fixed request rate). The former two follow a closed model and we only use the duration test in order to determine the maximum request rate the server can handle. The rate test follows an open model and ensures the specified request rate. This should be used for latency measurements due to the reasons explained above.
60+
* **SCENARIO**: *index*, *login*, *read*, *write* or *mixed*. *index* simply fetches the index page, *login* performs logins, *read* fetches 50 Roars from the server, *write* posts a Roar, and *mixed* combines *read* and *write* such that every tenth request is a write and all others are reads.
61+
* **DURATION**: The test duration in seconds (only for *rate* and *duration* modes)
62+
* **COUNT**: The number of requests (only for the *count* mode)
63+
* **RATE**: The request rate (only for *rate* mode)
64+
65+
All of these parameters are mandatory except if not used by a mode (e.g. *COUNT* being only used in *count* mode). These test parameters are passed using k6's `-e` flag, e.g. `-e MODE=count`. Apart from these test parameters, there are some additional k6 flags which we'll use. In general, an running a test is done something like this:
5766

5867
```console
59-
TODO
68+
k6 run \
69+
--out csv=./results/raw/Assignment<X>/<LOG_NAME>.csv \
70+
# --http-debug=headers oder --http-debug=full, optional for debug output
71+
-e HOST=<HOST> \
72+
-e MODE=<MODE> -e SCENARIO=<SCENARIO> \
73+
-e DURATION=<DUR> -e COUNT=<CNT> -e RATE=<RATE> \
74+
./scripts/tests/Assignment<X>.js
6075
```
6176

77+
Note, before running, the target should be reset into a comparable state. The easiest way to do this is by running the Roary implementations in a Docker container and resetting this container. Alternatively, with a manual setup, restarting the server process and resetting persistent data is also acceptable. For Roary, the only persistent data is database defaults which are provided in the *db-defaults* folder.
78+
79+
## Generating the plots
80+
6281
To generate the plots using the R script, do the following:
6382

6483
```console
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
File renamed without changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
// TODO: write test. Password for default database is always: "y9viuxq4uw"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
import http from 'k6/http';
2+
import exec from 'k6/execution';
3+
4+
////////////////////////////////////////////////////////////
5+
// Possible scenarios //
6+
////////////////////////////////////////////////////////////
7+
8+
const scenarios = {
9+
rate: {
10+
executor: "constant-arrival-rate",
11+
duration: parseInt(__ENV.DURATION) + "s",
12+
rate: parseInt(__ENV.RATE),
13+
timeUnit: "1s",
14+
preAllocatedVUs: 50,
15+
maxVUs: 500,
16+
exec: "index"
17+
},
18+
duration: {
19+
executor: "constant-vus",
20+
duration: parseInt(__ENV.DURATION) + "s",
21+
vus: parseInt(__ENV.VUS),
22+
exec: "index"
23+
},
24+
count: {
25+
executor: "shared-iterations",
26+
iterations: parseInt(__ENV.COUNT),
27+
vus: parseInt(__ENV.VUS),
28+
exec: "index"
29+
}
30+
}
31+
32+
////////////////////////////////////////////////////////////
33+
// Enabled scenarios //
34+
////////////////////////////////////////////////////////////
35+
36+
let scen = scenarios[__ENV.MODE];
37+
38+
if (scen === undefined)
39+
throw "Missing mode. Must be rate, duration or count";
40+
41+
scen.exec = __ENV.SCENARIO;
42+
43+
if (!["index", "login", "read", "write", "mixed"].includes(scen.exec))
44+
throw "Invalid Scenario. Must be index, login, read, write or mixed"
45+
46+
export const options = {
47+
scenarios: {
48+
test: scen
49+
}
50+
}
51+
52+
////////////////////////////////////////////////////////////
53+
// setup function //
54+
////////////////////////////////////////////////////////////
55+
56+
export function setup() {
57+
if (!["read", "write", "mixed"].includes(scen.exec))
58+
return;
59+
60+
const res = http.post(`http://${__ENV.HOST}/api/login`, {
61+
62+
password: "test"
63+
})
64+
65+
return res.cookies["connect.sid"][0].value
66+
}
67+
68+
////////////////////////////////////////////////////////////
69+
// actual scenario functions //
70+
////////////////////////////////////////////////////////////
71+
72+
export function index() {
73+
http.get(`http://${__ENV.HOST}`)
74+
}
75+
76+
export function login() {
77+
http.post(`http://${__ENV.HOST}/api/login`, {
78+
email: (exec.scenario.iterationInTest % 100) + "@b.c",
79+
password: "test"
80+
})
81+
}
82+
83+
export function read(cookie) {
84+
http.cookieJar().set(`http://${__ENV.HOST}`, "connect.sid", cookie)
85+
http.get(`http://${__ENV.HOST}/api/getRoars?upTo=0&limit=200`)
86+
}
87+
88+
export function write(cookie) {
89+
http.cookieJar().set(`http://${__ENV.HOST}`, "connect.sid", cookie)
90+
http.post(`http://${__ENV.HOST}/api/postRoar`,
91+
"Lorem ipsum dolor sit amet, consectetur adipiscing elit, [...]",
92+
{headers: {"Content-Type": "text/plain"}})
93+
}
94+
95+
export function mixed(cookie) {
96+
http.cookieJar().set(`http://${__ENV.HOST}`, "connect.sid", cookie)
97+
98+
if (exec.scenario.iterationInTest % 10 == 0)
99+
http.post(`http://${__ENV.HOST}/api/postRoar`,
100+
"Lorem ipsum dolor sit amet, consectetur adipiscing elit, [...]",
101+
{headers: {"Content-Type": "text/plain"}})
102+
else
103+
http.get(`http://${__ENV.HOST}/api/getRoars?upTo=0&limit=50`)
104+
}

Assignment5/manuel/test-scripts/Assignment4/test.js

Whitespace-only changes.

0 commit comments

Comments
 (0)