Python, flask application acting as proxy takes too long for a response

771 views Asked by At

I have been building up an app using Flask to act as a proxy and authentication layer to another service running on the same machine. My issue is that when making a REST call to the second service, response times vary between 15ms to 20ms. Howver, when the proxy is queries first, response times take > 1000ms which is an overkill in this case.

The proxy only does authentication using HTTPBasicAuth for a user table in SQLAlchemy and will instantly forward the call to an appropriate url exposing the second service. Here is an example below:

@device_blueprint.route('/devices/data', methods=['GET'])
@auth.login_required
def getAll():
    current_app.logger.info('Received request from ip [%s] with headers [%s]', request.remote_addr, request.
    r = requests.get("URL TO SECOND SERVICE")
    if not r:
        abort(400)

    return "%s" % r.json()

The application is running on gunicorn with 4 worker threads. Any ideas how the response time can be decreased?

0

There are 0 answers