Threads in PHP - will change the world

2,013 views 43 slides May 22, 2014
Slide 1
Slide 1 of 69
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12
Slide 13
13
Slide 14
14
Slide 15
15
Slide 16
16
Slide 17
17
Slide 18
18
Slide 19
19
Slide 20
20
Slide 21
21
Slide 22
22
Slide 23
23
Slide 24
24
Slide 25
25
Slide 26
26
Slide 27
27
Slide 28
28
Slide 29
29
Slide 30
30
Slide 31
31
Slide 32
32
Slide 33
33
Slide 34
34
Slide 35
35
Slide 36
36
Slide 37
37
Slide 38
38
Slide 39
39
Slide 40
40
Slide 41
41
Slide 42
42
Slide 43
43
Slide 44
44
Slide 45
45
Slide 46
46
Slide 47
47
Slide 48
48
Slide 49
49
Slide 50
50
Slide 51
51
Slide 52
52
Slide 53
53
Slide 54
54
Slide 55
55
Slide 56
56
Slide 57
57
Slide 58
58
Slide 59
59
Slide 60
60
Slide 61
61
Slide 62
62
Slide 63
63
Slide 64
64
Slide 65
65
Slide 66
66
Slide 67
67
Slide 68
68
Slide 69
69

About This Presentation

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 ...


Slide Content

Threads in PHP
„will changes the world“

Stefan Willkommer
Co-Founder and CTO
wagner_tim78
@
Tim Wagner
Co-Founder and Lead Architect
@
swillkommer

Tiger
Sissi
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

PHP5.3+

compiledthread-safe
--enable-maintainer-zts

PECLextension
pthreads

my first
THREAD

my first
THREAD

What is a
STACKABLE

enablingsharingandsynchronizing
DataoverTHREADS

taskswhichcanbeprocessed
byaWORKER

What can be
SHARED

everythingwhichis
SERIALIZABLE

sharing Data
with a
Stackable

sharing Data
with a
Stackable

sharing Data
with a
Stackable

What is a
WORKER

allowsstackingof
DATA

likea
QUEUE

using a
Worker

using a
Worker

SYNCHRONISATION
and
CONCURRENCY
HANDLING

waiting for Threads with
join()

enableswaitingforoneormore
THREADS

makessurethatresultisavailablein
THREAD

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

GOOD
everything
is
BAD

Runtime ApplicationServer PersistenceContainer Web MQ Objects WebServer Worker Threads Socket!
0.0.0.0:8587 Socket!
0.0.0.0:8585 Socket!
0.0.0.0:8586 HTTPRemoteMethodMessageTimer 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
milliseconds
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
milliseconds
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?