S
S
Sergey Pozdnyakov2020-12-11 21:18:28
PHP
Sergey Pozdnyakov, 2020-12-11 21:18:28

Why are phpfpm+nginx slower in docker?

I decided to wrap everything in docker containers on the prod. For development, they switched to docker a long time ago.
Everything started fine, I transferred the configs from the sale, corrected only the paths.
But complaints began to arrive that the site began to slow down. I checked, indeed the response speed increased by 2 (!!) times. php very well started to eat CPU, about the same 2 times more. There are no changes to the OP.
I started looking for the reason, by typing I transferred services from the docker to the piece of iron. So I found out that nginx + php-fpm work fine with all docker containers and the site does not slow down if they are not in the container ...
To visualize two graphs from the Yandex tank
Hardware
Docker

Dockerfile nginx

FROM nginx:1.17.4

ARG SERVER_UID
RUN usermod -u $SERVER_UID www-data && groupmod -g $SERVER_UID www-data

COPY ./config /etc/nginx

RUN ln -sf /dev/stdout /var/log/nginx/site.ru.access.log \
        && ln -sf /dev/stderr /var/log/nginx/site.ru.error.log \


Dockerfile php-fpm
FROM php:7.2.34-fpm

## Install dependeses
RUN apt-get update && mkdir -p /usr/share/man/man1 && \
    apt-get install --yes --no-install-recommends git unzip wget mc ssh \
    default-mysql-client default-jdk default-jre locales ghostscript \
    libssl-dev \
    zlib1g-dev libzip-dev libicu-dev libpng-dev libxml2-dev libldap2-dev libmemcached-dev libmagickwand-dev

RUN sed -i -e 's/# ru_RU.UTF-8 UTF-8/ru_RU.UTF-8 UTF-8/' /etc/locale.gen && \
    locale-gen
ENV LANG ru_RU.UTF-8
ENV LANGUAGE ru_RU:en
ENV LC_ALL ru_RU.UTF-8

##Configure php extension
RUN docker-php-ext-configure intl
##Install php extension
RUN docker-php-ext-install zip gd mbstring pdo_mysql soap intl
RUN pecl install redis memcached imagick
RUN docker-php-ext-enable redis memcached imagick
RUN docker-php-ext-configure ldap --with-libdir=lib/x86_64-linux-gnu/ && \
    docker-php-ext-install ldap
RUN docker-php-ext-install calendar && docker-php-ext-enable calendar


ENV EXT_MONGODB_VERSION=1.3.4

RUN docker-php-source extract \
    && git clone --branch $EXT_MONGODB_VERSION --depth 1 https://github.com/mongodb/mongo-php-driver.git /usr/src/php/ext/mongodb \
    && cd /usr/src/php/ext/mongodb && git submodule update --init \
    && docker-php-ext-install mongodb \
    && rm -rf /usr/src/php/ext/mongodb

RUN apt-get autoremove -y \
    && apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* /usr/share/doc/* /usr/share/man/man1/* /var/cache/apt/archives/* \
    && docker-php-source delete && rm -rf ~/.pearrc

## Install Composer
#ENV COMPOSER_HOME=/var/www/.compose
RUN curl -sS https://getcomposer.org/installer \
  | php -- --install-dir=/usr/local/bin --filename=composer  --version=1.10.19
RUN composer diagnose

## Set user uid
ARG SERVER_UID
RUN usermod -u $SERVER_UID www-data && groupmod -g $SERVER_UID www-data

WORKDIR /var/www/html


What could be the reason?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Sergey Pozdnyakov, 2020-12-14
@Afinogen

docker-php-ext-install opcache solution. It turns out that by default it is NOT in the official image! And I thought that it is, because it's stupid to build php without it. Thanks to the DevOps chat in the cart, they helped.

B
Boris Korobkov, 2020-12-11
@BorisKorobkov

Weird question. You've installed an intermediary and then wonder why it's slower with it than without it. Obviously, some of the server resources are spent on docker itself.
It is better to rephrase the question why so many resources are spent on docker. But to answer this question, it is better to hire an experienced admin who will poke around in your site, profile and look for the problem.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question