Transcript
Page 1: Threads in PHP will change the world - appserver.io

Threads in PHP „will changes the world“

Page 2: Threads in PHP will change the world - appserver.io

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

TigerSissi

me ;)Annette

Uschi

me ah Tim

Barbecue

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

Let’s

DIFFERENTIATE

Page 6: Threads in PHP will change the world - appserver.io
Page 7: Threads in PHP will change the world - appserver.io

EVENTLOOPS

Page 8: Threads in PHP will change the world - appserver.io

FORKS

Page 9: Threads in PHP will change the world - appserver.io

THREADS

Page 10: Threads in PHP will change the world - appserver.io
Page 11: Threads in PHP will change the world - appserver.io

What is a

THREAD

Page 12: Threads in PHP will change the world - appserver.io

Process-Model without

THREADS

Page 13: Threads in PHP will change the world - appserver.io

Process-Model with

THREADS

Page 14: Threads in PHP will change the world - appserver.io

What do we

NEED

Page 15: Threads in PHP will change the world - appserver.io
Page 16: Threads in PHP will change the world - appserver.io

PHP 5.3+

Page 17: Threads in PHP will change the world - appserver.io

compiled thread-safe--enable-maintainer-zts

Page 18: Threads in PHP will change the world - appserver.io

PECL extensionpthreads

Page 19: Threads in PHP will change the world - appserver.io
Page 20: Threads in PHP will change the world - appserver.io
Page 21: Threads in PHP will change the world - appserver.io
Page 22: Threads in PHP will change the world - appserver.io

my first

THREAD

Page 23: Threads in PHP will change the world - appserver.io

my first

THREAD

Page 24: Threads in PHP will change the world - appserver.io

What is a

STACKABLE

Page 25: Threads in PHP will change the world - appserver.io
Page 26: Threads in PHP will change the world - appserver.io

enabling sharing and synchronizingData over THREADS

Page 27: Threads in PHP will change the world - appserver.io
Page 28: Threads in PHP will change the world - appserver.io

tasks which can be processedby a WORKER

Page 29: Threads in PHP will change the world - appserver.io
Page 30: Threads in PHP will change the world - appserver.io

What can be

SHARED

Page 31: Threads in PHP will change the world - appserver.io
Page 32: Threads in PHP will change the world - appserver.io

everything which is

SERIALIZABLE

Page 33: Threads in PHP will change the world - appserver.io
Page 34: Threads in PHP will change the world - appserver.io

sharing Data with a

Stackable

Page 35: Threads in PHP will change the world - appserver.io

sharing Data with a

Stackable

Page 36: Threads in PHP will change the world - appserver.io

sharing Data with a

Stackable

Page 37: Threads in PHP will change the world - appserver.io

What is a

WORKER

Page 38: Threads in PHP will change the world - appserver.io
Page 39: Threads in PHP will change the world - appserver.io

allows stacking ofDATA

Page 40: Threads in PHP will change the world - appserver.io

like aQUEUE

Page 41: Threads in PHP will change the world - appserver.io
Page 42: Threads in PHP will change the world - appserver.io

using a

Worker

Page 43: Threads in PHP will change the world - appserver.io

using a

Worker

Page 44: Threads in PHP will change the world - appserver.io

SYNCHRONISATION and

CONCURRENCY HANDLING

Page 45: Threads in PHP will change the world - appserver.io

waiting for Threads with

join()

Page 46: Threads in PHP will change the world - appserver.io
Page 47: Threads in PHP will change the world - appserver.io

enables waiting for one or moreTHREADS

Page 48: Threads in PHP will change the world - appserver.io

makes sure that result is available inTHREAD

Page 49: Threads in PHP will change the world - appserver.io
Page 50: Threads in PHP will change the world - appserver.io

waiting by using

Join

Page 51: Threads in PHP will change the world - appserver.io

waiting by using

Join

Page 52: Threads in PHP will change the world - appserver.io

waiting by using

Join

Page 53: Threads in PHP will change the world - appserver.io

synchronizing Threads with

synchronized()

Page 54: Threads in PHP will change the world - appserver.io

synchronize with synchronized()

Page 55: Threads in PHP will change the world - appserver.io

synchronize with synchronized()

Page 56: Threads in PHP will change the world - appserver.io

synchronize with

synchronized()

Page 57: Threads in PHP will change the world - appserver.io

concurrency handling by using

MUTEX

Page 58: Threads in PHP will change the world - appserver.io

synchronize with

Mutex

Page 59: Threads in PHP will change the world - appserver.io

synchronize with

Mutex

Page 60: Threads in PHP will change the world - appserver.io

synchronize with

Mutex

Page 61: Threads in PHP will change the world - appserver.io

sharing

Resources

Page 62: Threads in PHP will change the world - appserver.io

sharing Sockets

Page 63: Threads in PHP will change the world - appserver.io

sharing Sockets

Page 64: Threads in PHP will change the world - appserver.io

sharing Sockets

Page 65: Threads in PHP will change the world - appserver.io

What to do with all these

POSSIBILITIES

Page 66: Threads in PHP will change the world - appserver.io
Page 67: Threads in PHP will change the world - appserver.io
Page 68: Threads in PHP will change the world - appserver.io
Page 69: Threads in PHP will change the world - appserver.io

GOODeverything

is

BAD

Page 70: Threads in PHP will change the world - appserver.io
Page 71: Threads in PHP will change the world - appserver.io
Page 72: Threads in PHP will change the world - appserver.io

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 73: Threads in PHP will change the world - appserver.io
Page 74: Threads in PHP will change the world - appserver.io

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 75: Threads in PHP will change the world - appserver.io

The power of

MEMORY

Page 76: Threads in PHP will change the world - appserver.io

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 77: Threads in PHP will change the world - appserver.io

60%in average about

faster

Page 78: Threads in PHP will change the world - appserver.io
Page 79: Threads in PHP will change the world - appserver.io
Page 80: Threads in PHP will change the world - appserver.io

280%in average about

faster

Page 81: Threads in PHP will change the world - appserver.io

What’s

NEXT?

Page 82: Threads in PHP will change the world - appserver.io

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 83: Threads in PHP will change the world - appserver.io

Thank you!

Questions?


Recommended