Scaling php - Intercon php

Preview:

DESCRIPTION

Talk about scalability in the php world, given at the first Intercon PHP (2014) organized by Imasters and PHPSP community.

Citation preview

Scaling PHP

Lucas Arrudalucas@ciandt.com

@lunascarruda

Handrus Nogueirahandrus@taller.net.br

@handrus

Lucas Arruda

Software Architect @ CI&T

Open-Source enthusiast

~10 yrs on the road

Based on Campinas-SP

Zend Certified Engineer PHP 5.3

Drupaler for 4 yrs

Google Cloud Platform Qualified Dev.

Handrus

Software Architect / Dev @ Taller

Open-Source and Agile

~10 yrs on the road

Based on Bauru-SP/Florianópolis-SC

Drupaler for 3 yrs

The Basics

Use the latest PHP stable version

Use the latest PHP stable version

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!

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

ob_flush()flush()

?

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 OPcache

opcache.revalidate_freq

opcache.validate_timestamps

opcache.max_accelerated_files

opcache.memory_consumption

opcache.interned_strings_buffer

opcache.fast_shutdown

XCache

xcache.size

xcache.count

xcache.slots

xcache.ttl

xcache.gc_interval

xcache.cacher

xcache.stat

xcache.var_size

xcache.var_count

xcache.var_slots

xcache.var_ttl

xcache.var_maxttl

xcache.var_gc_interval

Zephir

Scaling PHPHorizontally

Does your app use session data?

No: you’re good to go!

Yes: then you’ll need to manage this data across multiple servers.

Sharing session data

Fault tolerantNo bottleneckCheaper

buut… it needs architecure changes!

Persistent load balancing

Sharing session data

PHP Session Management

Persistent load balacing

Single point of failureBottleneckExpensive

Options

Shared file-systemDatabaseMemcache / Redis

session.name

session.save_handler

session.save_path

Sharing session data

Handlers

filesusermemcache

Avoid database specific queries.

Good libraries can help (Doctrine FTW!)

If not possible Document like any Technical Debt!

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

APCfor caching user data

Memcachefor key/value storage (URI/HTML?)

tmpfs/ramfsfor all file-based caching

Reverse proxying

Nginx Varnish

Q&Aciandt.com

Presentation Deckhttp://goo.gl/0cV1KT

THANKS FOR

BEINGHERE!

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

(3 questions only)

@lunascarruda

lunascar@gmail.com

google.com/+LucasArruda

fb.com/lucasnarruda

linkedin.com/in/larruda

github.com/larruda

coderbits.com/larruda

@handrus

handrus@gmail.com

google.com/+HandrusNogueira

fb.com/handrus

linkedin.com/in/handrus

github.com/handrus

coderbits.com/handrus