Symfony2在多码头上的php7-fpm上运行速度非常慢

时间:2017-02-06 09:24:26

标签: php symfony nginx docker docker-compose

我正在尝试使用php7-fpm和nginx在多终端上设置symfony2环境。

整个事情都有效。但是,由于一些莫名其妙的原因,每个请求需要20-30秒才能完成(整个页面在大约5分钟内加载)。在负载期间,CPU出现峰值。我尝试使用php fpm config,nginx config。甚至复制了我正在使用的另一个应用程序的确切的,这非常好。在这一点上,我被困住了,我甚至不知道从哪里开始(继续)。

我的docker-compose.yml看起来像这样:

web:
  build: ./
  container_name: indago_web
  external_links:
    - mysql:mysql
  volumes:
    - ./php-fpm/www.conf:/usr/local/etc/php-fpm.d/www.conf
    - ~/Dev/indago/indago:/var/www/indago
  environment:
    ING_DB_USER: priz_wp
    ING_DB_PASSWORD: Shurik_0(8
    ING_DB_NAME: priz_wp
    ING_DB_HOST: mysql
proxy:
  image: nginx
  container_name: indago_proxy
  links:
    - web:web
  ports:
    - "80:80"
  volumes:
    - ./web/nginx.conf:/etc/nginx/nginx.conf
    - ./web/default.conf:/etc/nginx/conf.d/default.conf

webapp的Dockerfile:

FROM php:7-fpm

RUN apt-get update && apt-get install -y vim \
    libxml2-dev libicu-dev \
    && rm -rf /var/lib/apt/lists/* && apt-get autoremove

# Install Composer
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
RUN composer --version

# Set timezone
RUN rm /etc/localtime
RUN ln -s /usr/share/zoneinfo/America/Vancouver /etc/localtime
RUN "date"

RUN docker-php-ext-install pdo pdo_mysql opcache ctype json xml tokenizer mbstring iconv posix intl

RUN { \
        echo 'opcache.memory_consumption=128'; \
        echo 'opcache.interned_strings_buffer=8'; \
        echo 'opcache.max_accelerated_files=4000'; \
        echo 'opcache.revalidate_freq=2'; \
        echo 'opcache.fast_shutdown=1'; \
        echo 'opcache.enable_cli=1'; \
    } > /usr/local/etc/php/conf.d/opcache-recommended.ini


RUN { \
        echo 'upload_max_filesize = 100M'; \
        echo 'post_max_size = 100M'; \
    } > /usr/local/etc/php/conf.d/cutom.ini


CMD mkdir -p /var/www/indago

VOLUME /var/www/indago

CMD chown -R www-data:www-data /var/www/indago

WORKDIR /var/www/indago

#RUN usermod -u 1000 www-data
#USER www-data

CMD ["php-fpm"]

和default.conf

server {
    server_name indago-local.com www.indago-local.com;
    root /var/www/indago/web;

    location / {
        # try to serve file directly, fallback to app.php
        try_files $uri /app_dev.php$is_args$args;
    }
    # DEV
    # This rule should only be placed on your development environment
    # In production, don't include this and don't deploy app_dev.php or config.php
    location ~ ^/(app_dev|config)\.php(/|$) {
        fastcgi_pass web:9000;
        fastcgi_split_path_info ^(.+\.php)(/.*)$;
        include fastcgi_params;
        # When you are using symlinks to link the document root to the
        # current version of your application, you should pass the real
        # application path instead of the path to the symlink to PHP
        # FPM.
        # Otherwise, PHP's OPcache may not properly detect changes to
        # your PHP files (see https://github.com/zendtech/ZendOptimizerPlus/issues/126
        # for more information).
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    }
    # PROD
    location ~ ^/app\.php(/|$) {
        fastcgi_pass web:9000;
        fastcgi_split_path_info ^(.+\.php)(/.*)$;
        include fastcgi_params;
        # When you are using symlinks to link the document root to the
        # current version of your application, you should pass the real
        # application path instead of the path to the symlink to PHP
        # FPM.
        # Otherwise, PHP's OPcache may not properly detect changes to
        # your PHP files (see https://github.com/zendtech/ZendOptimizerPlus/issues/126
        # for more information).
        fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
        fastcgi_param DOCUMENT_ROOT $realpath_root;
        # Prevents URIs that include the front controller. This will 404:
        # http://domain.tld/app.php/some-path
        # Remove the internal directive to allow URIs like this
        internal;
    }

    # return 404 for all other php files not matching the front controller
    # this prevents access to other php files you don't want to be accessible.
    location ~ \.php$ {
      return 404;
    }

    error_log /var/log/nginx/project_error.log;
    access_log /var/log/nginx/project_access.log;
}

在www.conf中,我更新了pm.max_children = 20

nginx.conf非常简单(事实上,并没有改变任何东西)

user www-data;
worker_processes 4;
pid /run/nginx.pid;

events {
  worker_connections  2048;
  multi_accept on;
  use epoll;
}

http {
  server_tokens off;
  sendfile on;
  tcp_nopush on;
  tcp_nodelay on;
  keepalive_timeout 15;
  types_hash_max_size 2048;
  include /etc/nginx/mime.types;
  default_type application/octet-stream;
  access_log on;
  error_log on;
  gzip on;
  gzip_disable "msie6";
  include /etc/nginx/conf.d/*.conf;
  include /etc/nginx/sites-available/*;
  open_file_cache max=100;
}

作为一些额外的信息,fpm容器上的memmory没有交换,我在任何地方都没有出现任何错误(在我抽空儿童数量之前,我最大限度地利用它们)

提前感谢您对如何解决它的想法。

0 个答案:

没有答案