Skip to content

Performance degradation with sessions. Laravel 8. Docker #23

@apoldev

Description

@apoldev

Hello.
I have a docker container with RoadrRunner and Laravel 8.16.1 by default. (clean install laravel new www)

I try it many times:
ab -n 1000 -c 100 "http://serverhost:8080/"

I notice a degradation of app performance:

3113.96 [#/sec]
....
1024.88 [#/sec]
539.06 [#/sec]
439.41 [#/sec]

If i remove in Http/Kernel.php in $middlewareGroups
these lines:

\Illuminate\Session\Middleware\StartSession::class, 
\Illuminate\View\Middleware\ShareErrorsFromSession::class,
\App\Http\Middleware\VerifyCsrfToken::class, 

then performance not degrade:

Requests per second:    2844.97 [#/sec] (mean)
Time per request:       35.150 [ms] (mean)
Time per request:       0.351 [ms] (mean, across all concurrent requests)

I suppose I need to reset the sessions? Only with the default config, roadrunner-laravel does not work.
How can I do it?

Dockerfile

FROM php:7.4-cli

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

RUN apt-get update && apt-get install -y \
        curl \
  		vim \
  		libfreetype6-dev \
  		libjpeg62-turbo-dev \
  		libmcrypt-dev \
  		libpng-dev \
  		zlib1g-dev \
  		libxml2-dev \
  		libzip-dev \
  		libonig-dev \
  		graphviz \
  		libcurl4-openssl-dev \
  		pkg-config \
  		libpq-dev \
  		iputils-ping \
  		wget \
  		git

# Install PHP Extensions
RUN docker-php-ext-install -j$(nproc) iconv mbstring mysqli pdo_mysql zip \
    && docker-php-ext-install opcache \
    && docker-php-ext-enable opcache

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

# Download RoadRunner
ENV RR_VERSION 1.8.4
RUN mkdir /tmp/rr \
  && cd /tmp/rr \
  && echo "{\"require\":{\"spiral/roadrunner\":\"${RR_VERSION}\"}}" >> composer.json \
  && composer install --ignore-platform-reqs \
  && vendor/bin/rr get-binary -l /usr/local/bin \
  && rm -rf /tmp/rr

## Copy RoadRunner config
COPY config /etc/roadrunner

WORKDIR /var/www

CMD ["/usr/local/bin/rr", "serve", "-c", "/etc/roadrunner/.rr.yaml", "-w", "/var/www"]

docker-compose.yml

version: "3.7"
services:
  roadrunner:
    build: ./images/roadrunner
    container_name: "roadrunner"
    ports:
      - 8080:8080
    volumes:
      - ./www:/var/www:cached
      - ./configs/roadrunner:/etc/roadrunner:cached
    network_mode: "host"

.rr.yaml

env:
#APP_REFRESH: true

http:
  address: 0.0.0.0:8080
  workers:
    command: 'php /var/www/vendor/bin/rr-worker' # for windows: `php vendor/spiral/roadrunner-laravel/bin/rr-worker`
static:
  dir: 'public'

reload:
 interval: 1s
 patterns: [".php"]
 services:
   http:
     dirs: [""]
     recursive: true

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions