going beyond lamp again - manchester wordpress user group

34
COMPANY NAME PRESENTATION TITLE 12 - 12 - 2012 TimNash.co.uk @tnash #beyondLAMP LAMP To speed things up a bit Going Beyond...

Upload: tim-nash

Post on 08-May-2015

245 views

Category:

Documents


4 download

TRANSCRIPT

Page 1: Going Beyond LAMP Again - Manchester WordPress User Group

C O M PA N Y N A M E P R E S E N TAT I O N T I T L E 1 2 - 1 2 - 2 0 1 2TimNash.co.uk @tnash #beyondLAMP

LAMP To speed things up a bit

Going Beyond...

Page 2: Going Beyond LAMP Again - Manchester WordPress User Group

C O M PA N Y N A M E P R E S E N TAT I O N T I T L E 1 2 - 1 2 - 2 0 1 2TimNash.co.uk @tnash #beyondLAMP

Going beyond shared hosts

Page 3: Going Beyond LAMP Again - Manchester WordPress User Group

C O M PA N Y N A M E P R E S E N TAT I O N T I T L E 1 2 - 1 2 - 2 0 1 2TimNash.co.uk @tnash #beyondLAMP

WHERE TO PLAY?

Cheap VPS/Dedicated Box

Vagrant

Use third party services

PAAS hosting

Page 4: Going Beyond LAMP Again - Manchester WordPress User Group

C O M PA N Y N A M E P R E S E N TAT I O N T I T L E 1 2 - 1 2 - 2 0 1 2TimNash.co.uk @tnash #beyondLAMP

LAMP Linux

ApacheMySQL

PHP

Page 5: Going Beyond LAMP Again - Manchester WordPress User Group

C O M PA N Y N A M E P R E S E N TAT I O N T I T L E 1 2 - 1 2 - 2 0 1 2TimNash.co.uk @tnash #beyondLAMP

L[AMP] Linux

ApacheMySQL

PHP

Page 6: Going Beyond LAMP Again - Manchester WordPress User Group

C O M PA N Y N A M E P R E S E N TAT I O N T I T L E 1 2 - 1 2 - 2 0 1 2TimNash.co.uk @tnash #beyondLAMP

WIMP Windows

IISMySQL

PHP

REALLY!!!

OMG You like Serious init!

CRAZY??

Page 7: Going Beyond LAMP Again - Manchester WordPress User Group

C O M PA N Y N A M E P R E S E N TAT I O N T I T L E 1 2 - 1 2 - 2 0 1 2TimNash.co.uk @tnash #beyondLAMP

[AMP] “Use the best tool for the job...

...Not just the most popular”- almost certainly an engineer

Page 8: Going Beyond LAMP Again - Manchester WordPress User Group

C O M PA N Y N A M E P R E S E N TAT I O N T I T L E 1 2 - 1 2 - 2 0 1 2TimNash.co.uk @tnash #beyondLAMP

[AMP] “You don’t dig latrines with a swiss army knife”

Page 9: Going Beyond LAMP Again - Manchester WordPress User Group

C O M PA N Y N A M E P R E S E N TAT I O N T I T L E 1 2 - 1 2 - 2 0 1 2TimNash.co.uk @tnash #beyondLAMP

ANGINX HTTP and Proxy Server

Page 10: Going Beyond LAMP Again - Manchester WordPress User Group

C O M PA N Y N A M E P R E S E N TAT I O N T I T L E 1 2 - 1 2 - 2 0 1 2TimNash.co.uk @tnash #beyondLAMP

AApache is like Microsoft Word, it has a million options but you only need six. Nginx does those six things, and it does five of them 50 times faster than Apache.

- Chris Lea (https://chrislea.com/)

Page 11: Going Beyond LAMP Again - Manchester WordPress User Group

C O M PA N Y N A M E P R E S E N TAT I O N T I T L E 1 2 - 1 2 - 2 0 1 2TimNash.co.uk @tnash #beyondLAMP

MMaria DB & Percona Server

Page 12: Going Beyond LAMP Again - Manchester WordPress User Group

C O M PA N Y N A M E P R E S E N TAT I O N T I T L E 1 2 - 1 2 - 2 0 1 2TimNash.co.uk @tnash #beyondLAMP

PHipHop Virtual Machine (HHVM)

Page 13: Going Beyond LAMP Again - Manchester WordPress User Group

C O M PA N Y N A M E P R E S E N TAT I O N T I T L E 1 2 - 1 2 - 2 0 1 2TimNash.co.uk @tnash #beyondLAMP

P<?hh function yieldInfiniteInts(): Continuation<int> {   $i = 0;   while (true) {     yield $i++;   } } !

$generator = yieldInfiniteInts(); foreach ($generator as $value) {   echo "$value\n"; }

http://docs.hhvm.com/manual/en/hack.continuations.php

Page 14: Going Beyond LAMP Again - Manchester WordPress User Group

C O M PA N Y N A M E P R E S E N TAT I O N T I T L E 1 2 - 1 2 - 2 0 1 2TimNash.co.uk @tnash #beyondLAMP

Pasync function getAsyncTemplatePart( $slug, $name = false ) { return get_template_part( $slug, $name ); } !

async function gatherTemplateParts($templates) { $return = array(); !

foreach( $templates as $slug => $name ) { $return[] = getAsyncTemplatePart( $slug, $name ); } !

await GenArrayWaitHandle::create($return); } !

gatherTemplateParts( $templates )->join();

Async grabbing WordPress Templates in HackLang

Page 15: Going Beyond LAMP Again - Manchester WordPress User Group

C O M PA N Y N A M E P R E S E N TAT I O N T I T L E 1 2 - 1 2 - 2 0 1 2TimNash.co.uk @tnash #beyondLAMP

Key value storesMemcached and Redis (Redis Cloud)

Page 16: Going Beyond LAMP Again - Manchester WordPress User Group

C O M PA N Y N A M E P R E S E N TAT I O N T I T L E 1 2 - 1 2 - 2 0 1 2TimNash.co.uk @tnash #beyondLAMP

id user_login user_pass user_nicename user_email …1 tim diufhdiufg£bsdh874£423223 Tim [email protected]

Traditional SQL DB

Page 17: Going Beyond LAMP Again - Manchester WordPress User Group

C O M PA N Y N A M E P R E S E N TAT I O N T I T L E 1 2 - 1 2 - 2 0 1 2TimNash.co.uk @tnash #beyondLAMP

Key : Value : Expiry (Optional) !

Tim : Geeky

Page 18: Going Beyond LAMP Again - Manchester WordPress User Group

C O M PA N Y N A M E P R E S E N TAT I O N T I T L E 1 2 - 1 2 - 2 0 1 2TimNash.co.uk @tnash #beyondLAMP

WHAT ARE THEY GOOD FOR IN WORDPRESS?

Storing replicable Data…

Transients

Caching

Job Queues backends

Page 19: Going Beyond LAMP Again - Manchester WordPress User Group

C O M PA N Y N A M E P R E S E N TAT I O N T I T L E 1 2 - 1 2 - 2 0 1 2TimNash.co.uk @tnash #beyondLAMP

Memory comes and goes especially with age!

Page 20: Going Beyond LAMP Again - Manchester WordPress User Group

C O M PA N Y N A M E P R E S E N TAT I O N T I T L E 1 2 - 1 2 - 2 0 1 2TimNash.co.uk @tnash #beyondLAMP

Transients API

Key : Value : Expiry (Optional)

Page 21: Going Beyond LAMP Again - Manchester WordPress User Group

C O M PA N Y N A M E P R E S E N TAT I O N T I T L E 1 2 - 1 2 - 2 0 1 2TimNash.co.uk @tnash #beyondLAMP

Using KSV to cache WordPress

Page 22: Going Beyond LAMP Again - Manchester WordPress User Group

C O M PA N Y N A M E P R E S E N TAT I O N T I T L E 1 2 - 1 2 - 2 0 1 2TimNash.co.uk @tnash #beyondLAMP

Rendering/ Template/Theme

Processing/ ObjectsMySQL

HTTP/ Other Services

WordPress

Page 23: Going Beyond LAMP Again - Manchester WordPress User Group

C O M PA N Y N A M E P R E S E N TAT I O N T I T L E 1 2 - 1 2 - 2 0 1 2TimNash.co.uk @tnash #beyondLAMP

Page/Fragment Caching

Object CachingQuery Cache

HTTP Caching

Caching

Page 24: Going Beyond LAMP Again - Manchester WordPress User Group

C O M PA N Y N A M E P R E S E N TAT I O N T I T L E 1 2 - 1 2 - 2 0 1 2TimNash.co.uk @tnash #beyondLAMP

Caching can and will screw with you!

Page 25: Going Beyond LAMP Again - Manchester WordPress User Group

C O M PA N Y N A M E P R E S E N TAT I O N T I T L E 1 2 - 1 2 - 2 0 1 2TimNash.co.uk @tnash #beyondLAMP

Queue ManagementBeanstalkd & Gearman

(Amazon SQS)

Page 26: Going Beyond LAMP Again - Manchester WordPress User Group

C O M PA N Y N A M E P R E S E N TAT I O N T I T L E 1 2 - 1 2 - 2 0 1 2TimNash.co.uk

1. WordPress sends job to queue 2. Job Server (Beanstalk, Gearman) Holds in a queue 3. Worker picks job from the queue and completes it

2 .

3 .1 .

QUEUE MANAGEMENT SYSTEM

Page 27: Going Beyond LAMP Again - Manchester WordPress User Group

C O M PA N Y N A M E P R E S E N TAT I O N T I T L E 1 2 - 1 2 - 2 0 1 2TimNash.co.uk

1. User clicks approve on a comment, WordPress queries the database and collects all the emails to notify and the message to send and passes it to the job server.

2. Job Server put’s the emails into a queue

3. Script calls the queue server and takes the email and message, emails the user and marks job complete, repeats until the queue is empty2 .

3 .1 .

QUEUE MANAGEMENT SYSTEM (IN PRACTICE)

Page 28: Going Beyond LAMP Again - Manchester WordPress User Group

C O M PA N Y N A M E P R E S E N TAT I O N T I T L E 1 2 - 1 2 - 2 0 1 2TimNash.co.uk @tnash #beyondLAMP

function gatherTemplateParts( $templates ){ $client = new GearmanClient(); $client->addServer(); $client->setCompleteCallback(function(GearmanTask $task, $context) use (&$return) { $return[] = $task->data(); }); !

foreach( $templates as $template ){ $client->addTask('getAsyncTemplatePart', $template ); } client->runTasks(); }

ASYNC WITH GEARMAN - CLIENT

Page 29: Going Beyond LAMP Again - Manchester WordPress User Group

C O M PA N Y N A M E P R E S E N TAT I O N T I T L E 1 2 - 1 2 - 2 0 1 2TimNash.co.uk @tnash #beyondLAMP

$worker = new GearmanWorker(); $worker->addServer(); $worker->addFunction('getAsyncTemplatePart', function(GearmanJob $job){ return get_template_part( key(), current() ); }); while ($worker->work());

ASYNC WITH GEARMAN - WORKER

Page 30: Going Beyond LAMP Again - Manchester WordPress User Group

C O M PA N Y N A M E P R E S E N TAT I O N T I T L E 1 2 - 1 2 - 2 0 1 2TimNash.co.uk @tnash #beyondLAMP

Caching reverse proxiesVarnish

(CloudFront, CloudFlare)

Page 31: Going Beyond LAMP Again - Manchester WordPress User Group

C O M PA N Y N A M E P R E S E N TAT I O N T I T L E 1 2 - 1 2 - 2 0 1 2TimNash.co.uk @tnash #beyondLAMP

CLOUDFRONT NGINX (ORIGIN)

NGINX

Server

Page 32: Going Beyond LAMP Again - Manchester WordPress User Group

C O M PA N Y N A M E P R E S E N TAT I O N T I T L E 1 2 - 1 2 - 2 0 1 2TimNash.co.uk @tnash #beyondLAMP

VARNISH NGINX (ORIGIN)

PROXY CACHING OVER SSL WITH VARNISH

NGINX SSL END POINT

Page 33: Going Beyond LAMP Again - Manchester WordPress User Group

C O M PA N Y N A M E P R E S E N TAT I O N T I T L E 1 2 - 1 2 - 2 0 1 2TimNash.co.uk @tnash #beyondLAMP

Caching can and will screw with you!

Page 34: Going Beyond LAMP Again - Manchester WordPress User Group

C O M PA N Y N A M E P R E S E N TAT I O N T I T L E 1 2 - 1 2 - 2 0 1 2TimNash.co.uk @tnash #beyondLAMP

The End! Thanks for listening and don’t forget to visit...

!

!

Slides: https://timnash.co.uk/mwug-may-2014