scaling php - intercon php

31
Scaling PHP Lucas Arruda [email protected] @lunascarruda Handrus Nogueira [email protected] @handrus

Upload: handrus-nogueira

Post on 21-Jun-2015

744 views

Category:

Technology


4 download

DESCRIPTION

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

TRANSCRIPT

Page 1: Scaling php - Intercon php

Scaling PHP

Lucas [email protected]

@lunascarruda

Handrus [email protected]

@handrus

Page 2: Scaling php - Intercon php

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.

Page 3: Scaling php - Intercon php

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

Page 4: Scaling php - Intercon php

The Basics

Page 5: Scaling php - Intercon php

Use the latest PHP stable version

Page 6: Scaling php - Intercon php

Use the latest PHP stable version

Page 7: Scaling php - Intercon php

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!

Page 8: Scaling php - Intercon 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!

Page 9: Scaling php - Intercon php

mod_phpvs.

FastCGIvs.

PHP-FPM

Page 10: Scaling php - Intercon php

ob_flush()flush()

?

Page 11: Scaling php - Intercon php

PHP ACCELERATORS

Page 12: Scaling php - Intercon php

Alternative PHP Cache (APC)

Zend OPcache

XCache

Page 13: Scaling php - Intercon php

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

Page 14: Scaling php - Intercon php
Page 15: Scaling php - Intercon php

Zephir

Page 16: Scaling php - Intercon php

Scaling PHPHorizontally

Page 17: Scaling php - Intercon php

Does your app use session data?

No: you’re good to go!

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

Page 18: Scaling php - Intercon php

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

Page 19: Scaling php - Intercon php

Options

Shared file-systemDatabaseMemcache / Redis

session.name

session.save_handler

session.save_path

Sharing session data

Handlers

filesusermemcache

Page 20: Scaling php - Intercon php

Avoid database specific queries.

Good libraries can help (Doctrine FTW!)

If not possible Document like any Technical Debt!

Page 21: Scaling php - Intercon php

And choose wellyour database!!

● MySQL● MariaDB● PerconaDB

Version?!

Page 22: Scaling php - Intercon php
Page 23: Scaling php - Intercon php

How dependent of your actual environment are you?

timezonepaths connection stringlimits

timeouts

Number of triesAPI Keys

Page 24: Scaling php - Intercon php

Caching Mechanisms

Page 25: Scaling php - Intercon php

APCfor caching user data

Memcachefor key/value storage (URI/HTML?)

tmpfs/ramfsfor all file-based caching

Page 26: Scaling php - Intercon php

Reverse proxying

Nginx Varnish

Page 27: Scaling php - Intercon php
Page 29: Scaling php - Intercon php

Q&Aciandt.com

Presentation Deckhttp://goo.gl/0cV1KT

Page 30: Scaling php - Intercon php

THANKS FOR

BEINGHERE!

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

(3 questions only)

Page 31: Scaling php - Intercon php

@lunascarruda

[email protected]

google.com/+LucasArruda

fb.com/lucasnarruda

linkedin.com/in/larruda

github.com/larruda

coderbits.com/larruda

@handrus

[email protected]

google.com/+HandrusNogueira

fb.com/handrus

linkedin.com/in/handrus

github.com/handrus

coderbits.com/handrus