Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
SamashaNayananthi opened this issue Dec 10, 2024 · 2 comments
Open

Comments

@SamashaNayananthi
Copy link

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!

@RobbeSneyders
Copy link
Member

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

@SamashaNayananthi
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants