Scaling PHP and Drupal
Handrus Nogueira
handrus@taller.net.br
@handrus
Lucas Arruda
lucas@ciandt.com
@lunascarruda
Handrus
Based on Florianópolis-SC / BR
Software Architect / Dev @ Taller
Web & Open-Source & Agile
~11 yrs on the road
Drupaler for ~7 yrs
Dev with Passion!
Lucas Arruda
Software Architect @ CI&T DCO
Open-Source enthusiast
Acquia Certified Developer
Based on Campinas-SP / Brazil
Zend Certified Engineer PHP 5.3
Drupaler for 4+ yrs
GCP Authorized Trainer & Qualified Dev.
The Basics
Use the latest PHP stable version
Source: https://blog.asmallorange.com/2013/08/php-roadmap-performance/
Use the latest PHP stable version
Source: https://www.lourdas.name/blog/php-53-vs-54-vs-55-speed-and-memory-usage
Source: http://php.net/manual/en/features.gc.performance-considerations.php
Use the latest PHP stable version
Source: http://www.lornajane.net/posts/2014/php-5-6-benchmarks
Source: http://zsuraski.blogspot.com.au/2014/07/benchmarking-phpng.html
Source: https://kinsta.com/blog/hhvm-vs-php-7/
Disable unnecessary PHP extensions and web-server modules
● PHP extensions consume memory heap
● Some badly written can cause memory leaks
● The same applies for web-server modules
● Disable if you don’t need them!
2Read: http://www.slideshare.net/jpauli/help-im-leaking-memory-in-php
Fine tune your php.ini!
● memory_limit
memory_get_usage() / memory_get_peak_usage()
● realpath_cache_size
realpath_cache_get()
● realpath_cache_ttl
Max execution per thread - will affect memory usage!
mod_php
vs.
FastCGI
vs.
PHP-FPM
Apache
vs.
Nginx
2Read: http://www.prinew.com/mod-php-vs-fastcgi-vs-php-fpm-for-web-server-scripting/
PHP ACCELERATORS
Alternative PHP Cache (APC)
Zend OPcache
XCache
apc.shm_size
apc.ttl
apc.num_files_hint
apc.gc_ttl
apc.max_file_size
apc.stat
APC
2Read: https://www.scalingphpbook.com/best-zend-opcache-settings-tuning-config/
● Is PHP really your bottleneck?
● Same memory, less CPU
● Great for authenticated users.
● Some problems with NGINX (solvable!)
● Great resume: http://alexrayu.com/blog/drupal-hhvm
Scaling Drupal
Horizontally
(“Cattles, not Pets”)
Points of Attention
● Session
● Files
● Database
● Authenticated Users
Authenticated Users
- AuthCache contrib module
- Memcache
- AJAX
Database
- MySQL Read Replicas
+ AutoSlave contrib module
+ Orbital Cache Nuke (OCN)
Files
- Rsync bi-directional replication
- NFS shared mount
- Cloud-based solution (S3/GCS)
Session
- Drupal handes it beautifully
- Session is stored on Database
- Memcache to cache tables
Avoid database specific
queries.
Use Drupal`s built-in
Database API whenever
possible!
Avoid db_query(), always
prefer specific functions.
And choose well
your database!!
● MySQL
● MariaDB
● PerconaDB
Version?!
How dependent of your actual
environment are you?
timezonepaths connection string
limits
timeouts
Number of triesAPI Keys
Caching Mechanisms
Redis
Specially useful for entities
Memcache
for key/value storage
URI -> HTML output, Session data
tmpfs/ramfs
for all filesystem (I/O intensive) based
caching like Boost.
Use Drupal’s
built-in
Cache API
Reverse proxy caching
Nginx Varnish
Some modules that
break reverse caching
Adaptive Image - Since it detects browser to serve
image the reverse proxy will cache the first
occurence.
Text Size - Use cookies to store user choosen size.
Recaptcha - Use cookie to store valid challenge.
Key phrases:
“Depends on cookies”
“Browser detection”
Drupal Queue
API
Helpful Modules
RULES!
:-D
https://www.drupal.org/project/httprl
https://www.drupal.org/project/httprl
Profiling is about Measuring!
XHProf
Q&A
ciandt.com
Presentation Deck
http://goo.gl/0cV1KT
THANKS
FOR
BEING
HERE!
Please evaluate this presentation!
http://goo.gl/P8ZDfc
(3 questions only)
@lunascarruda
drupal.org/u/larruda
lunascar@gmail.com
google.com/+LucasArruda
fb.com/lucasnarruda
linkedin.com/in/larruda
github.com/larruda
@handrus
drupal.org/u/handrus
handrus@gmail.com
google.com/+HandrusNogueira
fb.com/handrus
linkedin.com/in/handrus
github.com/handrus

Escalando php e drupal- performance ao infinito e além! - Drupal camp sp 2015