Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
For users with large numbers of space visibilities (1000+), the query string in
SecurityGroupPresenter::space_guid_hash_for
was getting extremely large as it does aSELECT ... WHERE IN (<list of visible space guids>)
for each security group. As the goal of this query is to effectively find which spaces the security group is applied to, the number of returned rows is strictly less than or equal to the size of the visible space guid lists. By fetching the list of all space guids a security group is applied to and filtering in Ruby, we avoid having to serialize the large visible space list and create + send the large query (sometimes multiple MB in length!) across to the DB.Best case scenario (for this change)
security_groups_spaces
) so few rows are returnedThis should be a big improvement as the extra cost of doing
include?
in the Cloud Controller should be neglible when only a few rows are returnedUsing:
Timings:
cf curl /v3/security_groups
- 68scf curl /v3/security_groups
- 0.37scf curl /v3/security_groups?per_page=500
- Timed out after 30 minutes (watching the DB it was doing some weird stuff)cf curl /v3/security_groups?per_page=500
- 1.74sWorst case scenario (for this change)
security_groups_spaces
) so lots of rows are returnedThis could be a significant downgrade if the
include?
is expensive due to lots of rows being returned as the filtering is no longer done in the DBUsing:
Timings:
cf curl /v3/security_groups
- 8.1scf curl /v3/security_groups
- 4.6scf curl /v3/security_groups?per_page=500
- 96scf curl /v3/security_groups?per_page=500
- 48sInitially there appeared to be no significant difference between approaches however by including a
select(:guid)
in the query, this reduced the size of the returned dataset enough that the new query outperformed the old one even in this scenario.Conclusion
This adjusted query seems to be an improvement in both the worst and best case scenario for this change. I would also suggest that the "best case scenario" above is much more realistic for a real world scenario of having many spaces but only a few security groups per space.
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
branchI have run all the unit tests using
bundle exec rake
I have run CF Acceptance Tests