View Issue Details

IDProjectCategoryView StatusLast Update
0002106XdebugCode Coveragepublic2022-10-03 07:16
Reporternetdjw Assigned Toderick  
PrioritynormalSeveritycrashReproducibilityalways
Status resolvedResolutionnot fixable 
OSAlpine Linux in Docker 
Product Version3.1.5 
Summary0002106: phpunit runs out of memory & runs much more slower than without xdebug
Description

In my Laravel project I have 1349 tests. I try to run phpunit in a Docker container. Some test are failing, but it's not a problem.

When I start phpunit with this command:

docker-compose run --rm phpunit --coverage-html

Then I get this output:

E.I.F....FFFF............FF.FF...............................   61 / 1349 (  4%)
.............................................................  122 / 1349 (  9%)
.............................................................  183 / 1349 ( 13%)
...........................djw@DESKTOP $

The djw@DESKTOP $ part is my console promt string. It means phpunit died without any error message.

I tried to run phpunit without xdebug. In this case it can run all tests and create an error & fail reports as it should be.

I tried to run phpunit pcov instead of xdebug, it can run also without die.

When I run phpunit without --coverage-html option, it't runs smoothly. But with this option it start tests and new dots showing slowly and slowly and then stops showing new dots. But the processor usage grow up to 100%, memory usage also growing up to 100%, then swap is runs out, and then the container dies.

Based on this test cases I think the problem is with xdebug.

Here is my phpunit.dockerfile:

FROM php:8.1-fpm-alpine

WORKDIR /var/www/html

RUN apk add --no-cache --repository http://dl-cdn.alpinelinux.org/alpine/edge/community/ --allow-untrusted gnu-libiconv
ENV LD_PRELOAD /usr/lib/preloadable_libiconv.so php

ENV PHP_MEMORY_LIMIT=1G
ENV PHP_UPLOAD_MAX_FILESIZE: 512M
ENV PHP_POST_MAX_SIZE: 512M

RUN docker-php-ext-install pdo

RUN apk add --no-cache libpng libpng-dev && docker-php-ext-install gd && apk del libpng-dev

RUN apk update \
    && apk upgrade \
    && apk add --no-cache \
        freetype \
        libpng \
        libjpeg-turbo \
        freetype-dev \
        libpng-dev \
        jpeg-dev \
        libwebp-dev \
        libjpeg \
        libjpeg-turbo-dev

RUN docker-php-ext-configure gd \
        --with-freetype=/usr/lib/ \
        --with-jpeg=/usr/lib/ \
        --with-webp=/usr

RUN NUMPROC=$(grep -c ^processor /proc/cpuinfo 2>/dev/null || 1) \
    && docker-php-ext-install -j${NUMPROC} gd

RUN apk add --no-cache sqlite-libs
RUN apk add --no-cache icu sqlite git openssh zip
RUN apk add --no-cache --virtual .build-deps icu-dev libxml2-dev sqlite-dev curl-dev
RUN docker-php-ext-install \
        bcmath \
        curl \
        ctype \
        intl \
        pdo \
        pdo_sqlite \
        xml
RUN apk del .build-deps

RUN docker-php-ext-enable pdo_sqlite

# Add xdebug
RUN apk add --no-cache --virtual .build-deps $PHPIZE_DEPS
RUN apk add --update linux-headers
RUN pecl install xdebug-3.1.5
RUN docker-php-ext-enable xdebug
RUN apk del -f .build-deps

# Configure Xdebug
RUN echo "xdebug.start_with_request=yes" >> /usr/local/etc/php/conf.d/xdebug.ini \
    && echo "xdebug.mode=coverage" >> /usr/local/etc/php/conf.d/xdebug.ini \
    && echo "xdebug.log=/var/www/html/xdebug/xdebug.log" >> /usr/local/etc/php/conf.d/xdebug.ini \
    && echo "xdebug.discover_client_host=1" >> /usr/local/etc/php/conf.d/xdebug.ini

RUN echo memory_limit = -1 >> /usr/local/etc/php/conf.d/docker-php-memlimit.ini;

Is there any option to tell phpunit the maximum usable memory size or something other trick to avoid this issue?

Additional Information

PHP version 8.1.6

Tagsalpine, coverage, crash, Docker, fpm, php8.1
Operating System
PHP Version8.1.0-8.1.4

Activities

derick

2022-08-09 09:58

administrator   ~0006352

Is there any option to tell phpunit the maximum usable memory size or something other trick to avoid this issue?

Yes, that is easy. Dont set the memory limit to -1 as you've done with this docker config line:

RUN echo memory_limit = -1 >> /usr/local/etc/php/conf.d/docker-php-memlimit.ini;

But in general, I expect the code to run about 10-20 times as slow, and using a lot more memory. Are you should have you have enough and your machine didn't start swapping?

netdjw

2022-08-09 13:57

reporter   ~0006356

But in general, I expect the code to run about 10-20 times as slow, and using a lot more memory. Are you should have you have enough and your machine didn't start swapping?

I tried to remove that line, but then docker died after filled every available memory space. RAM and swap too. So noting difference.

derick

2022-10-02 15:30

administrator   ~0006380

It still seems to me you're simply running out of memory, and there is nothing that I can do about it. Coverage collection takes up quite a lot of memory, specifically when having a complex application.

netdjw

2022-10-03 07:16

reporter   ~0006385

What do you think, how can I calculate in the future: how many memory I need to run xdebug without any issues?

It's important to know because I use cloud technologies to run my Docker container, and I have possibility to expand memoires as I need.

Thanks!

Issue History

Date Modified Username Field Change
2022-07-27 08:23 netdjw New Issue
2022-07-27 08:23 netdjw Tag Attached: alpine
2022-07-27 08:23 netdjw Tag Attached: coverage
2022-07-27 08:23 netdjw Tag Attached: crash
2022-07-27 08:23 netdjw Tag Attached: Docker
2022-07-27 08:23 netdjw Tag Attached: fpm
2022-07-27 08:23 netdjw Tag Attached: php8.1
2022-08-09 09:58 derick Note Added: 0006352
2022-08-09 13:57 netdjw Note Added: 0006356
2022-10-02 15:30 derick Assigned To => derick
2022-10-02 15:30 derick Status new => resolved
2022-10-02 15:30 derick Resolution open => not fixable
2022-10-02 15:30 derick Note Added: 0006380
2022-10-03 07:16 netdjw Note Added: 0006385