From 98e453211bd62c9b403eadb24cf9ec76543afb66 Mon Sep 17 00:00:00 2001 From: Werner Date: Mon, 28 Aug 2023 17:27:38 +0200 Subject: [PATCH] feat: compress server response --- docker/requirements.txt | 1 + docker/src/app.py | 7 +++++++ 2 files changed, 8 insertions(+) diff --git a/docker/requirements.txt b/docker/requirements.txt index 2854e19..1aecf07 100644 --- a/docker/requirements.txt +++ b/docker/requirements.txt @@ -1,4 +1,5 @@ Flask==2.0.2 +flask-compress==1.13 joblib==1.1.0 numpy==1.25.2 pandas==1.3.5 diff --git a/docker/src/app.py b/docker/src/app.py index e2a0731..88b90fe 100644 --- a/docker/src/app.py +++ b/docker/src/app.py @@ -10,11 +10,18 @@ from flask import request from flask import jsonify as flask_jsonify from flask import Response +from flask_compress import Compress # import numpy as np # import numpy.random as rand app = flask.Flask(__name__) + +# compress all server responses with gzip, deflate or brotli +# for large responses this results in ±90% reduction (62.5MB -> 5.5MB) +# at a cost of ±15% response time (4.5s -> 5.2s) +Compress(app) + # !!! comment out for production !!! # app.config["DEBUG"] = True