Become a toast master!
There are three kinds of toast machines, each for a different kind of toast.
Plain | Chocolate | Strawberry | |
---|---|---|---|
Service Id | 1 | 2 | 3 |
Process time | 3s | 2.5s | 1s |
Note: Each kind of toast machine have different process time.
Main objective: Practice applying horizontal scaling and load balancing strategies.
Side effect: Become a toast master!
Test description: 50 requests in total, with 9 requests at the same time at most.
Each toast machine is limited to processing 3 toasts (requests) concurrently, if you go over this number, then the toast machine will burn out and produce failures.
For this part, you will be restricted to 1 replica of each kind of toast machine.
Please adjust the load balancing strategy through nginx.conf
in order to successfully process all of the toasts without failures.
Evenly dispatch to each server.
http {
upstream h1servers {
server plain:10000;
server chocolate:10000;
server strawberry:10000;
}
server {
listen 80 default_server;
listen [::]:80 default_server;
location /h1 {
proxy_pass http://h1servers;
}
}
}
e.g. for every 6(3+2+1) request, plain will get 3, chocolate will get 2, strawberry will get the last one.
http {
upstream h1servers {
server plain:10000 weight=3;
server chocolate:10000 weight=2;
server strawberry:10000 weight=1;
}
server {
listen 80 default_server;
listen [::]:80 default_server;
location /h1 {
proxy_pass http://h1servers;
}
}
}
Choose the server that currently holds least connections.
http {
upstream h1servers {
least_conn;
server plain:10000;
server chocolate:10000;
server strawberry:10000;
}
server {
listen 80 default_server;
listen [::]:80 default_server;
location /h1 {
proxy_pass http://h1servers;
}
}
}
Read more: https://nginx.org/en/docs/http/load_balancing.html
Test description: 50 requests in total, with 50 requests at the same time at most.
Process 50 toasts (requests) in the shortest amount of time with the least failure (failed requests).
You can adjust the load balancing strategy and number of replicas of each kind of toast machines freely.
Score formula: Time taken to process 50 toasts (requests) + number of failures (failed requests as penalty)
The lower the score, the better you are!
git clone https://github.com/candy02058912/toastmasters.git
Prerequisites: Docker should be installed
Usage
scripts/deploy_swarm.sh
Usage
scripts/scale_swarm.sh [-s <service id>] -r <number of replicas>
Example
# set service 1 to 1 replica and set service 2 to 2 replicas
srcipts/scale_swarm.sh -s 1 -r 1 -s 2 -r 2
# set all services to 3 replicas
scripts/scale_swarm.sh -r 3
Usage
# Test 1
scripts/run.sh -t 1
# Test 2
scripts/run.sh -t 2
# Test 1 & 2
scrupts/run.sh
Monitor the service:
docker stats
CONTAINER ID NAME CPU % MEM USAGE / LIMIT MEM % NET I/O BLOCK I/O PIDS
723109f3b483 demo_strawberry.1.yugi4i6j8g07j4ak09vq2uc2o 0.00% 1.16MiB / 5MiB 23.20% 1.78kB / 0B 0B / 0B 5
c3a277e1093c demo_plain.1.728f24hul2e0177auwfqp4rhk 0.00% 1.148MiB / 5MiB 22.97% 1.78kB / 0B 0B / 0B 6
379b48c1fe86 demo_chocolate.1.l3980tsvgqp8araf8c2y7f6tl 0.00% 1.145MiB / 5MiB 22.89% 1.78kB / 0B 0B / 0B 6
2c17680b2ab1 demo_nginx.1.iq8w5mabcum8yuitskt69y89w 0.00% 4.418MiB / 7.779GiB 0.06% 263kB / 335kB 0B / 0B 5
860ed21cbdb1 demo_tester.1.uf5u6822lowrtll2wry2hikmy 0.00% 296KiB / 7.779GiB 0.00% 2.07kB / 42B 0B / 0B 1
The metrics you should take a look:
Time taken for tests: 56.109 seconds
...
Non-2xx responses: 49
Edit src/nginx/nginx.conf
for adjusting load balancing strategies, please run scripts/deploy_swarm.sh
when the file is changed, documentation: https://nginx.org/en/docs/http/load_balancing.html
Files involved: nginx.conf
, scale.conf
-
Edit
nginx.conf
for your desired load balancing strategy -
Edit
scale.conf
with your desired number of replicas -
Open a Pull Request, documentation: https://docs.github.com/en/github/collaborating-with-issues-and-pull-requests/creating-a-pull-request
-
Once submission finished successfully, you will receive a comment in your PR
Low concurrency test:
Server Software: | nginx/1.17.8 | ||
---|---|---|---|
Server Hostname: | nginx | ||
Server Port: | 80 | ||
Document Path: | /h1 | ||
Document Length: | Variable | ||
Concurrency Level: | 9 | ||
Time taken for tests: | 26.097 seconds | ||
Complete requests: | 50 | ||
Failed requests: | 0 | ||
Non-2xx responses: | 34 | ||
Total transferred: | 13633 bytes | ||
HTML transferred: | 6081 bytes | ||
Requests per second: | 1.92 | ||
Transfer rate: | 0.51 kb/s received | ||
Connnection Times (ms) | |||
min | avg | max | |
Connect: | 0 | 0 | 2 |
Processing: | 0 | 2195 | 12633 |
Total: | 0 | 2195 | 12635 |
Server Software: | nginx/1.17.8 | ||
---|---|---|---|
Server Hostname: | nginx | ||
Server Port: | 80 | ||
Document Path: | /h1 | ||
Document Length: | Variable | ||
Concurrency Level: | 50 | ||
Time taken for tests: | 5.517 seconds | ||
Complete requests: | 50 | ||
Failed requests: | 0 | ||
Non-2xx responses: | 47 | ||
Total transferred: | 15108 bytes | ||
HTML transferred: | 7517 bytes | ||
Requests per second: | 9.06 | ||
Transfer rate: | 2.67 kb/s received | ||
Connnection Times (ms) | |||
min | avg | max | |
Connect: | 0 | 2 | 3 |
Processing: | 447 | 771 | 3011 |
Total: | 447 | 773 | 3014 |