Making WordPress Fly

Post on 15-May-2015

1072 Views

Category:

Technology

1 Downloads

Preview:

Click to see full reader

DESCRIPTION

Stefan Didak's presentation about APC, memcached, varnish, and other tools for speeding up your WordPress site (as long as you're in charge of your own server). From the October 2013 East Bay WordPress Meetup.

Transcript

EAST BAY WORDPRESS MEETUP

HOW TO MAKE WP FLY...LIKE A BAT OUT OF HELL

Sunday, October 6, 13

THE ALTERNATIVE TITLEI could have renamed this presentation

EXPLAININGTHE SECRETS

BEHIND MANAGED HOSTING AND REALLY

FAST WORDPRESS SITES

Sunday, October 6, 13

Stefan Didakhttp://www.stefandidak.com

(“not a web developer”)

Sunday, October 6, 13

The sound a WordPress siteshould make when your client ishappy to pay you more becausetheir site is so fast that it putstheir competition to shame.

TIME = MONEY

Sunday, October 6, 13

LEVELS OF CACHINGall of those make a difference but... NOT ENOUGH

Caching provided by optimizing your site

Caching through plugins

Caching because of all of the above

As you’ve already been shown today

Sunday, October 6, 13

Everything I’m going to show today requires you to have full control and access to your server (VM, VPS, Cloud, etc.)

LEVELS OF CACHING

Don’t just optimize your site

Optimize YOUR SERVER!and if you have none, build one!

Optimize YOUR CODE TOO!

Sunday, October 6, 13

WHAT I’LL BE COVERINGAlso known as the Tip of the Iceberg

WordPress CachingDigital Ocean + DEMO

OpCode CachingApache v.s. Nginx

VarnishMemcached

Sunday, October 6, 13

WP CACHING OVERVIEWEveryone should know what levels of caching WP supports

Sunday, October 6, 13

WORDPRESS CACHINGRun-Time Cache

Only lasts the duration of the request. After the request the run-time cache no

longer exists.

For example: the global $post and $wp_query variables

Sunday, October 6, 13

WORDPRESS CACHINGTransient Cache

WordPress has a “Transient Cache” API that allows you to store data in

your MySQL DB.

Ahum... Right...

But it can still be useful...if used selectively

Sunday, October 6, 13

WORDPRESS CACHINGObject Cache

Is usually persistent because it’s stored “somewhere”.

Somewhere could be in memory through APC, Memcached, or Redis, but could also

be in your MySQL DB or on disk.

Sunday, October 6, 13

WORDPRESS CACHINGPage Cache - Stored on disk or in memory

Stores HTML data representing entire pages. This is one of the more typical

caching schemes used by most plugins.

Unfortunately, not so useful when you have highly dynamic pages where someone does

not always get the same content (i.e. membership sites).

Sunday, October 6, 13

WORDPRESS CACHINGFragment Cache

I don’t like the term and it is no different from the Object Cache. Instead of storing

entire HTML pages it stores parts of pages.

I like to think of it as just another object because that’s what it is.

Sunday, October 6, 13

PERSONAL EXPERIENCEManaged Hosting, however optimized, is still designed to be a

version of a “one size fits all” approach

I prefer to have full control over my own online servers because I can have them be

faster than managed hosting at a fraction of the cost.

Sunday, October 6, 13

GREAT PERFORMANCE& COOL PRICES

GREAT(ER) PERFORMANCE& OK PRICES

NICE PERFORMANCE& CAN GET EXPENSIVE

SLOW & EXPENSIVE

Sunday, October 6, 13

FIRST DEPLOYMENTIt was really exciting to see my first droplet come online

After running and testing my first “droplet” on Digital Ocean and after playing with some deployments on

Linode I knew my shared hosting for 30+ domains would come to an end.

A very WELCOME END!

Sunday, October 6, 13

HOSTING, BUT WHEREThe long search has come to an end

If you don’t care much about the “managed” part

of managed hosting and really want things to roar

like a bat out of hell...

Sunday, October 6, 13

STEALTH PROJECTNot to mention, Digital Ocean has a nice evolving API to

manage all your “droplets”. Not as mature as Linode, though!

Once my “stealth project” goes live I expect that within 2 years I will need

around 150 to 500 virtual servers.(virtual servers of various capacities)

Digital Ocean has the absolute best price point I’ve seen. And I’ve been

looking. Really looking.

Sunday, October 6, 13

DEMO TIME ! DEMO TIME !If this doesn’t convince you I don’t know what will

$20/mo shared hostingv.s.

$5/mo Digital Ocean Droplet

Oakley Chamber of CommerceWordPress site

(a heavy and NOT OPTIMIZED one!)

Sunday, October 6, 13

TRY IT FOR YOURSELFanyone with laptops here are encouraged to check it out

http://oakleychamber.com

http://oc.ignyter.com

Sunday, October 6, 13

YES YOU CANStop whining about the commandline and typing on the

keyboard, as if you don’t do that crap when you’re CSS’ing!!!

WAS THAT FASTOR WAS THAT FAST?

Or is it just cool to know that you can do it TOO!?

Sunday, October 6, 13

I can’t show you managed hosting vs. Digital Ocean at a $25-30/month vs. $5-10/

month price point...

BUT....Sunday, October 6, 13

I will take any bet, for any amount of serious money, that I can setup and

configure servers on Digital Ocean or Linode that beat the living daylights out of any managed hosting in terms

of performance.

And YOU can do it TOO!

So let’s not even talk aboutshared hosting anymore, ok?

Sunday, October 6, 13

COPY AND PASTEIf you can’t do copy and paste then I’m wasting your time and I

am very sorry. If you can, however... new doors will open!

I know what I’m doing and...may be biased.

I do, however, believe, that if you put in some time to learn more than what you copy & paste will serve you to be even more valuable to your clients!

Sunday, October 6, 13

INSTALLING AND RUNNINGOn how to install, configure, and run with all the things I

mentioned today, visit the libraries.

https://www.digitalocean.com/community

TUTORIALS, GUIDES, AND MORE

https://library.linode.com/

Sunday, October 6, 13

OPCODE CACHINGAnd now to explain what you’ve just seen

Sunday, October 6, 13

OPCODE CACHINGYeah, uh, sure, what what does it DO?!

What your server does for EVERY page hit on your site:

Read most (or all) of your PHP files/code

Interpret each line & “compile” it into whatthe CPU understands

Execute the “compiled” code and render out the page by sending it to the browser.

Sunday, October 6, 13

OPCODE CACHING

What your server does for EVERY page hit on your site:

Read most (or all) of your PHP files/code

Interpret each line & “compile” it into whatthe CPU understands

Execute the “compiled” code and render out the page by sending it to the browser.

Yeah, uh, sure, what what does it DO?!

Execute the “compiled” code and render out the page by sending it to the browser.

What your server does for EVERY page hit on your site:

Sunday, October 6, 13

OPCODE CACHINGThe simple explanation

PHP PARSE COMPILE EXECUTE SEND

PHPAPC

CACHEEXECUTE SEND

WITHOUT OPCODE CACHING

WITH OPCODE CACHING

Sunday, October 6, 13

OPCODE CACHINGSpeeds up your site much more than “regular” file/data caching

APCXCache

eAcceleratorZend OpCache

NuSphere PHPExpressIonCube Accelerator

Sunday, October 6, 13

BUT PHP 5.5 HAS OPCACHEPerformance between APC, XCache, etc. is all very similar

Because APC is going to be included in “PHP6”

But as we all know, there is no such thing as PHP6, right?

There is a book on PHP6.But there is no Beta of PHP6.

There isn’t even an Alpha of PHP6.

Sunday, October 6, 13

PHP APCAPC = Alternative PHP Cache

Sunday, October 6, 13

BENCHMARKING APCYour site without APC sucks donkey balls

Without APC

Req. Per Sec : 85Time Per Req. : 900msConc. Time Per Req. : 20msXfer Rate : 898 Kbytes/s

With “vanilla” APC

Req. Per Sec : 138.5Time Per Req. : 476msConc. Time Per Req. : 9.5msXfer Rate : 1265 Kbytes/s

Great, but...IS THAT ALL?

Sunday, October 6, 13

BENCHMARKING APCYour site with APC and apc.stat = off WILL FLY!

Without APC

Req. Per Sec : 85Time Per Req. : 900msConc. Time Per Req. : 20msXfer Rate : 898 Kbytes/s

With “vanilla” APC

Req. Per Sec : 138.5Time Per Req. : 476msConc. Time Per Req. : 9.5msXfer Rate : 1265 Kbytes/s

Now with apc.stat=off

Req. Per Sec : 317.4Time Per Req. : 152.1msConc. Time Per Req. : 3.1msXfer Rate : 3985 Kbytes/s

Sunday, October 6, 13

APC.STAT = OFFTHINK AND PLAN BEFORE YOU TURN IT OFF

Only turn APC.STAT to OFF if:

Your PHP code on the server does not change and you are willing to restart

the web server if it does.

WP or Plugin updates =CHANGE OF PHP CODE

Sunday, October 6, 13

RESTARTING? SO WHAT?There are other ways to deal with this but those are for another time when we get real deep into server stuff

# /etc/init.d/apache2 restart

It’s just one line. Maybe not exactly the same as this one, though.

And it’s only for a few seconds.

Sunday, October 6, 13

INSTALLING APCBecause it might be different for your flavor of server I’m not

going into too much detail here, but it’s dead easy

Ensure your server has:php-pear, php5-dev, make, apache2-prefork-dev

# pecl install apc

Then add the extension to your php.ini (or other)

extension=apc.so

Sunday, October 6, 13

CONFIGURING APCYou should tweak it as much as needed

And there’s a lot more you can tweak in APC

apc.enabled=1apc.shm_segments=1apc.shm_size=128M (or 1G, etc.)apc.ttl=3600apc.user_ttl=7200apc.gc_ttl=3600apc.max_file_size=1Mapc.stat=1 (or 0)

Sunday, October 6, 13

WORTH KNOWINGAPC will also extend PHP with new functions

With APC installed you can use PHP function calls to...

Manage the APC cacheInterrogate the APC cache

Load/Dump Binary cache data

START OPTIMIZING YOUR CODEIntegrate it selectively in your plugins

Sunday, October 6, 13

APC WITH A WP PLUGINYour mileage may vary

http://wordpress.org/plugins/apc/

APC Object Cache Backend

Place the object-cache.phpin your wp-content directory.

Optionally you can also install theBATCACHE plugin

Sunday, October 6, 13

APACHE V.S. NGINXBecause you might get a lot of visitors... all at the same time!

Apache = Process BasedNginx = Event Based

Sunday, October 6, 13

A FEW ADVANTAGESOn sites with light traffic you will not see much difference in

performance between event vs. processed based servers

AsynchronousAsynchronous = Scalability

Fewer Server Resources(i.e. much less memory)

Better for heavy load sites

Sunday, October 6, 13

ALSO A COST DIFFERENCEPart of the cost of virtual servers is the amount of memory that

is available. Disk space is not as important as memory.

10.000 concurrent connectionsand Nginx still uses only a few MB of

memory

Apache... 100’s of MB’sAnd often will not even handle the load.

Sunday, October 6, 13

WORDPRESS.COMBig servers and big sites prefer Nginx... and now you know why

Back in 2008...8000 live traffic requests per second

Apache would have fallen overand DIED

Sunday, October 6, 13

GAME OVERBig servers and big sites prefer Nginx... and now you know why

15MB of RAM and10% of CPU resources

Apache and a pound load balancerwould freak out at the 1000th

process, using 400+MB RAM and “leaking” 20MB RAM per hour

Sunday, October 6, 13

WORDPRESS & NGINXNot quite a match made in heaven

You’ll have to do some marriage counseling

WP development is “intertwined” with the Apache world.

Support is “limited but growing”.

http://codex.wordpress.org/Nginxhttp://wiki.nginx.org/WordPress

Sunday, October 6, 13

WORDPRESS & NGINXWHERE THE HECK DID MY .HTACCESS FILE GO?!

Nginx has no conceptual notion of this thing called an .htaccess file

http://wordpress.org/plugins/nginx-helper/

Search for Nginx related WP plugins

Sunday, October 6, 13

Proxy Servers are not just “the thing you set in your browser”

Caching HTTP Reverse Proxy

Sunday, October 6, 13

VARNISHAnd it really is... really really, really, REALLY FAST!

BROWSERPROXYSERVER

WEBSITE

VARNISH WEBSITEBROWSER

With Varnish YOU control the caching(because not everyone uses a proxy)

Sunday, October 6, 13

VARNISHYou control the proxy and you control the resources

Cache on DiskCache in Memory

Control through VCL(Varnish Cache Language)

Sunday, October 6, 13

VARNISH SAME SERVERChange the web server port to something else because

Varnish should respond on port 80

APACHE OR NGINXPORT 8080

http://mysite.com:8080

VARNISHPORT 80

http://mysite.com

Varnish points to a “backend” serverwhich happens to be itself but withthe web server on a different port

Sunday, October 6, 13

VARNISH DIFFERENT SERVERSYou can do the setup in whatever way you like

APACHE OR NGINXPORT 8080

http://mysite.com:8080http://wowy.com:8080

VARNISHPORT 80

http://mysite.comhttp://somesite.com

http://wowy.comhttp://admin.com APACHE OR NGINX

PORT 8081

http://somesite.com:8081http://admin.com:8081

Sunday, October 6, 13

WP AND VARNISHBEWARE OF COOKIES

# Drop any cookies sent to Wordpress.sub vcl_recv {! if (!(req.url ~ "wp-(login|admin)")) {! ! unset req.http.cookie;! }}

# Drop any cookies Wordpress# tries to send back to the client.sub vcl_fetch {! if (!(req.url ~ "wp-(login|admin)")) {! ! unset beresp.http.set-cookie;! }}

Sunday, October 6, 13

MEMCACHEDThe name of the game is “DISTRIBUTED”

Sunday, October 6, 13

AND IT DOES WHAT?It manages cache and memory... for more than one server

The “for dummies” version:Make better use of memory

Cache data in memory on other servers that aren’t

using it as much.

Sunday, October 6, 13

DISTRIBUTED, I SAIDThe more the merrier

Sunday, October 6, 13

WORDPRESS.COMYes, wordpress.com uses memcached. As do Twitter, Flickr,

Wikipedia, Craigslist, YouTube, and many others

System interconnects on servers (depending on how you plan and set

them up) can still get more performance over TCP/IP and

memory than a local server faced with only its limited resources.

More servers = more memcached

Sunday, October 6, 13

MEMCACHED PHPWhen installed Memcached will provide you a lot of PHP

functionality to have full control over your caching

$mc = new Memcache;$mc->connect(‘10.0.1.20’, 11211);

$data = “cache this!”;

$mc->set(‘mydata’, $data, false, 100);

$result = $mc->get(‘mydata’);

Sunday, October 6, 13

“MEMCACHED PLUGIN”Your mileage may vary

http://wordpress.org/plugins/batcache/

BATCACHE

Place the advanced-cache.phpin your wp-content directory

Sunday, October 6, 13

LIFE IN THE SLOW LANEIf all this server and site performance is getting to you! :-)

Single Malt ScotchHi Stefan!

TequilaHi Kelly!

BourbonHi Mitch!

BeerHi Andrei!

Sunday, October 6, 13

DOWNLOAD THE SLIDESBecause this MAY have gone WAY too FAST for you!

http://eastbaywp.com/

http://www.stefandidak.com

Sunday, October 6, 13

THINGS MENTIONEDIn case you want to go look stuff up for yourself

Digital Oceanhttps://www.digitalocean.com/

Linodehttps://www.linode.com/

Rackspacehttp://www.rackspace.com/

Amazon VPChttp://aws.amazon.com/vpc/

APChttp://php.net/manual/en/book.apc.php

XCachehttp://xcache.lighttpd.net/

eAcceleratorhttp://eaccelerator.net/

Zend OpCache/Optimizer/Platformhttp://en.wikipedia.org/wiki/Zend_Technologies

Nginxhttp://nginx.org/

Varnishhttps://www.varnish-cache.org/

Redishttp://redis.io/

Memcachedhttp://memcached.org/

WordPress Batcachehttp://wordpress.org/plugins/batcache/

WordPress APC Object Backendhttp://wordpress.org/plugins/apc/

And finally, a “real developer’s” home officebecause everyone keeps asking... :-)

http://www.stefandidak.com/office/

http://www.flickr.com/photos/didak/sets/72157633152434208/

http://www.flickr.com/photos/didak/sets/72157632343719954/

http://www.flickr.com/photos/didak/sets/72157632244753177/

Sunday, October 6, 13

QUESTIONSBecause I’m sure there’ll be some!

Sunday, October 6, 13

top related