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

Assorted server optimizations #1717

Merged
merged 3 commits into from
Jul 22, 2023
Merged

Assorted server optimizations #1717

merged 3 commits into from
Jul 22, 2023

Conversation

ml-evs
Copy link
Member

@ml-evs ml-evs commented Jul 21, 2023

This PR adds three optimisations, arising from the (ongoing) talk about optimizing FastAPI/pydantic at EuroPython2023 by Marcelo Tryle.

  • Make sure uvloop and httptools are installed alongside uvicorn
  • Avoid validating data twice in both the get_entries function and the routes
  • Actually fix the validate_api_response option, now that I realise the FastAPI type hints were also validating...

Perf with mongomock:

Old version (current state of master):

$ ./wrk -t12 -c400 -d30s http://localhost:5000/v1/structures
Running 30s test @ http://localhost:5000/v1/structures
  12 threads and 400 connections
  Thread Stats   Avg      Stdev     Max   +/- Stdev
    Latency     0.00us    0.00us   0.00us    -nan%
    Req/Sec    10.73     15.34   121.00     91.48%
  368 requests in 30.08s, 14.28MB read
  Socket errors: connect 0, read 264, write 0, timeout 368
Requests/sec:     12.23
Transfer/sec:    486.22KB

New version with VALIDATE_API_RESPONSE=true:

$ ./wrk -t12 -c400 -d30s http://localhost:5000/v1/structures

Running 30s test @ http://localhost:5000/v1/structures
  12 threads and 400 connections
  Thread Stats   Avg      Stdev     Max   +/- Stdev
    Latency     0.00us    0.00us   0.00us    -nan%
    Req/Sec     9.88     12.00    80.00     90.49%
  701 requests in 30.10s, 27.22MB read
  Socket errors: connect 0, read 281, write 0, timeout 701
Requests/sec:     23.29
Transfer/sec:      0.90MB

New version with VALIDATE_API_RESPONSE=false:

$ ./wrk -t12 -c400 -d30s http://localhost:5000/v1/structures

Running 30s test @ http://localhost:5000/v1/structures
  12 threads and 400 connections
  Thread Stats   Avg      Stdev     Max   +/- Stdev
    Latency     0.00us    0.00us   0.00us    -nan%
    Req/Sec    10.14     11.96   171.00     91.84%
  1451 requests in 30.10s, 56.21MB read
  Socket errors: connect 0, read 113, write 0, timeout 1451
Requests/sec:     48.21
Transfer/sec:      1.87MB

@ml-evs ml-evs added the server Issues pertaining to the example server implementation label Jul 21, 2023
@codecov
Copy link

codecov bot commented Jul 21, 2023

Codecov Report

Merging #1717 (1a64f86) into master (a8e28e1) will decrease coverage by 0.07%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##           master    #1717      +/-   ##
==========================================
- Coverage   90.92%   90.86%   -0.07%     
==========================================
  Files          74       74              
  Lines        4608     4609       +1     
==========================================
- Hits         4190     4188       -2     
- Misses        418      421       +3     
Flag Coverage Δ
project 90.86% <100.00%> (-0.07%) ⬇️
validator 90.75% <100.00%> (-0.07%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
...made/server/entry_collections/entry_collections.py 95.83% <100.00%> (-0.05%) ⬇️
optimade/server/routers/links.py 100.00% <100.00%> (ø)
optimade/server/routers/references.py 100.00% <100.00%> (ø)
optimade/server/routers/structures.py 100.00% <100.00%> (ø)
optimade/server/routers/utils.py 95.12% <100.00%> (-0.82%) ⬇️

... and 1 file with indirect coverage changes

@ml-evs ml-evs force-pushed the ml-evs/optimisations branch 2 times, most recently from e62e108 to 6f047f7 Compare July 21, 2023 11:50
@ml-evs ml-evs force-pushed the ml-evs/optimisations branch 2 times, most recently from 1f25f51 to e81320a Compare July 21, 2023 13:46
@ml-evs ml-evs force-pushed the ml-evs/optimisations branch from e81320a to 1a64f86 Compare July 21, 2023 15:00
Copy link
Contributor

@JPBergsma JPBergsma left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for making these performance improvements.
To me, the changes you made look good.

@ml-evs ml-evs merged commit 2f37478 into master Jul 22, 2023
@ml-evs ml-evs deleted the ml-evs/optimisations branch July 22, 2023 09:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
server Issues pertaining to the example server implementation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants