connexion: Slowdown of cold start in connexion 3.0
Description
When switching to connexion 3.0 we noticed a considerable slowdown at startup. Startup with connexion 3.x: 700ms-1s Startup with connexion 2.x: 1ms-10ms
Expected behaviour
No slowdown at startup compared to connexion 2.x
Actual behaviour
Slowdown at startup.
Steps to reproduce
- Have a medium sized OpenApi specification in yaml format (700 lines)
- Have a simple app created with a factory method:
# openapi_server/factory.py from connexion import App def create_app() -> App: connexion_app = App(__name__, specification_dir="./openapi/") connexion_app.add_api("openapi.yaml") return connexion_app - Use pytest and have a simple dummy unit test:
For connexion 3.x:
For connexion 2.x:# tests/test_dummy.py import pytest from openapi_server.factory import create_app @pytest.fixture() def app(): return create_app().test_client() @pytest.mark.parametrize("arg", range(10)) def test_startup(app, arg): app.get("/")# tests/test_dummy.py import pytest import webtest from openapi_server.factory import create_app @pytest.fixture() def app(): return webtest.TestApp(create_app()) @pytest.mark.parametrize("arg", range(10)) def test_startup(app, arg): app.get("/") - Timings:
- connexion 3.x:
pytest tests/test_dummy.py 8,97s user 0,11s system 98% cpu 9,188 total - connexion 2.x:
pytest tests/test_dummy.py 2,36s user 0,10s system 85% cpu 2,888 total
- connexion 3.x:
Additional info:
Output of the commands:
python --versionPython 3.9.18pip show connexion | grep "^Version\:"Version: 3.0.1
What I tried:
- Use AsyncApp (no speedup)
- Use different backends for starlette (no speedup)
- Use a different python version (some speedup)
Looking at the profiler it seems like the yaml parsing now takes more time?
About this issue
- Original URL
- State: closed
- Created 8 months ago
- Comments: 15 (3 by maintainers)
Commits related to this issue
- Only instantiate specification once (#1819) Fixes #1801 I had to make quite a few additional changes to satisfy mypy. — committed to spec-first/connexion by RobbeSneyders 7 months ago
Here is an output from the profiler for the same file with tests.
Python 3.10.7 Connexion[flask, uvicorn]==3.0.1 Flask==3.0.0

Python 3.10.7 Connexion==2.14.1 Flask==2.2.5

I also, faced performance issues after the upgrade. Will share some profiling results tomorrow. But what I can see is that my laptop is getting hot with Connexion 3 when I run tests. Tests execution time increased dramatically.
Thanks for the reports everyone, I just submitted a fix. Will release it as a
3.0.3once it’s merged.I have same issue
@RobbeSneyders thank you very much for looking into this, I will try to investigate myself in the meantime 😃
Regarding response time I also didn’t notice any slowdown.
I’m indeed able to reproduce a longer startup time in Connexion 3 compared to Connexion 2 using the following script. You can add it to the
restyresolverexample and install the connexion version you want to test.Parsing the specification and passing it to the application has a bigger impact on Connexion 3 than Connexion 2, but can’t completely explain the slowdown. I’ll have a deeper look when I find the time. I can’t really make sense of the v3 pstat file, since almost all time is spent on
thread.lockand there’s a lot of pytest stuff in there.FYI, we did test the response time of Connexion 3 vs Connexion 2 before the release and didn’t notice any meaningful difference between the two.