threads in php - will change the world
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
Threads in PHP „will changes the world“
Stefan WillkommerCo-Founder and CTO
wag
ner_t
im78
@
Tim WagnerCo-Founder and Lead Architect
@
swillkommer
TigerSissi
me ;)Annette
Uschi
me ah Tim
Barbecue
Let’s DIFFERENTIATE
EVENTLOOPS
FORKS
THREADS
What is a THREAD
Process-Model without THREADS
Process-Model with THREADS
What do we
NEED
PHP 5.3+
compiled thread-safe--enable-maintainer-zts
PECL extensionpthreads
my first THREAD
my first THREAD
What is a STACKABLE
enabling sharing and synchronizingData over THREADS
tasks which can be processedby a WORKER
What can be SHARED
everything which is
SERIALIZABLE
sharing Data with a Stackable
sharing Data with a Stackable
sharing Data with a Stackable
What is a WORKER
allows stacking ofDATA
like aQUEUE
using a Worker
using a Worker
SYNCHRONISATION and
CONCURRENCY HANDLING
waiting for Threads with join()
enables waiting for one or moreTHREADS
makes sure that result is available inTHREAD
waiting by using Join
waiting by using Join
waiting by using Join
synchronizing Threads with synchronized()
synchronize with synchronized()
synchronize with synchronized()
synchronize with synchronized()
concurrency handling by using MUTEX
synchronize with Mutex
synchronize with Mutex
synchronize with Mutex
sharing Resources
sharing Sockets
sharing Sockets
sharing Sockets
What to do with all these
POSSIBILITIES
GOODeverything
is
BAD
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
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
The power of
MEMORY
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
60%in average about
faster
280%in average about
faster
What’s
NEXT?
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
Thank you! Questions?