Skip to content

Commit 4f6195f

Browse files
committed
Experiment with load shedding.
1 parent 37629b6 commit 4f6195f

File tree

4 files changed

+20
-1
lines changed

4 files changed

+20
-1
lines changed

docker-compose.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ services:
88
- gunicorn
99
ports:
1010
- "8080:8000"
11+
environment:
12+
- LOG=/var/log/nginx/access.log
1113

1214
gunicorn:
1315
build: sampleapp

run.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,9 @@ http {
129129
$BIND
130130
$HEADERS
131131
132+
proxy_connect_timeout 5s;
133+
# proxy_send_timeout 5s;
134+
132135
location / {
133136
proxy_pass http://app_upstream;
134137
proxy_redirect off;

sampleapp/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ FROM python:3.8-slim
33
RUN pip install gunicorn==20.0.4
44
COPY app.py .
55

6-
CMD ["gunicorn", "--bind", "0.0.0.0:8000", "app:application"]
6+
CMD ["gunicorn", "--bind", "0.0.0.0:8000", "--backlog", "0", "app:application"]

sampleapp/app.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,19 @@
1+
from time import sleep
2+
13

24
def application(environ, start_response):
5+
path = environ['PATH_INFO'].strip('/')
6+
if path == 'healthcheck':
7+
status = '200 OK'
8+
headers = [('Content-type', 'text/plain')]
9+
start_response(status, headers)
10+
return [b"OK\n"]
11+
elif path:
12+
try:
13+
sleep_time = float(path)
14+
except ValueError:
15+
raise ValueError('Path must be an integer or float.')
16+
sleep(sleep_time)
317
status = '200 OK'
418
headers = [('Content-type', 'text/plain')]
519
start_response(status, headers)

0 commit comments

Comments
 (0)