Add performance testing

Created on 3 December 2024, 16 days ago

Problem/Motivation

This adds a very basic performance test using core's PerformanceTestBase.

It runs locally with the recommended ddev set up, you need to do ddev get ddev/ddev-selenium-standalone-chrome in addition to the usual steps to be able to run the test successfully.

The anonymous test generally looks good. I haven't done any manual testing yet to see what the page weight/lighthouse scores etc. are.

I think I immediately found a performance issue with the authenticated test - dozens of menu tree queries which I assume are from the navigation bar and uncached. This is probably πŸ“Œ Implement a caching strategy for the menu links Active . Because there's so many queries, I didn't add individual query assertions to the test, just the number of queries.

Once this is in, or before if desired, we can add more scenarios like a node page.

Steps to reproduce

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

πŸ“Œ Task
Status

Active

Component

Base Recipe

Created by

πŸ‡¬πŸ‡§United Kingdom catch

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @catch
  • Pipeline finished with Canceled
    16 days ago
    Total: 292s
    #357980
  • Pipeline finished with Canceled
    16 days ago
    Total: 64s
    #357989
  • Merge request !260Add performance test β†’ (Merged) created by catch
  • πŸ‡¬πŸ‡§United Kingdom catch
  • Pipeline finished with Failed
    16 days ago
    Total: 533s
    #357991
  • Pipeline finished with Failed
    16 days ago
    Total: 543s
    #357992
  • πŸ‡¬πŸ‡§United Kingdom catch

    This passes locally but fails on gitlab with:

    1) Drupal\Tests\drupal_cms_starter\FunctionalJavascript\PerformanceTest::testPerformance
    TypeError: Behat\Mink\Driver\Selenium2Driver::__construct(): Argument #1 ($browserName) must be of type string, array given
    

    So something is up with the gitlab configuration I think.

  • Pipeline finished with Failed
    16 days ago
    #358207
  • Pipeline finished with Failed
    16 days ago
    #358208
  • Pipeline finished with Failed
    16 days ago
    Total: 629s
    #358211
  • Pipeline finished with Failed
    16 days ago
    Total: 714s
    #358212
  • Pipeline finished with Failed
    16 days ago
    Total: 517s
    #358226
  • Pipeline finished with Failed
    16 days ago
    Total: 1308s
    #358227
  • Pipeline finished with Failed
    16 days ago
    #358253
  • Pipeline finished with Failed
    16 days ago
    Total: 533s
    #358254
  • Pipeline finished with Failed
    16 days ago
    Total: 446s
    #358262
  • Pipeline finished with Failed
    16 days ago
    Total: 455s
    #358263
  • Pipeline finished with Failed
    15 days ago
    Total: 682s
    #358268
  • Pipeline finished with Failed
    15 days ago
    Total: 689s
    #358269
  • Pipeline finished with Failed
    15 days ago
    Total: 672s
    #358275
  • Pipeline finished with Failed
    15 days ago
    Total: 701s
    #358276
  • Pipeline finished with Canceled
    15 days ago
    Total: 64s
    #358319
  • Pipeline finished with Canceled
    15 days ago
    Total: 64s
    #358318
  • Pipeline finished with Failed
    15 days ago
    Total: 623s
    #358320
  • Pipeline finished with Failed
    15 days ago
    Total: 662s
    #358321
  • Pipeline finished with Failed
    15 days ago
    Total: 572s
    #358808
  • Pipeline finished with Failed
    15 days ago
    Total: 654s
    #358809
  • Pipeline finished with Failed
    15 days ago
    Total: 769s
    #358838
  • Pipeline finished with Failed
    15 days ago
    Total: 850s
    #358839
  • Pipeline finished with Failed
    15 days ago
    Total: 502s
    #358860
  • Pipeline finished with Failed
    15 days ago
    Total: 516s
    #358861
  • Pipeline finished with Failed
    15 days ago
    Total: 475s
    #358880
  • Pipeline finished with Failed
    15 days ago
    Total: 491s
    #358881
  • Pipeline finished with Success
    15 days ago
    Total: 502s
    #358889
  • Pipeline finished with Failed
    15 days ago
    Total: 545s
    #358890
  • Pipeline finished with Success
    15 days ago
    Total: 539s
    #358901
  • Pipeline finished with Failed
    15 days ago
    Total: 736s
    #358902
  • Pipeline finished with Failed
    15 days ago
    #358931
  • Pipeline finished with Failed
    15 days ago
    #358932
  • Pipeline finished with Failed
    15 days ago
    Total: 736s
    #358940
  • Pipeline finished with Failed
    15 days ago
    Total: 1120s
    #358941
  • Pipeline finished with Failed
    15 days ago
    Total: 731s
    #358980
  • Pipeline finished with Failed
    15 days ago
    Total: 1160s
    #358981
  • Pipeline finished with Failed
    15 days ago
    Total: 711s
    #359015
  • Pipeline finished with Failed
    15 days ago
    Total: 732s
    #359016
  • Pipeline finished with Failed
    15 days ago
    Total: 666s
    #359066
  • Pipeline finished with Failed
    15 days ago
    Total: 741s
    #359067
  • Pipeline finished with Failed
    15 days ago
    Total: 623s
    #359087
  • Pipeline finished with Failed
    15 days ago
    Total: 963s
    #359086
  • Pipeline finished with Canceled
    15 days ago
    Total: 575s
    #359097
  • Pipeline finished with Canceled
    15 days ago
    Total: 627s
    #359096
  • Pipeline finished with Success
    15 days ago
    Total: 787s
    #359106
  • Pipeline finished with Failed
    15 days ago
    Total: 830s
    #359105
  • πŸ‡¬πŸ‡§United Kingdom catch

    Had to fight gitlab a bit to get functional javascript tests running, short version of what needed to change after some dead ends:

    1. Needs to copy some bits from the d.o gitlab templates to get the chromedriver service done, and also to set the right env var for the driver args.

    2. A red herring where the mysql database refuses connections, these seems to be an intermittent issue that has nothing to do with this MR, but convinced me I'd broken something in the gitlab config.

    3. Arguably out of scope but would have helped me here - added junit logging so the tests tab works on the pipeline: https://git.drupalcode.org/issue/drupal_cms-3491405/-/pipelines/359106/t... - requires a chance to one line of YAML we're already changing and a extra two lines of YAML... so only a little bit out of scope.

    This run successfully fails with the wrong query count on a page cache hit, so proves the tests are running at all (not the case when I was thrashing around with gitlab).

    https://git.drupalcode.org/issue/drupal_cms-3491405/-/jobs/3587342

    This passes https://git.drupalcode.org/issue/drupal_cms-3491405/-/jobs/3588474

    This is the most recent pass with the junit change included, not much difference on the job log itself but just for reference: https://git.drupalcode.org/issue/drupal_cms-3491405/-/jobs/3589032

  • πŸ‡©πŸ‡ͺGermany Fabianx

    Looks great to me.

    RTBC!

  • πŸ‡¬πŸ‡§United Kingdom catch

    Started opening issues for performance problems found via the tests.

    πŸ“Œ Try to reduce database queries from MenuLinkTree::load() Active (not actually found by the test, found it when profiling drush cr instead of the page I was supposed to be looking at)

    πŸ“Œ Add render caching for the navigation render array Active - possible quick fix for navigation.

  • πŸ‡ΊπŸ‡ΈUnited States phenaproxima Massachusetts

    This could use a follow-up to add the ability to run the performance tests locally too.

  • πŸ‡ΊπŸ‡ΈUnited States phenaproxima Massachusetts

    One minor thing, and needs a follow-up, then this is mergeable IMHO.

  • Pipeline finished with Failed
    7 days ago
    #366089
  • πŸ‡¬πŸ‡§United Kingdom catch

    Opened the follow-up for database query assertions πŸ“Œ Add database query assertions to performance tests Active .

    Any additional performance tests we want can be covered by the performance testing meta for now I think.

    Applied the suggestion.

  • Pipeline finished with Failed
    7 days ago
    Total: 1048s
    #366090
  • Pipeline finished with Failed
    7 days ago
    Total: 56s
    #366110
  • Pipeline finished with Failed
    7 days ago
    #366111
  • πŸ‡¬πŸ‡§United Kingdom catch

    Builds are failing on cannot stat patches.lock.json which I don't think is related to the MR.

  • πŸ‡ΊπŸ‡ΈUnited States phenaproxima Massachusetts

    Well, that's...weird. I'll look into that, try to get it fixed, and commit this.

  • πŸ‡¬πŸ‡§United Kingdom catch

    Adding all the issues I discovered as a result of adding the tests - some were a direct result, some spotted while looking at other things.

  • Pipeline finished with Failed
    7 days ago
    Total: 61s
    #366159
  • Pipeline finished with Failed
    7 days ago
    Total: 53s
    #366161
  • Pipeline finished with Canceled
    7 days ago
    Total: 63s
    #366165
  • Pipeline finished with Failed
    7 days ago
    Total: 613s
    #366167
  • Pipeline finished with Failed
    7 days ago
    Total: 571s
    #366173
  • πŸ‡ΊπŸ‡ΈUnited States phenaproxima Massachusetts

    Perf test is failing due to:

    1) Drupal\Tests\drupal_cms_starter\FunctionalJavascript\PerformanceTest::testPerformance
    Failed asserting that 4 is identical to 2.
    /builds/project/drupal_cms/recipes/drupal_cms_starter/tests/src/FunctionalJavaScript/PerformanceTest.php:54
    /builds/project/drupal_cms/recipes/drupal_cms_starter/tests/src/FunctionalJavaScript/PerformanceTest.php:36
    
  • Pipeline finished with Failed
    7 days ago
    Total: 629s
    #366513
  • πŸ‡¬πŸ‡§United Kingdom catch

    @phenaproxima the extra two cache gets are apparently because requesting the front page of Drupal CMS now redirects to /home - has something changed? Seems non-optimal to have an extra http round trip from the front page of the site. I can update the test expectations to match, but would be good to know what happened too.

  • πŸ‡¬πŸ‡§United Kingdom catch

    So the new test fails are all because Drupal is bootstrapped twice when you visit the homepage - once for the redirect and once to visit /home. I opened πŸ“Œ Front page always redirects to /home Active and updated the test coverage here to directly request the /home URL and avoid the redirect. If we'd done that in the first place it wouldn't have picked up the change, but now it has, there doesn't seem to be a lot of benefit in testing the additional redirect vs. a more 'normal' request. Can add more test scenarios later anyway.

    I also had to increase the cache get and cache tag counts for the editor request, assume this is due to different config changes made since the tests were written but didn't investigate in detail yet - it will be easier to diagnose why things are changing when this is running against MRs rather than here.

    Adding a screenshot of what an OpenTelemetry trace looks like in the Gander dashboard, which can be added to a local ddev install via a one-liner documented here and will automatically start to receive traces when running this test locally.

    We can add this to the hosted Grafana dashboard at https://gander.tag1.io/ too but that will take some pipeline work at a minimum.

  • πŸ‡¬πŸ‡§United Kingdom catch

    I've added @todos for the known issues. Updated assertions for the increased cache get counts, CSS and JavaScript weight for the editor user on the home page. I think the MR should be green now but test takes a long time to run locally and need to head afk soon, so pushing what I have while waiting for the hopefully last local run to come back.

  • Pipeline finished with Failed
    7 days ago
    Total: 584s
    #366922
  • Pipeline finished with Failed
    7 days ago
    Total: 738s
    #366923
  • πŸ‡¬πŸ‡§United Kingdom catch

    https://git.drupalcode.org/issue/drupal_cms-3491405/-/jobs/3678952

    MR is green again. I haven't investigated all the increased assertion limits apart from the new front page redirect, but as above it would be better if MRs find out they're changing things to not have to investigate in retrospect.

  • πŸ‡ΊπŸ‡ΈUnited States phenaproxima Massachusetts

    Question about this one: is there a risk of this slowing down contribution if various changes alter the number of queries and whatnot, in ways that can't be anticipated? Should this perhaps be moved to a separate CI job that is allowed to fail? Or maybe the assertions just become looser?

  • heddn Nicaragua

    re #19: It isn't an issue w/ Drupal core. It is much more stable though with the numbers and types of modules. So we won't know the answer to that with Drupal CMS until we get it in and start seeing results.

  • πŸ‡ΊπŸ‡ΈUnited States phenaproxima Massachusetts

    OK, I guess that's good enough for me. We can back it off if it becomes disruptive.

    I am assigning this to @tim.plunkett for final review and commit, once we come out of commit freeze (which should end next week).

  • πŸ‡¬πŸ‡§United Kingdom catch

    Question about this one: is there a risk of this slowing down contribution if various changes alter the number of queries and whatnot, in ways that can't be anticipated?

    When the test fails, you need to update the assertions, then it's possible to see which commit improved or regressed things. There is some headroom in the css and js assertions (i.e. they round up) to allow for small CSS and JS changes not to change too much. But if something suddenly adds 50k of CSS or 25 database queries to a page, it's good to know about it. It doesn't mean things can't get committed that do this, they just can't silently make things worse and require someone to track it down months later when they get bad lighthouse scores or their site slows to a crawl.

    It's a bit more of a pain with the query logging/assertions because there is more chance of commit conflicts etc. that was the reason to defer those to a follow-up - but I think that would be a good idea to add once coffee module issues are sorted and things are generally a bit more stable - when there's less queries overall, less chances of conflicts.

  • πŸ‡ΊπŸ‡ΈUnited States phenaproxima Massachusetts

    I'm okay with merging this but it looks like it needs to be synced back up with 1.x.

  • πŸ‡¬πŸ‡§United Kingdom catch

    Rebased.

  • Pipeline finished with Success
    3 days ago
    Total: 1307s
    #370224
  • πŸ‡¬πŸ‡§United Kingdom catch

    MR is green.

  • πŸ‡ΊπŸ‡ΈUnited States phenaproxima Massachusetts

    I'd like to merge this first thing tomorrow - can it be rebased one more time just to ensure that the most recent bunch of commits haven't broken its assertions?

  • πŸ‡¬πŸ‡§United Kingdom catch

    Lots of merge conflicts in the rebase again, so just went for the merge commit this time to save time.

    πŸ› Privacy policy link goes to a 403 Active will probably start to fail when this is merged, but only in a good way in that things are improving.

  • Pipeline finished with Failed
    2 days ago
    Total: 666s
    #370852
  • πŸ‡ΊπŸ‡ΈUnited States phenaproxima Massachusetts

    Would like to commit but tests seem to be failing.

    I think one risk of this is that if a dependency updates (remember, we don't pin and we use the relatively lax ^ operator), this test may just break out of nowhere. That's why I think it might make sense to have a follow-up that moves the performance testing into its own job.

  • πŸ‡¬πŸ‡§United Kingdom catch

    All green on https://git.drupalcode.org/issue/drupal_cms-3491405/-/pipelines/370852 - did you rerun the failing jobs or something?

    If we move the performance tests to their own job it will then be easier from there to add a job to populate the Grafana dashboard, so +1 to that. Opened πŸ“Œ Run performance tests in their own job Active .

  • πŸ‡ΊπŸ‡ΈUnited States phenaproxima Massachusetts
  • Pipeline finished with Skipped
    2 days ago
    #371278
  • πŸ‡ΊπŸ‡ΈUnited States phenaproxima Massachusetts

    Finally! Merged into 1.x. Thanks for the hard work and persistence on this.

  • Pipeline finished with Success
    2 days ago
    Total: 512s
    #371272
Production build 0.71.5 2024