Skip to content

Commit

Permalink
WPK-17 – configure Redis caching (+ opcache)
Browse files Browse the repository at this point in the history
  • Loading branch information
NoelLH committed May 18, 2022
1 parent 010c4a8 commit a3ee227
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 23 deletions.
4 changes: 3 additions & 1 deletion .env
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ APP_SECRET=replace-with-your-secret
DATABASE_URL=postgresql://wpackagist_local:wpLocalPassword@db:/wpackagist_local
###< doctrine/doctrine-bundle ###

# Deployed envs use an EFS-mounted path so that all instances share data.
# Only used if you turn off using the database, e.g. for isolated local testing.
PACKAGE_PATH=/var/www/html/packages

REDIS_HOST=redis

PUBLIC_DIR=web
4 changes: 4 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ RUN apt-get update -qq && \
RUN docker-php-ext-configure pgsql -with-pgsql=/usr/local/pgsql \
&& docker-php-ext-install intl mbstring pdo_pgsql

RUN docker-php-ext-enable opcache

RUN pecl install redis && rm -rf /tmp/pear && docker-php-ext-enable redis

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

Expand Down
14 changes: 9 additions & 5 deletions config/packages/cache.yaml
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
framework:
cache:
# Unique name of your app: used to compute stable namespaces for cache keys.
#prefix_seed: your_vendor_name/app_name
prefix_seed: "wpackagist/%env(APP_ENV)%"

# The "app" cache stores to the filesystem by default.
# The data in this cache should persist between deploys.
# Other options include:

# Redis
#app: cache.adapter.redis
#default_redis_provider: redis://localhost
app: cache.adapter.redis
system: cache.adapter.redis
default_redis_provider: "redis://%env(REDIS_HOST)%"

# APCu (not recommended with heavy random-write workloads as memory fragmentation can cause perf issues)
#app: cache.adapter.apcu

# Namespaced pools use the above "app" backend by default
#pools:
#my.dedicated.cache: null
pools:
doctrine.result_cache_pool:
adapter: cache.app
doctrine.system_cache_pool:
adapter: cache.system
8 changes: 0 additions & 8 deletions config/packages/prod/doctrine.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,3 @@ doctrine:
result_cache_driver:
type: pool
pool: doctrine.result_cache_pool

framework:
cache:
pools:
doctrine.result_cache_pool:
adapter: cache.app
doctrine.system_cache_pool:
adapter: cache.system
8 changes: 0 additions & 8 deletions config/packages/stg/doctrine.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,3 @@ doctrine:
result_cache_driver:
type: pool
pool: doctrine.result_cache_pool

framework:
cache:
pools:
doctrine.result_cache_pool:
adapter: cache.app
doctrine.system_cache_pool:
adapter: cache.system
17 changes: 17 additions & 0 deletions config/php/php.ini
Original file line number Diff line number Diff line change
@@ -1,2 +1,19 @@
memory_limit = -1
date.timezone = "UTC"

; See https://secure.php.net/manual/en/opcache.configuration.php#ini.opcache.max-accelerated-files
; and https://www.scalingphpbook.com/blog/2014/02/14/best-zend-opcache-settings.html
opcache.max_accelerated_files = 7963

; We have a good amount of memory available, so increase this from the default 128MB
opcache.memory_consumption = 384

; Increase from default 8MB
opcache.interned_strings_buffer = 32

; As recommended by https://secure.php.net/manual/en/opcache.installation.php and
; https://www.scalingphpbook.com/blog/2014/02/14/best-zend-opcache-settings.html
opcache.fast_shutdown = 1

; Task definition artifacts are immutable on ECS and cache check time is 0 on local -> may as well make tasks faster
opcache.enable_cli = 1
2 changes: 1 addition & 1 deletion config/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# Put parameters here that don't need to change on each machine where the app is deployed
# https://symfony.com/doc/current/best_practices/configuration.html#application-related-configuration
parameters:
wpackagist.packages.path: '%env(resolve:PACKAGE_PATH)%'
wpackagist.packages.path: '%env(resolve:PACKAGE_PATH)%' # Not used any more except for a subset of local dev.

services:
# default configuration for services in *this* file
Expand Down
4 changes: 4 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ services:
- 5432:5432
env_file:
- .env.postgres.local
redis:
image: redis:6.2
cron:
build:
context: .
Expand All @@ -28,6 +30,7 @@ services:
- .env.local
depends_on:
- db
- redis
web:
build:
context: .
Expand All @@ -41,6 +44,7 @@ services:
- .env.local
depends_on:
- db
- redis
adminer:
image: adminer
ports:
Expand Down

0 comments on commit a3ee227

Please sign in to comment.