Problem/Motivation

In #3170261: Entity static cache can cause memory exhaustion during sitemap regeneration we improved memory usage at the expense of doubling the amount queries - see #3202233: Stop clearing the persistent entity cache when building the sitemap.

Let's add some instrumentation to make it easy to get both query and memory information.

Proposed resolution

Always add memory info to the batch message. Add setting to count the queries too.

Remaining tasks

User interface changes

API changes

Data model changes

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

alexpott created an issue. See original summary.

alexpott’s picture

Status: Active » Needs review
alexpott’s picture

I've merge the latest changes in. This would be helpful for any future work on this module - in order to prove there haven't been performance regressions.

alexpott’s picture

gbyte’s picture

Status: Needs review » Needs work

What's the reasoning behind showing some metrics by default? How would you feel about us adding a UI setting under advanced 'show performance metrics' that would enable all of the above? If unchecked, no performance metrics would be shown. In configuration there would be just 'show_performance_metrics' instead of monitoring.count_queries.

alexpott’s picture

Here's the reasoning why I did it like this: the memory calculations are essentially free (when compared with the other work) - so there's no point not displaying them. The query counting affects the memory calculations so needs to be turnable on and off. Also I don't think this needs to be something in the UI. However I do think it might be worth thinking about from a different perspective. We could add a performance test script to the project so it's really easy for people to run a performance test and display the results in an issue. This script could turn on and off the query logging and do the memory calculations and thereby we wouldn't need to make any runtime change.

alexpott’s picture

Status: Needs work » Needs review

Here's the output of the command before and after the recent performance changes:

Before

 [info] Created 500 nodes for sitemap testing
 [info] Running memory usage tests:
 [info] Executing: /Users/alex/dev/sites/drupal8alt.dev/vendor/bin/drush batch-process 2 --uri=http://drupal8alt.test --root=/Users/alex/dev/sites/drupal8alt.dev
>  [notice] 501 out of 501 total items have been processed.
>  [notice] Memory: 38.5 MB, non-peak mem: 38.5 MB
 [info] Generation completed in: 1.25 seconds
 [info] Executing: /Users/alex/dev/sites/drupal8alt.dev/vendor/bin/drush batch-process 3 --uri=http://drupal8alt.test --root=/Users/alex/dev/sites/drupal8alt.dev
>  [notice] 501 out of 501 total items have been processed.
>  [notice] Memory: 38.5 MB, non-peak mem: 38.5 MB
 [info] Generation completed in: 1.16 seconds
 [info] Running query count tests:
 [info] Executing: /Users/alex/dev/sites/drupal8alt.dev/vendor/bin/drush batch-process 4 --uri=http://drupal8alt.test --root=/Users/alex/dev/sites/drupal8alt.dev
>  [notice] 501 out of 501 total items have been processed.
>  [notice] Query count: 5110
 [info] Generation completed in: 1.24 seconds
 [info] Executing: /Users/alex/dev/sites/drupal8alt.dev/vendor/bin/drush batch-process 5 --uri=http://drupal8alt.test --root=/Users/alex/dev/sites/drupal8alt.dev
>  [notice] 501 out of 501 total items have been processed.
>  [notice] Query count: 5066
 [info] Generation completed in: 1.22 seconds

After

vendor/bin/drush scr --uri=http://drupal8alt.test modules/simple_sitemap/tests/scripts/performance_test.php generate
 [info] Created 500 nodes for sitemap testing
 [info] Running memory usage tests:
 [info] Executing: /Users/alex/dev/sites/drupal8alt.dev/vendor/bin/drush batch-process 2 --uri=http://drupal8alt.test --root=/Users/alex/dev/sites/drupal8alt.dev
>  [notice] 11 out of 11 total queue items have been processed.
>  [notice] Memory: 40.5 MB, non-peak mem: 40.5 MB
 [info] Generation completed in: 0.81 seconds
 [info] Executing: /Users/alex/dev/sites/drupal8alt.dev/vendor/bin/drush batch-process 3 --uri=http://drupal8alt.test --root=/Users/alex/dev/sites/drupal8alt.dev
>  [notice] 11 out of 11 total queue items have been processed.
>  [notice] Memory: 38.5 MB, non-peak mem: 38.5 MB
 [info] Generation completed in: 0.51 seconds
 [info] Running query count tests:
 [info] Executing: /Users/alex/dev/sites/drupal8alt.dev/vendor/bin/drush batch-process 4 --uri=http://drupal8alt.test --root=/Users/alex/dev/sites/drupal8alt.dev
>  [notice] 11 out of 11 total queue items have been processed.
>  [notice] Query count: 1182
 [info] Generation completed in: 0.73 seconds
 [info] Executing: /Users/alex/dev/sites/drupal8alt.dev/vendor/bin/drush batch-process 5 --uri=http://drupal8alt.test --root=/Users/alex/dev/sites/drupal8alt.dev
>  [notice] 11 out of 11 total queue items have been processed.
>  [notice] Query count: 593
 [info] Generation completed in: 0.53 seconds

So we can see the reduction in the number of queries and the increase run times and whilst the first run uses a little bit more memory subsequent runs do not. Note that the number of queries 8.x-3.9 does per node means that you will have 10x the number of queries as nodes. As we can see, the new performance fixes in the dev branch completely change this.

gbyte’s picture

Status: Needs review » Active

This is interesting. Would it make sense to make it available as Drush command instead of running it with `dursh scr`?

It would be nice to have some sort of cleanup script in case people run it with the generate flag on production. Maybe a warning?

Another thought: Any idea if we can leverage this as part of the testing suite? Tests spin up a new Drupal environment so it wouldn't pollute production. On the other hand, the results would be less representative of the specific Drupal environment. Plus the output of this test would be of relevance and not its passing/failing. Thoughts?

Also, we'll need a readme section as well as a copy of it in the documentation page.

alexpott’s picture

If you run it on production - you run it without the generate option - then you can get results back for your site. Imo cleanup and warnings on the generate are unnecessary.

I choose to not make it a drush command because I don't think this is something people should just "use" if they are running the module. It's to help contributors and maintainers ensure there aren't performance regressions on make changes. Given the nature of what this module does and how it works small changes can have large and unintended impacts.

Wrt to running the script in a test - I thought about that - I think it is a good idea - because it means with can ensure we don't break it and set maybe an expected number of queries and memory usage. But on the other hand using Drush then makes this quite tricky because we'd need to somehow get that code and make it use the test site... seems a lot of work.

  • gbyte committed cc36d7a on 8.x-3.x authored by alexpott
    Issue #3202290 by alexpott, gbyte: Add performance test script
    
gbyte’s picture

Title: Add performance metrics to batch info » Add performance test script
Status: Active » Fixed

Added minor changes and documentation. Thanks!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.