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

42
Scaling PHP and Drupal Handrus Nogueira [email protected] @handrus Lucas Arruda [email protected] @lunascarruda

Upload: handrus-nogueira

Post on 18-Aug-2015

13 views

Category:

Software


1 download

TRANSCRIPT

Scaling PHP and Drupal

Handrus [email protected]

@handrus

Lucas [email protected]

@lunascarruda

HandrusBased 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-usageSource: 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-benchmarksSource: 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_phpvs.

FastCGIvs.

PHP-FPM

Apachevs.

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 DrupalHorizontally

(“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 wellyour database!!

● MySQL● MariaDB● PerconaDB

Version?!

How dependent of your actual environment are you?

timezonepaths connection stringlimits

timeouts

Number of triesAPI Keys

Caching Mechanisms

RedisSpecially useful for entities

Memcachefor key/value storageURI -> HTML output, Session data

tmpfs/ramfsfor 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”

Helpful Modules

RULES!:-D

Profiling is about Measuring!

XHProf

Q&Aciandt.com

Presentation Deckhttp://goo.gl/0cV1KT

THANKS FOR

BEINGHERE!

Please evaluate this presentation!http://goo.gl/P8ZDfc

(3 questions only)

@lunascarruda

drupal.org/u/larruda

[email protected]

google.com/+LucasArruda

fb.com/lucasnarruda

linkedin.com/in/larruda

github.com/larruda

@handrus

drupal.org/u/handrus

[email protected]

google.com/+HandrusNogueira

fb.com/handrus

linkedin.com/in/handrus

github.com/handrus