Skip to content

Commit 9c7cefc

Browse files
authored
Merge pull request #25 from phenixblue/gunicorn-testing
Move to Gunicorn WSGI Server
2 parents e0b7f24 + 14edadb commit 9c7cefc

File tree

9 files changed

+131
-40
lines changed

9 files changed

+131
-40
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,6 @@ This release contains several package updates geared towards fixing security rel
1818

1919
The updated pyyaml package required updates to the Kubernetes Python client library, moving primary support to Kubernetes 1.15+. Backwards compatibility to Kubernetes 1.13 should exist, but isn't tested/gauranteed.
2020

21+
## 2.1.3
22+
23+
This release migrates to using the Gunicorn WSGI HTTP Server instead of the default Flask server. This change reduces average latency by about 75% in our normal benchmarking tests. THis change also means the standar 3 replica deployment can handle almost 3 times the request rate as before.

Makefile

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
# its contributors may be used to endorse or promote products derived from this
1717
# software without specific prior written permission.
1818

19-
MAGTAPE_VERSION := v2.1.2
19+
MAGTAPE_VERSION := v2.1.3
2020
OPA_VERSION := 0.19.2
2121
KUBE_MGMT_VERSION := 0.11
2222

@@ -81,6 +81,12 @@ uninstall:
8181
kubectl delete validatingwebhookconfiguration magtape-webhook
8282
kubectl delete csr magtape-svc.magtape-system.cert-request
8383

84+
# Restart Magtape Pods (Demo Install)
85+
.PHONY: restart
86+
restart:
87+
88+
kubectl rollout restart deploy magtape -n magtape-system
89+
8490
# Cleanup MagTape (Demo Install)
8591
.PHONY: clean
8692
clean: uninstall
@@ -135,7 +141,7 @@ test-clean:
135141

136142
# Run all unit and functional tests for MagTape/MagTape-Init
137143
.PHONY: test-all
138-
test-all: test test-functional-deployments
144+
test-all: test test-functional
139145

140146
###############################################################################
141147
# Misc Repo Targets ###########################################################

app/magtape/Dockerfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ RUN pip install pipenv
1313
RUN pipenv install --system --deploy
1414

1515
COPY ./magtape.py /app/
16+
COPY ./config.py /app/
1617

17-
CMD ["python", "magtape.py"]
18+
CMD ["gunicorn", "magtape:app", "--config=config.py"]
1819

app/magtape/Pipfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ flask = "*"
1010
kubernetes = "~=11.0"
1111
prometheus-client = "*"
1212
prometheus-flask-exporter = "*"
13+
gunicorn = "*"
14+
werkzeug = "*"
1315

1416
[requires]
1517
python_version = "3.8"

app/magtape/Pipfile.lock

Lines changed: 75 additions & 29 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/magtape/config.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Copyright 2020 T-Mobile, USA, Inc.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
#
15+
# Trademark Disclaimer: Neither the name of T-Mobile, USA, Inc. nor the names of
16+
# its contributors may be used to endorse or promote products derived from this
17+
# software without specific prior written permission.
18+
19+
from os import environ as env
20+
import multiprocessing
21+
22+
APP_PORT = int(env.get("APP_PORT", 5000))
23+
APP_DEBUG = int(env.get("APP_DEBUG", 1))
24+
magtape_tls_path = "/tls"
25+
26+
# Gunicorn config
27+
bind = ":" + str(APP_PORT)
28+
workers = multiprocessing.cpu_count() * 2 + 1
29+
threads = 2 * multiprocessing.cpu_count()
30+
certfile = magtape_tls_path + "/cert.pem"
31+
keyfile = magtape_tls_path + "/key.pem"

app/magtape/magtape.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@
5353
cluster = os.environ["MAGTAPE_CLUSTER_NAME"]
5454
magtape_namespace_name = os.environ["MAGTAPE_NAMESPACE_NAME"]
5555
magtape_pod_name = os.environ["MAGTAPE_POD_NAME"]
56-
magtape_tls_path = "/tls"
5756

5857
# Set Slack related variables
5958
slack_enabled = os.environ["MAGTAPE_SLACK_ENABLED"]
@@ -716,7 +715,10 @@ def main():
716715
port=5000,
717716
debug=False,
718717
threaded=True,
719-
ssl_context=(f"{magtape_tls_path}/cert.pem", f"{magtape_tls_path}/key.pem"),
718+
ssl_context=(
719+
f"{config.magtape_tls_path}/cert.pem",
720+
f"{config.magtape_tls_path}/key.pem",
721+
),
720722
)
721723

722724

deploy/install.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ spec:
315315
serviceAccountName: magtape-sa
316316
initContainers:
317317
- name: magtape-init
318-
image: tmobile/magtape-init:v2.1.2
318+
image: tmobile/magtape-init:v2.1.3
319319
command: [/app/magtape-init.py]
320320
imagePullPolicy: Always
321321
env:
@@ -337,10 +337,10 @@ spec:
337337
mountPath: /vwc
338338
containers:
339339
- name: magtape
340-
image: tmobile/magtape:v2.1.2
340+
image: tmobile/magtape:v2.1.3
341341
ports:
342342
- containerPort: 5000
343-
command: [/app/magtape.py]
343+
command: ["gunicorn", "magtape:app", "--config=config.py"]
344344
imagePullPolicy: Always
345345
livenessProbe:
346346
httpGet:

deploy/manifests/magtape-deploy.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ spec:
1818
serviceAccountName: magtape-sa
1919
initContainers:
2020
- name: magtape-init
21-
image: tmobile/magtape-init:v2.1.2
21+
image: tmobile/magtape-init:v2.1.3
2222
command: [/app/magtape-init.py]
2323
imagePullPolicy: Always
2424
env:
@@ -40,10 +40,10 @@ spec:
4040
mountPath: /vwc
4141
containers:
4242
- name: magtape
43-
image: tmobile/magtape:v2.1.2
43+
image: tmobile/magtape:v2.1.3
4444
ports:
4545
- containerPort: 5000
46-
command: [/app/magtape.py]
46+
command: ["gunicorn", "magtape:app", "--config=config.py"]
4747
imagePullPolicy: Always
4848
livenessProbe:
4949
httpGet:

0 commit comments

Comments
 (0)