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

Speed up regular result iterator #1370

Merged
merged 22 commits into from
Dec 8, 2020

Conversation

mattmundell
Copy link
Contributor

@mattmundell mattmundell commented Dec 1, 2020

What:

Speed up iterator created by init_result_get_iterator:

  1. Simplify level check when checking for all levels.
  2. Use LATERAL to keep the new severity SQL in a single place in the statement.
  3. Inline SQL from views and functions to take advantage of the JOIN on table nvts.
  4. Use WITH to isolate the current severity calculation in the "overrides on, dynamic on" case.

Improvements to my GET_RESULTS times:

static, overrides off      17s to 6s
static, overrides on      248s to 34s
dynamic, overrides off     45s to 6s
dynamic, overrides on     415s to 33s

This translates to similar jumps in the GSA Results page.

This PR is similar to the changes to the result counting iterator in #1358.

Why:

Improves the speed of the GSA result pages when using bigger dbs, especially the Results page.

Making the dynamic cases fast may enable us to switch to "query-time" dynamic-only severity (#1337).

How did you test it:

With an 800k result db, having 3 overrides.

  1. git checkout master

  2. make install

  3. gvmd

  4. update settings set value = 0 where owner = (select id from users where name = 'm') and uuid = '77ec2444-e7f2-4a80-a59b-f4237782d93f';

  5. time o m m '<get_results details="1" filter="apply_overrides=0 min_qod=70 sort-reverse=severity rows=10 first=1"/>' > /tmp/master-st => 17s

  6. time o m m '<get_results details="1" filter="apply_overrides=1 min_qod=70 sort-reverse=severity rows=10 first=1"/>' > /tmp/master-st-ov => 248s

  7. update settings set value = 1 where owner = (select id from users where name = 'm') and uuid = '77ec2444-e7f2-4a80-a59b-f4237782d93f';

  8. time o m m '<get_results details="1" filter="apply_overrides=0 min_qod=70 sort-reverse=severity rows=10 first=1"/>' > /tmp/master-dy => 45s

  9. time o m m '<get_results details="1" filter="apply_overrides=1 min_qod=70 sort-reverse=severity rows=10 first=1"/>' > /tmp/master-dy-ov => 415s

  10. time o m m '<get_results details="1" filter="rexec apply_overrides=1 min_qod=70 sort-reverse=severity rows=10 first=1"/>' > /tmp/master-dy-ov-filter => 209s (with pg jit off)

  11. git checkout lateral-results

  12. make install

  13. gvmd

  14. update settings set value = 1 where owner = (select id from users where name = 'm') and uuid = '77ec2444-e7f2-4a80-a59b-f4237782d93f';

  15. time o m m '<get_results details="1" filter="apply_overrides=0 min_qod=70 sort-reverse=severity rows=10 first=1"/>' > /tmp/lateral-st => 6s

  16. time o m m '<get_results details="1" filter="apply_overrides=1 min_qod=70 sort-reverse=severity rows=10 first=1"/>' > /tmp/lateral-st-ov => 34s

  17. update settings set value = 1 where owner = (select id from users where name = 'm') and uuid = '77ec2444-e7f2-4a80-a59b-f4237782d93f';

  18. time o m m '<get_results details="1" filter="apply_overrides=0 min_qod=70 sort-reverse=severity rows=10 first=1"/>' > /tmp/lateral-dy => 5s

  19. time o m m '<get_results details="1" filter="apply_overrides=1 min_qod=70 sort-reverse=severity rows=10 first=1"/>' > /tmp/lateral-dy-ov => 33s

  20. time o m m '<get_results details="1" filter="rexec apply_overrides=1 min_qod=70 sort-reverse=severity rows=10 first=1"/>' > /tmp/lateral-dy-ov-filter => 73s (with pg jit off)

  21. cd /tmp

  22. diff master-st lateral-st => empty

  23. diff master-st-ov lateral-st-ov => empty

  24. diff master-dy lateral-dy => empty

  25. diff master-dy-ov lateral-dy-ov => empty

  26. diff master-dy-ov-filter lateral-dy-ov-filter => empty

Checklist:

@mattmundell mattmundell marked this pull request as ready for review December 2, 2020 12:11
@mattmundell mattmundell marked this pull request as draft December 2, 2020 15:36
@mattmundell mattmundell marked this pull request as ready for review December 2, 2020 16:57
@mattmundell mattmundell requested review from timopollmeier and removed request for timopollmeier December 7, 2020 19:19
@timopollmeier timopollmeier merged commit 0a81819 into greenbone:master Dec 8, 2020
@mattmundell mattmundell deleted the lateral-results branch December 8, 2020 08:30
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.

2 participants