Reduce Flask-API downtime in IIS

  Kiến thức lập trình

I’m using waitress to serve a Flask Python API in IIS 10.0, with the purpose of serving endpoints for reverse image searching.

The initial part the script deals with importing a number of large files, such as sentence encoders and data indices with millions of entries. In total, around 7.5GB of auxiliary data is loaded.
This means that the initialization process usually takes around 45 to 60 seconds, after which the API is ready to be used. The structure of the app.py file is something like:

# Import packages
from flask import Flask, request, jsonify
from flask_restful import Api
from waitress import serve
# Keras, Tensorflow, etc...

# Start APP
app = Flask(__name__)

# Load resources
# Neural Networks, Sentence Encoders, Lookup Indices...

api = Api(app)

# Define endpoints
@app.route('/home', methods=['POST'])
def home():
    # Do something...

# ... Other endpoints

if __name__ = '__main__':
    serve(app)

I also have pinging service hitting the website with a blank request every minute, to ensure the API stays in a “warm” state (as suggested in this answer)

However, I am facing a problem in which IIS appears to be recycling the application pool at seemingly random intervals, making it so that the next request takes abnormally long to process, and often induce a timeout.

I am by no means an expert in setting up IIS, but my research thus far has lead me into trying:

  • IIS Application Initialization
  • Increasing timeout limits
  • Changing ApplicationPool settings to AlwaysRunning, removing idle time-out limits, and disabling all Recycling triggers. (In fact, I’m mostly compliant to this best practices guide)
  • Setting Preload Enabled to True in the site settings.

None of the previous steps lead to any tangible improvements. However, I have also noticed that periods of less activity tend to have less interruptions due to the API restarting. Ultimately, this finding leads me to believe the issue may be related to memory handling, but I am still unable to understand if this is the case or not.

What could I attempt tackling next to understand where the issue is coming from? Is there a way to monitor the timings and causes of restarts? Could this be a hardware limitation?

Theme wordpress giá rẻ Theme wordpress giá rẻ Thiết kế website

LEAVE A COMMENT