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

🐛 Add project name search parameter for project listing for the API server usecase 🚨 #7066

Conversation

matusdrobuliak66
Copy link
Contributor

@matusdrobuliak66 matusdrobuliak66 commented Jan 21, 2025

What do these changes do?

  • On osparc.io, we observed overloading of the database.
    image

  • Currently, our database has only 2 CPUs. This graph shows that, on average, we would need 70 CPUs to handle the traffic.

  • The issue is primarily when api server calls "list projects" query, which involves multiple column searches, especially for the end-to-end testing user (who has 1,800 hidden projects).

  • Initial analysis showed that the query takes 93 seconds to execute. Since the API server does not require multi-column search, I performed some tests by removing unnecessary search fields and leaving only the project name. This reduced the query time to 150 ms. Furthermore, changing ILIKE to LIKE, which is even lighter, reduced it further to 73 ms.

  • This is why I introduced a new filter field specifically for the API server, projects_name_search. This approach can also be easily hotfixed if needed.

  • After further investigation, it turned out that the issue is not directly related to multi-column search itself but rather to how the database engine plans the execution. For some reason, when multiple joins and multiple text ILIKE filters are involved, the engine appears to get confused and does not create an optimal execution plan. For example, it first joins the projects table with the project_tags table (30,000 projects × 4,000 project tags ≈ 120,000,000 rows) and only afterward performs the multi-column search.

  • By simplifying the query for the API server use case, the engine started to create a more optimal execution plan.

  • Other steps that should be taken:

    • Add @cancel_on_disconnect to each route.
    • Implement a specialized listing of projects that retrieves only the necessary data (e.g., project tags are not required).

Related issue/s

How to test

Dev-ops checklist

  • 🚨 reactivate e2e api tests when this PR is released

@matusdrobuliak66 matusdrobuliak66 self-assigned this Jan 21, 2025
Copy link

codecov bot commented Jan 21, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 83.67%. Comparing base (21561a6) to head (09db770).
Report is 1 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #7066      +/-   ##
==========================================
- Coverage   88.30%   83.67%   -4.63%     
==========================================
  Files        1484      752     -732     
  Lines       58987    35336   -23651     
  Branches     1299      262    -1037     
==========================================
- Hits        52088    29569   -22519     
+ Misses       6697     5707     -990     
+ Partials      202       60     -142     
Flag Coverage Δ
integrationtests 64.74% <16.66%> (+1.08%) ⬆️
unittests 85.59% <100.00%> (-0.92%) ⬇️
Components Coverage Δ
api ∅ <ø> (∅)
pkg_aws_library ∅ <ø> (∅)
pkg_dask_task_models_library ∅ <ø> (∅)
pkg_models_library ∅ <ø> (∅)
pkg_notifications_library ∅ <ø> (∅)
pkg_postgres_database ∅ <ø> (∅)
pkg_service_integration ∅ <ø> (∅)
pkg_service_library ∅ <ø> (∅)
pkg_settings_library ∅ <ø> (∅)
pkg_simcore_sdk 77.37% <ø> (-8.02%) ⬇️
agent ∅ <ø> (∅)
api_server 90.55% <100.00%> (+<0.01%) ⬆️
autoscaling ∅ <ø> (∅)
catalog ∅ <ø> (∅)
clusters_keeper ∅ <ø> (∅)
dask_sidecar ∅ <ø> (∅)
datcore_adapter ∅ <ø> (∅)
director ∅ <ø> (∅)
director_v2 78.53% <ø> (-12.74%) ⬇️
dynamic_scheduler ∅ <ø> (∅)
dynamic_sidecar 89.75% <ø> (ø)
efs_guardian ∅ <ø> (∅)
invitations ∅ <ø> (∅)
osparc_gateway_server ∅ <ø> (∅)
payments ∅ <ø> (∅)
resource_usage_tracker ∅ <ø> (∅)
storage ∅ <ø> (∅)
webclient ∅ <ø> (∅)
webserver 83.99% <100.00%> (-0.56%) ⬇️

Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 21561a6...09db770. Read the comment docs.

@matusdrobuliak66 matusdrobuliak66 added a:webserver issue related to the webserver service a:apiserver api-server service labels Jan 21, 2025
@matusdrobuliak66 matusdrobuliak66 added this to the Singularity milestone Jan 21, 2025
@matusdrobuliak66 matusdrobuliak66 marked this pull request as ready for review January 21, 2025 16:15
@matusdrobuliak66 matusdrobuliak66 changed the title 🐛 fix 🐛 Add project name search parameter for project listing for the API server usecase. Jan 21, 2025
Copy link
Member

@odeimaiz odeimaiz left a comment

Choose a reason for hiding this comment

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

thanks!

Copy link
Member

@sanderegg sanderegg left a comment

Choose a reason for hiding this comment

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

thanks!

Copy link
Contributor

@bisgaard-itis bisgaard-itis left a comment

Choose a reason for hiding this comment

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

Very nice analysis! Thanks a lot for the fix

Copy link
Member

@pcrespov pcrespov left a comment

Choose a reason for hiding this comment

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

Thx!

@matusdrobuliak66 matusdrobuliak66 merged commit e2aeff5 into ITISFoundation:master Jan 22, 2025
89 of 93 checks passed
@pcrespov pcrespov changed the title 🐛 Add project name search parameter for project listing for the API server usecase. 🐛 Add project name search parameter for project listing for the API server usecase 🚨 Jan 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a:apiserver api-server service a:webserver issue related to the webserver service
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants