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

⚡️(api) cache logged-in user database request #296

Merged
merged 2 commits into from
Dec 16, 2024
Merged

Conversation

jmaupetit
Copy link
Member

Purpose

Getting request user from database is the most frequent request as it's accessed by every API endpoint. It can be optimize.

Proposal

  • cache logged user object for a limited time

@jmaupetit jmaupetit self-assigned this Dec 16, 2024
@jmaupetit jmaupetit added critical improvement API Item related to the API service labels Dec 16, 2024
src/api/qualicharge/db.py Outdated Show resolved Hide resolved
Copy link

Current benchmark

Type Name Request Count Failure Count Median Response Time Average Response Time Min Response Time Max Response Time Average Content Size Requests/s Failures/s 50% 66% 75% 80% 90% 95% 98% 99% 99.9% 99.99% 100% git timestamp version
GET /auth/whoami 34 0 560.0 601.4275499117666 8.186683000019457 1152.502233000007 160.0 1.1730410747171591 0.0 620 700 840 880 1100 1100 1200 1200 1200 1200 1200 4822aa8 2024-12-16 11:31:21.860494+00:00 0.16.0
POST /dynamique/session/ 35 0 870.0 890.8610270000005 105.2129440000158 1874.1443040000263 45.0 1.2075422827970757 0.0 870 1100 1200 1300 1500 1800 1900 1900 1900 1900 1900 4822aa8 2024-12-16 11:31:21.860494+00:00 0.16.0
POST /dynamique/session/bulk 28 0 610.0 771.6839528214315 26.523166999993464 2184.8539150000192 411.0 0.9660338262376604 0.0 670 990 1200 1300 1400 1800 2200 2200 2200 2200 2200 4822aa8 2024-12-16 11:31:21.860494+00:00 0.16.0
GET /dynamique/status/ 21 0 720.0 825.1694335714293 19.766468999989684 2308.755553000026 285.0 0.7245253696782453 0.0 720 980 1100 1200 1600 2100 2300 2300 2300 2300 2300 4822aa8 2024-12-16 11:31:21.860494+00:00 0.16.0
POST /dynamique/status/ 33 0 850.0 827.2987455757554 29.00862899997492 1562.0095419999984 45.0 1.1385398666372426 0.0 850 1100 1200 1200 1400 1600 1600 1600 1600 1600 1600 4822aa8 2024-12-16 11:31:21.860494+00:00 0.16.0
GET /dynamique/status/FRALLEGO002006P3 26 0 830.0 835.229561615377 21.22476199997436 1825.0457729999996 283.0 0.8970314100778276 0.0 840 1100 1400 1400 1500 1600 1800 1800 1800 1800 1800 4822aa8 2024-12-16 11:31:21.860494+00:00 0.16.0
GET /dynamique/status/FRALLEGO002006P3/history 20 0 1000.0 856.9053845500008 39.01000399997656 1477.5282239999683 49757.8 0.6900241615983289 0.0 1100 1200 1200 1300 1500 1500 1500 1500 1500 1500 1500 4822aa8 2024-12-16 11:31:21.860494+00:00 0.16.0
POST /dynamique/status/bulk 38 0 1100.0 1024.5189008421062 21.648051999989093 2312.941692000038 411.0 1.311045907036825 0.0 1100 1200 1300 1400 1900 2200 2300 2300 2300 2300 2300 4822aa8 2024-12-16 11:31:21.860494+00:00 0.16.0
POST /statique/ 23 14 860.0 780.2324382173933 34.98960600001055 1476.058254000009 55.17391304347826 0.7935277858380783 0.4830169131188302 860 920 960 1000 1200 1500 1500 1500 1500 1500 1500 4822aa8 2024-12-16 11:31:21.860494+00:00 0.16.0
GET /statique/?limit=10 31 0 920.0 868.7096352580633 16.02251700001034 1921.810905999962 13826.774193548386 1.0695374504774098 0.0 920 1100 1200 1200 1600 1800 1900 1900 1900 1900 1900 4822aa8 2024-12-16 11:31:21.860494+00:00 0.16.0
GET /statique/?limit=100 32 0 1000.0 1004.3360073125032 143.65192300004992 2170.608571999992 129006.65625 1.1040386585573263 0.0 1000 1400 1400 1500 1600 2100 2200 2200 2200 2200 2200 4822aa8 2024-12-16 11:31:21.860494+00:00 0.16.0
PUT /statique/FR073EP7QU5233 35 0 840.0 767.2043174857175 26.413961999992356 1830.475726999964 1371.0 1.2075422827970757 0.0 840 1000 1100 1200 1400 1600 1800 1800 1800 1800 1800 4822aa8 2024-12-16 11:31:21.860494+00:00 0.16.0
GET /statique/FRALLEGO002006P3 39 0 690.0 753.4405097948749 34.06124099996077 1825.59157999998 1202.0 1.3455471151167413 0.0 690 1000 1300 1300 1400 1700 1800 1800 1800 1800 1800 4822aa8 2024-12-16 11:31:21.860494+00:00 0.16.0
POST /statique/bulk 28 0 920.0 1045.728950071419 381.57072000001335 2992.1345230000043 1105.321428571429 0.9660338262376604 0.0 930 1200 1200 1300 1500 1800 3000 3000 3000 3000 3000 4822aa8 2024-12-16 11:31:21.860494+00:00 0.16.0
Aggregated 423 14 860.0 846.7656575815608 8.186683000019457 2992.1345230000043 13541.486997635931 14.594011017804656 0.4830169131188302 860 1100 1200 1200 1500 1700 2100 2200 3000 3000 3000 4822aa8 2024-12-16 11:31:21.860494+00:00 0.16.0

Comparison with the latest previous benchmark

A lower (negative) value means the current version performs better than the previous one.

Type Name Request Count Failure Count Median Response Time Average Response Time Min Response Time Max Response Time Average Content Size Requests/s
GET /auth/whoami
POST /dynamique/session/
POST /dynamique/session/bulk
GET /dynamique/status/
POST /dynamique/status/
GET /dynamique/status/FRALLEGO002006P3
GET /dynamique/status/FRALLEGO002006P3/history
POST /dynamique/status/bulk
POST /statique/
GET /statique/?limit=10
GET /statique/?limit=100
PUT /statique/FR073EP7QU5233
GET /statique/FRALLEGO002006P3
POST /statique/bulk
Aggregated

@jmaupetit jmaupetit marked this pull request as ready for review December 16, 2024 11:34
@jmaupetit jmaupetit requested a review from ssorin December 16, 2024 11:34
Copy link

Current benchmark

Type Name Request Count Failure Count Median Response Time Average Response Time Min Response Time Max Response Time Average Content Size Requests/s Failures/s 50% 66% 75% 80% 90% 95% 98% 99% 99.9% 99.99% 100% git timestamp version
GET /auth/whoami 44 0 310.0 390.3500919545425 2.434585999992578 1391.4149679999923 160.0 1.5087968796650586 0.0 310 460 690 750 800 1100 1400 1400 1400 1400 1400 d931cdf 2024-12-16 11:36:42.738183+00:00 0.16.0
POST /dynamique/session/ 42 0 840.0 746.5208703095217 9.595450000006169 1606.58423000001 45.0 1.4402152033166469 0.0 840 920 990 1100 1300 1500 1600 1600 1600 1600 1600 d931cdf 2024-12-16 11:36:42.738183+00:00 0.16.0
POST /dynamique/session/bulk 53 0 780.0 744.0212969622563 28.26976199997944 2077.9987870000127 411.0 1.8174144232329117 0.0 780 890 1000 1200 1400 1700 1800 2100 2100 2100 2100 d931cdf 2024-12-16 11:36:42.738183+00:00 0.16.0
GET /dynamique/status/ 30 0 540.0 635.5288262999959 11.869756000010057 1339.975786000025 285.0 1.0287251452261763 0.0 650 870 1000 1200 1300 1300 1300 1300 1300 1300 1300 d931cdf 2024-12-16 11:36:42.738183+00:00 0.16.0
POST /dynamique/status/ 42 0 570.0 655.4356821666652 10.975799999982884 2057.014912 45.0 1.4402152033166469 0.0 580 850 1100 1300 1300 1500 2100 2100 2100 2100 2100 d931cdf 2024-12-16 11:36:42.738183+00:00 0.16.0
GET /dynamique/status/FRALLEGO002006P3 47 0 730.0 654.261064489363 12.469194999994215 1861.8152859999668 269.3404255319149 1.611669394187676 0.0 730 870 930 970 1200 1500 1900 1900 1900 1900 1900 d931cdf 2024-12-16 11:36:42.738183+00:00 0.16.0
GET /dynamique/status/FRALLEGO002006P3/history 30 0 750.0 682.2736812000035 11.943166000037309 1343.9901149999969 59709.53333333333 1.0287251452261763 0.0 840 890 970 1100 1200 1300 1300 1300 1300 1300 1300 d931cdf 2024-12-16 11:36:42.738183+00:00 0.16.0
POST /dynamique/status/bulk 36 0 700.0 757.3943373333426 20.00343600002452 2057.8661779999834 411.0 1.2344701742714117 0.0 730 970 1200 1200 1600 1700 2100 2100 2100 2100 2100 d931cdf 2024-12-16 11:36:42.738183+00:00 0.16.0
POST /statique/ 38 21 720.0 769.6523216578904 18.028919000016685 2076.0820759999774 56.78947368421053 1.3030518506198232 0.7201076016583234 830 960 1100 1200 1500 1900 2100 2100 2100 2100 2100 d931cdf 2024-12-16 11:36:42.738183+00:00 0.16.0
GET /statique/?limit=10 37 0 480.0 656.902808081084 34.32533500000545 2058.8296440000136 13826.432432432432 1.2687610124456177 0.0 480 840 880 1100 1500 2100 2100 2100 2100 2100 2100 d931cdf 2024-12-16 11:36:42.738183+00:00 0.16.0
GET /statique/?limit=100 37 0 880.0 836.7479094594676 134.83959400002732 1714.1431520000197 129006.43243243244 1.2687610124456177 0.0 880 1000 1200 1300 1400 1600 1700 1700 1700 1700 1700 d931cdf 2024-12-16 11:36:42.738183+00:00 0.16.0
PUT /statique/FR073EP7QU5233 45 0 400.0 539.0017205999965 21.726569999998446 2076.744589999976 1371.0 1.5430877178392644 0.0 400 700 810 970 1300 1500 2100 2100 2100 2100 2100 d931cdf 2024-12-16 11:36:42.738183+00:00 0.16.0
GET /statique/FRALLEGO002006P3 45 0 840.0 706.970945955561 14.421780999953173 1582.3812990000192 1202.0 1.5430877178392644 0.0 840 900 1100 1200 1300 1300 1600 1600 1600 1600 1600 d931cdf 2024-12-16 11:36:42.738183+00:00 0.16.0
POST /statique/bulk 25 0 970.0 1047.6572232400008 420.49031300001616 1790.9431859999927 1128.72 0.8572709543551469 0.0 970 1300 1500 1600 1700 1800 1800 1800 1800 1800 1800 d931cdf 2024-12-16 11:36:42.738183+00:00 0.16.0
Aggregated 551 21 700.0 689.316360684211 2.434585999992578 2077.9987870000127 13232.070780399274 18.89425183398744 0.7201076016583234 700 880 990 1200 1300 1500 1800 2100 2100 2100 2100 d931cdf 2024-12-16 11:36:42.738183+00:00 0.16.0

Comparison with the latest previous benchmark

A lower (negative) value means the current version performs better than the previous one.

Type Name Request Count Failure Count Median Response Time Average Response Time Min Response Time Max Response Time Average Content Size Requests/s
GET /auth/whoami
POST /dynamique/session/
POST /dynamique/session/bulk
GET /dynamique/status/
POST /dynamique/status/
GET /dynamique/status/FRALLEGO002006P3
GET /dynamique/status/FRALLEGO002006P3/history
POST /dynamique/status/bulk
POST /statique/
GET /statique/?limit=10
GET /statique/?limit=100
PUT /statique/FR073EP7QU5233
GET /statique/FRALLEGO002006P3
POST /statique/bulk
Aggregated

@jmaupetit jmaupetit changed the title ⚡️(api) cache logged user database request ⚡️(api) cache logged-in user database request Dec 16, 2024
Getting request user from database is the most frequent request as it's
accessed by every API endpoint. Caching logged user object for a limited
time can significantly decrease database queries.
When using the `list-groups` command it's more user-friendly to sort
things alphabetically.
Copy link

Current benchmark

Type Name Request Count Failure Count Median Response Time Average Response Time Min Response Time Max Response Time Average Content Size Requests/s Failures/s 50% 66% 75% 80% 90% 95% 98% 99% 99.9% 99.99% 100% git timestamp version
GET /auth/whoami 27 0 880.0 825.3771688518566 33.02797699998905 2565.1589710000167 160.0 0.9287417428403916 0.0 880 1100 1100 1200 1600 1600 2600 2600 2600 2600 2600 dec743d 2024-12-16 15:57:42.779979+00:00 0.16.0
POST /dynamique/session/ 28 0 640.0 855.7774042857145 17.80692899998826 3229.140615999995 45.0 0.9631395851678136 0.0 700 1200 1400 1400 2000 2700 3200 3200 3200 3200 3200 dec743d 2024-12-16 15:57:42.779979+00:00 0.16.0
POST /dynamique/session/bulk 21 0 720.0 891.688967904763 31.166041000005865 2569.5549309999988 411.0 0.7223546888758601 0.0 720 790 1300 1400 1800 2200 2600 2600 2600 2600 2600 dec743d 2024-12-16 15:57:42.779979+00:00 0.16.0
GET /dynamique/status/ 17 0 790.0 920.6412575294092 39.69807400000036 1918.6410039999944 285.0 0.5847633195661724 0.0 790 1300 1400 1400 1900 1900 1900 1900 1900 1900 1900 dec743d 2024-12-16 15:57:42.779979+00:00 0.16.0
POST /dynamique/status/ 15 0 780.0 857.4001276666612 36.88385299997776 2180.090245000002 45.0 0.5159676349113287 0.0 780 800 1200 1300 1600 2200 2200 2200 2200 2200 2200 dec743d 2024-12-16 15:57:42.779979+00:00 0.16.0
GET /dynamique/status/FRALLEGO002006P3 29 0 730.0 917.538770551719 11.42170099998907 2604.709139000022 268.2413793103448 0.9975374274952352 0.0 730 1400 1400 1500 1900 2300 2600 2600 2600 2600 2600 dec743d 2024-12-16 15:57:42.779979+00:00 0.16.0
GET /dynamique/status/FRALLEGO002006P3/history 23 0 1000.0 1003.2247918695653 165.18552300001943 2894.2030910000085 44095.086956521736 0.7911503735307039 0.0 1000 1300 1400 1400 1600 2000 2900 2900 2900 2900 2900 dec743d 2024-12-16 15:57:42.779979+00:00 0.16.0
POST /dynamique/status/bulk 29 0 860.0 959.140677862068 46.16441900000723 2911.789703000011 411.0 0.9975374274952352 0.0 860 1300 1400 1400 1500 1900 2900 2900 2900 2900 2900 dec743d 2024-12-16 15:57:42.779979+00:00 0.16.0
POST /statique/ 27 13 780.0 1021.355290888888 46.8482010000173 3056.4709479999974 57.5925925925926 0.9287417428403916 0.4471719502564848 780 1200 1700 1700 2400 2800 3100 3100 3100 3100 3100 dec743d 2024-12-16 15:57:42.779979+00:00 0.16.0
GET /statique/?limit=10 18 0 790.0 862.2083968888886 29.2170489999819 2791.993596999987 13826.611111111111 0.6191611618935944 0.0 800 890 1200 1400 1700 2800 2800 2800 2800 2800 2800 dec743d 2024-12-16 15:57:42.779979+00:00 0.16.0
GET /statique/?limit=100 18 0 770.0 1066.7481498888883 138.8740010000049 3038.676166000016 129006.61111111112 0.6191611618935944 0.0 890 1200 1400 1400 3000 3000 3000 3000 3000 3000 3000 dec743d 2024-12-16 15:57:42.779979+00:00 0.16.0
PUT /statique/FR073EP7QU5233 25 0 1200.0 1109.7481288000008 23.48413800001481 2879.4637109999994 1371.0 0.8599460581855477 0.0 1200 1400 1700 1800 2600 2900 2900 2900 2900 2900 2900 dec743d 2024-12-16 15:57:42.779979+00:00 0.16.0
GET /statique/FRALLEGO002006P3 32 0 900.0 1043.895952062501 9.813851000018303 3055.2107229999874 1202.0 1.100730954477501 0.0 1100 1400 1500 1700 2200 2900 3100 3100 3100 3100 3100 dec743d 2024-12-16 15:57:42.779979+00:00 0.16.0
POST /statique/bulk 36 0 1400.0 1423.509499277778 393.8538130000211 3056.8013779999887 1127.388888888889 1.2383223237871888 0.0 1400 1700 1900 1900 2800 3000 3100 3100 3100 3100 3100 dec743d 2024-12-16 15:57:42.779979+00:00 0.16.0
Aggregated 345 13 800.0 1001.955719046376 9.813851000018303 3229.140615999995 10839.11304347826 11.867255602960558 0.4471719502564848 800 1300 1400 1500 1900 2700 3000 3100 3200 3200 3200 dec743d 2024-12-16 15:57:42.779979+00:00 0.16.0

Comparison with the latest previous benchmark

A lower (negative) value means the current version performs better than the previous one.

Type Name Request Count Failure Count Median Response Time Average Response Time Min Response Time Max Response Time Average Content Size Requests/s
GET /auth/whoami
POST /dynamique/session/
POST /dynamique/session/bulk
GET /dynamique/status/
POST /dynamique/status/
GET /dynamique/status/FRALLEGO002006P3
GET /dynamique/status/FRALLEGO002006P3/history
POST /dynamique/status/bulk
POST /statique/
GET /statique/?limit=10
GET /statique/?limit=100
PUT /statique/FR073EP7QU5233
GET /statique/FRALLEGO002006P3
POST /statique/bulk
Aggregated

@jmaupetit jmaupetit merged commit be1fc42 into main Dec 16, 2024
15 checks passed
@jmaupetit jmaupetit deleted the cache-request-user branch December 16, 2024 17:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API Item related to the API service critical improvement needs review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants