connexion icon indicating copy to clipboard operation
connexion copied to clipboard

High CPU Spike During Deployment After Upgrading to Connexion 3.x

Open SamashaNayananthi opened this issue 1 year ago • 3 comments

Description

After upgrading Connexion to version 3.x, we are encountering significant CPU spikes during deployments. The spikes normalize shortly after deployment but consume approximately 10x more CPU compared to our previous version. This occurs consistently across multiple deployment attempts, as illustrated in the attached image. image-20241204-120935

Expected behaviour

The deployment should proceed with minimal CPU usage, similar to previous Connexion versions.

Actual behaviour

CPU usage spikes drastically during deployment. CPU consumption returns to normal shortly after deployment is complete. The spikes occur during every deployment attempt.

Additional info:

Environment Details In the following snippet we can see the updated libraries image

And in below I have added the current app configurations

app setup

def setup_application() -> tuple['Flask', 'App', 'SQLAlchemy']:
    # Create the application instance
    swagger_ui_options = SwaggerUIOptions(swagger_ui=config.ENABLE_SWAGGER_UI)

    _connexion_app = connexion.App(__name__, specification_dir='./', swagger_ui_options=swagger_ui_options)
    _application = _connexion_app.app

    _connexion_app.add_middleware(
        CORSMiddleware,
        position=MiddlewarePosition.BEFORE_ROUTING,
        allow_origins=config.CORS_ALLOWED_ORIGINS,
        allow_credentials=True,
        allow_methods=['*'],
        allow_headers=['*'],
    )

    _application.config.from_object(config)
    _application.config['SQLALCHEMY_DATABASE_URI'] = config.APPLICATION_DATABASE_URI
    _application.static_folder = '../dist'
    _application.template_folder = '../dist'
    _application.static_url_path = 'static'

    _db = SQLAlchemy(
        _application,
        model_class=declarative_base(cls=BaseModel, metaclass=NoNameMeta, name='Model'),
        engine_options=config.SQLALCHEMY_ENGINE_OPTIONS,
    )

    return _application, _connexion_app, _db


def setup_interfaces(connexion_flask_app: 'FlaskApp') -> None:
    connexion_flask_app.app.url_map.strict_slashes = False
    swagger_ui_options = SwaggerUIOptions(swagger_ui=True)

    # Read the swagger.yml file to configure the endpoints
   .
   .

from .interface import type_checking 

application, connexion_app, db = setup_application()

log = setup_logging()
setup_rollbar(application=application)

setup_interfaces(connexion_flask_app=connexion_app)

main function

if __name__ == '__main__':
        uvicorn.run('middleware:connexion_app', host='0.0.0.0', port=5003)

docker configs

proc_name = 'connexion_app'
workers = 4
worker_class = 'uvicorn.workers.UvicornWorker'
bind = '0.0.0.0:5000'
timeout = 240
debug = False
loglevel = 'debug'
errorlog = '-'
accesslog = '-'

And running the docker using the gunicorn gunicorn -c gunicorn-config-docker.py middleware:connexion_app

Given the above information we appreciate any insights or guidance on resolving this issue. Thank you!

SamashaNayananthi avatar Dec 10 '24 11:12 SamashaNayananthi

Hi @SamashaNayananthi, are you using particularly large OpenAPI specifications?

RobbeSneyders avatar Dec 23 '24 12:12 RobbeSneyders

Hi @RobbeSneyders, no we don't use large OpenAPI specifications.

SamashaNayananthi avatar Jan 01 '25 07:01 SamashaNayananthi

Hi @RobbeSneyders do you have any updates or inputs here ? We have around 140 endpoints in total in our OpenAPI specifications. I believe this is comparatively a small OpenAPI spec, and I don't think this has an impact on the CPU spikes

SamashaNayananthi avatar Apr 21 '25 09:04 SamashaNayananthi