Performance optimization and scaling strategy for your Magento2 Shop

Low resources environments optimization

  • OS : about 300Mb
  • MySQL: around 1Gb
  • PHP (mostly during the CRON runs): depends on your PHP limit but can go up to 512Mb during CRON runs, up to 756Mb when deploying and up to 2Gb when installing some plugins)
  • Zend OPCache: 128Mb minimum (recommended 512MB)
  • PHP-FPM processes: about 100Mb per child (let’s count 110 to be safe)
  • Redis: 100Mb
  • Varnish: 256Mb
pm = ondemand

Settings and strategies to look at when you increase your server resources

  • increasing pm.max_children: to handle concurrent connections you definitely need more than 5 max children. If you have a 4Gb machine I would raise to 15, 8Gb 50 … let it run and fine tune over time.
  • moving to a static process manager: this will keep all children alive instead of terminating them after the timeout. The advantage is that when traffic augments, your children are ready to accept the load, there is no need to spawn new ones and get the overhead from that activity.
  • increasing Varnish cache memory: from 128Mb get back to the recommended 256Mb max cache
  • activate Zend OPCache: activate operations caching and give it a 128Mb memory space to start with
  • serve static and media folders from a CDN
  • decouple your database from your application instance
  • use a dedicated elasticsearch instance if you have a huge catalog to handle searches
  • use a dedicated redis instance for session caching
  • use a dedicated Varnish instance for full page caching
[11-Oct-2019 10:05:24] WARNING: [pool www] server reached pm.max_children setting (35), consider raising it

Auto-scaling and High Availability strategy

  • Database replication in a different availability zone
  • Redis session caching replication in a different availability zone
  • Load balancer directing traffic to 2 or more different availability zones (2 different subnets)

Conclusion

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store