Skip to content

unit:1.34.1-php8.4 consumes more and more memory over time (possibly due to one unitd process) #1576

Open
@kapyaar

Description

@kapyaar

Bug Overview

Hi,

I have a project using unit:1.34.1-php8.4. I am testing it in docker, along with redis, and mysql. Everything is working fine, except the php container memory usage keeps increasing.

Docker-compose.yml

services:
  php:
    build:
      context: .
      dockerfile: Dockerfile
    working_dir: /var/www/html/
    container_name: phpApp
    ports:
      - '80:80'
      - '443:443'
    volumes:
      - '.:/var/www/html/'
    networks:
      - default

Dockerfile

RUN apt-get update \    
    && curl -s https://getcomposer.org/installer | php \
    && mv composer.phar /usr/local/bin/composer
	
RUN apt-get update && apt-get install -y \
    libonig-dev \
    libxml2-dev \
    && docker-php-ext-install pcntl

RUN pecl install redis \
    && docker-php-ext-enable redis
	
RUN apt-get update && apt-get install -y supervisor 

COPY config/opcache.ini /usr/local/etc/php/conf.d/opcache.ini


WORKDIR /var/www/html/
COPY config/supervisord.conf /etc/supervisor/conf.d/supervisord.conf

COPY config/config.json init.json
COPY config/cert-bundle.pem init.pem

	
RUN nohup /bin/sh -c "unitd --no-daemon --pid init.pid --log /dev/stdout --control unix:init.unit.sock &" && \
    # Wait for Unit to start (a few seconds to be sure)
    sleep 5 && \
    # Check if the socket is available
    curl --unix-socket init.unit.sock -fsX GET _/config && \
    curl -fsX PUT --data-binary @init.pem --unix-socket init.unit.sock _/certificates/cert-bundle && \
    curl -fsX PUT [email protected] --unix-socket init.unit.sock _/config && \
    rm init.*

EXPOSE 80 443

CMD ["/usr/bin/supervisord", "-c", "/etc/supervisor/conf.d/supervisord.conf"]

docker status start like below.

Image

When it is exposed to traffic, the memory for phpApp slowly starts to rise. Say, it goes from 120MB at start, to ~400MB in 12 hours or so. And keeps going, to the point the container gets restarted.

This is with traffic, after some time

Image

Trying to narrow down to what might be causing this, I have identified a process in the process list that shows notable cpu usage (3-4%, while the others are in the 1.x %). In the below screenshot, pid 15 is the one I am referring to.

Image

Looking into this process, I could see a lot of entries, trying to access the base machine, with permission denied. Adding
privileged: true
to the docker-compose file for the phpApp got rid of this error, and I could see a bunch of entries like below

Image Image

Note that, even when I was seeing all those Permission denied entries under PID15, the app is running fine, so it is not affecting the app. If I kill this process, the memory usage comes down instantly.

Image

But another process spawns and starts doing the same thing.

Expected Behavior

Memory usage should remain more or less same for a constant load. But it keeps increasing.

Steps to Reproduce the Bug

I use docker-compose up command to start the containers on AWS EC2.

Environment Details

  • Target deployment platform: [AWS]
  • Target OS: [Amazon Linux 2023]
  • Version of any relevant project languages: [php8.4]

Additional Context

Any help is much appreciated. I can provide any additional info (config.json, supervisor.conf etc if needed).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions