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

Improve service keys quota check performance #2564

Conversation

philippthun
Copy link
Member

The performance of the service keys quota check is improved by the following means:

  • Fetch existing service keys count only when the quota for total_service_keys is not -1 (i.e. unlimited).
  • Fetch service instances as subquery.
  • Add index for service_instance_id to service_keys table.

When running the new tests added to cf-performance-tests locally, the response time decreases from ~2,9 to 0,05 seconds with the changes in this PR.

  • I have reviewed the contributing guide

  • I have viewed, signed, and submitted the Contributor License Agreement

  • I have made this pull request to the main branch

  • I have run all the unit tests using bundle exec rake

  • I have run CF Acceptance Tests

philippthun and others added 3 commits November 8, 2021 10:59
With this change the existing service keys count is fetched only when
the quota for total_service_keys is not -1 (i.e. unlimited). This
removes an unneeded database query.
- Don't fetch them upfront if not needed
- Issue less db queries

Co-authored-by: Katharina Przybill <katharina.przybill@sap.com>
While improving the selection of existing service keys and reducing the
number of database queries from 3 ([1]) to 1 ([2]), we found out that
the sub-select queries were very slow (for a large number of service
instances) due to a missing index.

[1]
SELECT * FROM "spaces" WHERE ("organization_id" = <ORG_ID>);
SELECT * FROM "service_instances" WHERE ("space_id" IN (<SPACE_IDS>));
SELECT count(*) AS "count" FROM "service_keys"
  WHERE ("service_instance_id" IN (<SERVICE_INSTANCE_IDS>)) LIMIT 1;

[2]
SELECT count(*) AS "count" FROM "service_keys"
  WHERE ("service_instance_id" IN (
    SELECT "id" FROM "service_instances" WHERE ("space_id" IN (
      SELECT "id" FROM "spaces" WHERE ("organization_id" = <ORG_ID>)
    ))
  )) LIMIT 1;

Co-authored-by: Katharina Przybill <katharina.przybill@sap.com>
@philippthun philippthun merged commit de83340 into cloudfoundry:main Nov 18, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants