-
-
Notifications
You must be signed in to change notification settings - Fork 771
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
Slowdown of cold start in connexion 3.0 #1801
Comments
Thanks for the report @ThomasSchwengler You mention
But the difference seems a lot smaller in your tests
Where do the top numbers come from?
Could you post some data from the profiler? |
@RobbeSneyders thanks for the fast reply, I updated the examples to run the tests multiple times to see the difference. |
Regarding the profiler data: |
Those are the timings Pycharm tells me, which probably don't include the pytest framework starting up. |
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 import time
from multiprocessing import Process
import requests
from connexion import App
from connexion.resolver import RestyResolver
def start_app():
app = App(__name__, specification_dir="spec")
app.add_api(
"openapi.yaml",
arguments={"title": "RestyResolver Example"},
resolver=RestyResolver("api"),
)
app.run(port=8080)
def wait_for_app():
while True:
try:
r = requests.get("http://localhost:8080/openapi/pets")
except Exception:
pass
else:
if r.status_code == 200:
break
if __name__ == '__main__':
p = Process(target=start_app)
start = time.time()
p.start()
wait_for_app()
print(time.time() - start)
p.kill() 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 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. |
@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 also, faced performance issues after the upgrade. Will share some profiling results tomorrow. |
I have same issue |
Thanks for the reports everyone, I just submitted a fix. Will release it as a |
It's awesome. Thank you very much. |
I'm glad to see this - can't wait for the release. Thank you very much. Currently working on an app with >300 API tests (with testclient), developing with TDD. The time for a full test run has become almost unbearable (>15min)... |
Same) |
Fixes #1801 I had to make quite a few additional changes to satisfy mypy.
So 3.0.3 now released. It looks much better now but still not ideal in comparison to Connexion2. |
Hi not a good solution, but tip for TDD people. I have same problems where my tests execution jumped too high 2x - 3x even. Ultimately I was able to make my final ASGI app stateless adding my own middleware to handle the initial state (using lifespan protocol). And that allowed me to create app just once for test session and reuse it for all tests. Cutting my test run time in half compared to connexion 2.x. It also forced my to much nicer solution for a server state than before. |
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
For connexion 3.x:
pytest tests/test_dummy.py 8,97s user 0,11s system 98% cpu 9,188 total
pytest tests/test_dummy.py 2,36s user 0,10s system 85% cpu 2,888 total
Additional info:
Output of the commands:
python --version
Python 3.9.18
pip show connexion | grep "^Version\:"
Version: 3.0.1
What I tried:
Looking at the profiler it seems like the yaml parsing now takes more time?
The text was updated successfully, but these errors were encountered: