1

I have a problem which I find awfully hard to debug: In my application, I currently have about 1000 tests, so not much. They are split across several directories (tests/someDir, tests/someOtherDir, tests/evenAnotherDir....). When I run phpunit for one of these directories separately, the tests have a normal performance. When I run the whole /tests directory however, the tests get awfully slow, increasing from test to test. Tests that usually take 100ms suddenly take 2s and more.

I have no idea what the issue is, which makes debugging hard. What I checked so far:

  • System resources: There is no unusual CPU load, nor is the memory full - nothing is put to swap (see screenshot). However, the fan of my computer starts working hard when I run the tests.
  • Database (MariaDB 11): All tests use the same connection, there is no max_connection problem or so.

My setup:

  • Ubuntu 24.04 on a modern machine (LG Gram 2024)
  • PhpStorm as IDE - I run the tests from PhpStorm ([docker-compose://[/var/www/html/EOO/EOOv5/app/tests/.docker/docker-compose.yml]:php-apache-xdebug/]:php /var/www/html/vendor/phpunit/phpunit/phpunit --configuration /var/www/html/phpunit.xml.dist /var/www/html/tests --teamcity)
  • PHP8.3 dockered, Xdebug on on coverage mode
  • MariaDB dockered

Can you give me a hint what to try to find the issue?

Best regards

enter image description here

enter image description here

7
  • 2
    If there is a lot of database access, then they could be holding each other up. If you are setting certain data in the database then it may be a bottleneck. Commented Oct 28 at 16:22
  • Hi, yes, there is a lot of DB access, but I see no reason why this should make the tests run so slow. I enabled slow query log on MariaDB, not a single query is slow. Each test is run in a transaction which is started in setUp() and rolled back in tearDown() Commented Oct 28 at 17:23
  • 2
    Are the DB test queries really necessary or can it be mocked? This would speed up massively. Commented Oct 28 at 21:21
  • 2
    Also please provide the code of one slow test. With that current given information alone no debug or analysis is possible, just guessing. Commented Oct 28 at 21:23
  • 2
    [slowness] It that's not CPU and memory , then most likely it is I/O Commented Oct 29 at 2:54

2 Answers 2

1

Comments mention I/O performance. You can increase it by storing the database in memory instead of a storage (SSD):

services:
    database:
        image: mariadb:10
        # …
        tmpfs:
            - /var/lib/mysql

On my computer, tests take 50% less time when using tmpfs.

Sign up to request clarification or add additional context in comments.

Comments

0

I found the issue: Registering the same event handlers again and again in the tests, leading up to about 50 times the same code being executed (50 tests that did that). Fixed now.

How I got there:

  1. In Github Actions, the tests also ran awfully slow, 40 Minutes for 970 tests. So the problem could not be locally.

  2. I also disabled Xdebug, didn't solve the issue.

  3. I started running the tests directory for directory. The summed up time for all tests were only 2 minutes 20 seconds.

  4. I also noted times for some longer running tests to find after which tests the performance problem started.

  5. This helped me identify The tests which caused the problem and then debug it.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.