threads in php - will change the world

69
Threads in PHP „will changes the world“

Upload: techdivision-gmbh

Post on 08-May-2015

1.220 views

Category:

Internet


1 download

DESCRIPTION

In August 2012 Joe Watkins introduced the Pthreads extension for PHP. Since then it is possible to use threads for asynchronous data handling in PHP as well. Now the extension is in a very promising state so it is definitely a look worth. The talk will show you the basics of using threads in PHP on the base of some real world examples. We will also have a look into interesting fields of future use. As parallelization and asynchronity is becoming more and more important this is a good way to step into some very interesting an promising fields.

TRANSCRIPT

Page 1: Threads in PHP - will change the world

Threads in PHP „will changes the world“

Page 2: Threads in PHP - will change the world

Stefan WillkommerCo-Founder and CTO

wag

ner_t

im78

@

Tim WagnerCo-Founder and Lead Architect

@

swillkommer

Page 3: Threads in PHP - will change the world

TigerSissi

me ;)Annette

Uschi

me ah Tim

Barbecue

Page 4: Threads in PHP - will change the world
Page 5: Threads in PHP - will change the world

Let’s DIFFERENTIATE

Page 6: Threads in PHP - will change the world

EVENTLOOPS

Page 7: Threads in PHP - will change the world

FORKS

Page 8: Threads in PHP - will change the world

THREADS

Page 9: Threads in PHP - will change the world

What is a THREAD

Page 10: Threads in PHP - will change the world

Process-Model without THREADS

Page 11: Threads in PHP - will change the world

Process-Model with THREADS

Page 12: Threads in PHP - will change the world

What do we

NEED

Page 13: Threads in PHP - will change the world

PHP 5.3+

Page 14: Threads in PHP - will change the world

compiled thread-safe--enable-maintainer-zts

Page 15: Threads in PHP - will change the world

PECL extensionpthreads

Page 16: Threads in PHP - will change the world
Page 17: Threads in PHP - will change the world

my first THREAD

Page 18: Threads in PHP - will change the world

my first THREAD

Page 19: Threads in PHP - will change the world

What is a STACKABLE

Page 20: Threads in PHP - will change the world

enabling sharing and synchronizingData over THREADS

Page 21: Threads in PHP - will change the world

tasks which can be processedby a WORKER

Page 22: Threads in PHP - will change the world

What can be SHARED

Page 23: Threads in PHP - will change the world

everything which is

SERIALIZABLE

Page 24: Threads in PHP - will change the world

sharing Data with a Stackable

Page 25: Threads in PHP - will change the world

sharing Data with a Stackable

Page 26: Threads in PHP - will change the world

sharing Data with a Stackable

Page 27: Threads in PHP - will change the world

What is a WORKER

Page 28: Threads in PHP - will change the world

allows stacking ofDATA

Page 29: Threads in PHP - will change the world

like aQUEUE

Page 30: Threads in PHP - will change the world

using a Worker

Page 31: Threads in PHP - will change the world

using a Worker

Page 32: Threads in PHP - will change the world

SYNCHRONISATION and

CONCURRENCY HANDLING

Page 33: Threads in PHP - will change the world

waiting for Threads with join()

Page 34: Threads in PHP - will change the world

enables waiting for one or moreTHREADS

Page 35: Threads in PHP - will change the world

makes sure that result is available inTHREAD

Page 36: Threads in PHP - will change the world

waiting by using Join

Page 37: Threads in PHP - will change the world

waiting by using Join

Page 38: Threads in PHP - will change the world

waiting by using Join

Page 39: Threads in PHP - will change the world

synchronizing Threads with synchronized()

Page 40: Threads in PHP - will change the world

synchronize with synchronized()

Page 41: Threads in PHP - will change the world

synchronize with synchronized()

Page 42: Threads in PHP - will change the world

synchronize with synchronized()

Page 43: Threads in PHP - will change the world

concurrency handling by using MUTEX

Page 44: Threads in PHP - will change the world

synchronize with Mutex

Page 45: Threads in PHP - will change the world

synchronize with Mutex

Page 46: Threads in PHP - will change the world

synchronize with Mutex

Page 47: Threads in PHP - will change the world

sharing Resources

Page 48: Threads in PHP - will change the world

sharing Sockets

Page 49: Threads in PHP - will change the world

sharing Sockets

Page 50: Threads in PHP - will change the world

sharing Sockets

Page 51: Threads in PHP - will change the world

What to do with all these

POSSIBILITIES

Page 52: Threads in PHP - will change the world
Page 53: Threads in PHP - will change the world
Page 54: Threads in PHP - will change the world
Page 55: Threads in PHP - will change the world

GOODeverything

is

BAD

Page 56: Threads in PHP - will change the world
Page 57: Threads in PHP - will change the world
Page 58: Threads in PHP - will change the world

RuntimeApplicationServerPersistenceContainer Web

MQ Objects WebServer

Worker Threads

Socket!0.0.0.0:8587

Socket!0.0.0.0:8585

Socket!0.0.0.0:8586

HTTPRemoteMethodMessage

Timer

MBeans!SBeans!

!

Worker

Page 59: Threads in PHP - will change the world
Page 60: Threads in PHP - will change the world

Performance comparison

Test Profile

Setup: 1 Webserver + 1 DB Server Virtualisation: KVM / Intel Xeon / 4 Cores OS: Debian wheezy Magento: 1.13.1.0 EE Amount of Products: 10,000

mill

isec

onds

0

65

130

195

260

Homepage Category Page Detailpage

AS, mod PHP nginx, PHP FPM

Page 61: Threads in PHP - will change the world

The power of

MEMORY

Page 62: Threads in PHP - will change the world

Performance comparison

Test Profile

Setup: 1 Webserver + 1 DB Server Virtualisation: KVM / Intel Xeon / 4 Cores OS: Debian wheezy Magento: 1.13.1.0 EE Amount of Products: 10,000

mill

isec

onds

0

65

130

195

260

Homepage Category Page Detailpage

AS, Mage Servlet nginx, PHP FPM

Page 63: Threads in PHP - will change the world

60%in average about

faster

Page 64: Threads in PHP - will change the world
Page 65: Threads in PHP - will change the world
Page 66: Threads in PHP - will change the world

280%in average about

faster

Page 67: Threads in PHP - will change the world

What’s

NEXT?

Page 68: Threads in PHP - will change the world

https://github.com/techdivision/phptek_2014 https://github.com/krakjoe/pthreads https://computing.llnl.gov/tutorials/pthreads/ http://appserver.io https://github.com/techdivision/TechDivision_ApplicationServer

Ressources

Page 69: Threads in PHP - will change the world

Thank you! Questions?