From 3127a6e91efca476da07f17b74340089a39b0239 Mon Sep 17 00:00:00 2001 From: Nyholm Date: Fri, 17 Apr 2020 17:05:45 +0200 Subject: [PATCH] Added a first attempt for a readme --- README.md | 80 ++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 79 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 0610612..d90cc16 100644 --- a/README.md +++ b/README.md @@ -12,9 +12,87 @@ composer req bref/symfony-bridge ## Usage -Update your Kernel.php +You only need to one one small change To quickly setup Symfony to work with Bref. ```diff +// src/Kernel.php + +namespace App; + +use App\Repository\Test\TestRepository; ++ Bref\SymfonyBridge\BrefKernel; +use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait; +use Symfony\Component\Config\Loader\LoaderInterface; +use Symfony\Component\Config\Resource\FileResource; +use Symfony\Component\DependencyInjection\ContainerBuilder; +-use Symfony\Component\HttpKernel\Kernel as BaseKernel; +use Symfony\Component\Routing\RouteCollectionBuilder; + - class Kernel extends BaseKernel + class Kernel extends BrefKernel +{ + // ... +``` + +Now you are up and running. + +## Optimize first request + +The first HTTP request that hits your application after you deployed a new version +will use a cold cache directory. Symfony now spends time building thc cache. It may +take everything between 1-20 seconds depending on the complexity of the application. + +Technically this happens whenever your application run on a new Lambda. That could +be when you get a lot more traffic so AWS increases the resources or when AWS just +decides to kill the lambda function (or server) that you are currently on. It is +normal that this happens at least a handful of times every day. + +To optimize the first request, one must deploy the application with a warm cache. +In a simple application it means that the deploy script should include `cache:warmup` +to look something like this: + +```bash +# Install dependencies +composer install --classmap-authoritative --no-dev --no-scripts + +# Warmup the cache +bin/console cache:warmup --env=prod + +# Disable use of Dotenv component +echo " .env.local.php + +serverless deploy +``` + +## Optimize cache + +When running Symfony on Lambda you should avoid writing to the filesystem. If +you prewarm the cache before deploy you are mostly fine. But you should also make +sure you never write to a filesystem cache like `cache.system` or use a pool like: + +```yaml +framework: + cache: + pools: + my_pool: + adapter: cache.adapter.filesystem +``` + +If you dont write to such cache pool you can optimize your setup by not copy the +`var/cache/pools` directory. The change below will make sure to symlink the `pools` +directory. + +```diff +// src/Kernel.php + + +class Kernel extends BrefKernel +{ + // ... + ++ protected function getWritableCacheDirectories(): array ++ { ++ return []; ++ } +} ```