Slide 1

Slide 1 text

INCREASE WORDPRESS PERFORMANCE ON THE STACK Taylor Jasko | NetDNA/MaxCDN

Slide 2

Slide 2 text

Hello! I’m Taylor Jasko from

Slide 3

Slide 3 text

. com @tjasko I market stuff. SRC: http://www.flickr.com/photos/mishism/5371074626/

Slide 4

Slide 4 text

. com @tjasko I — Code

Slide 5

Slide 5 text

. com @tjasko I — Design SRC: http://www.flickr.com/photos/burningredstudio/5080751535/

Slide 6

Slide 6 text

End Goal= Make WordPress BLAZING FAST on the Stack SRC: http://www.flickr.com/photos/21474493@N02/7967778988/

Slide 7

Slide 7 text

1 Make WordPress über fast Handle some HTTP DoS attacks 2 Have your server work much less 3 All on only one server! 4 . com @tjasko Would you like to...

Slide 8

Slide 8 text

STEVE SOUDERS . com @tjasko

Slide 9

Slide 9 text

80/20 RULE “80-90% of the end-user response time is spent on the frontend. Start there.”

Slide 10

Slide 10 text

. com @tjasko WHAATT??? stack ≠ FRONT-END SRC: http://www.flickr.com/photos/ theknowlesgallery/7483719462/

Slide 11

Slide 11 text

. com @tjasko Normal WorDPRESS Site 4.34 Page Load

Slide 12

Slide 12 text

. com @tjasko FRONT-END 80% Normal WorDPRESS Site

Slide 13

Slide 13 text

. com @tjasko BACK-END 20% Normal WorDPRESS Site

Slide 14

Slide 14 text

. com @tjasko Great... just great. SRC: http://www.flickr.com/photos 55293400@N07/5726700785/

Slide 15

Slide 15 text

. com @tjasko well... not really. What happens to the back-end under heavy load?

Slide 16

Slide 16 text

. com @tjasko

Slide 17

Slide 17 text

. com @tjasko Just kiddin’... But things do get slow. Let’s see an example of a WP site under heavy load

Slide 18

Slide 18 text

WordPRESS Hit hard 7 second load time!

Slide 19

Slide 19 text

. com @tjasko So let’s look at what really happened Note: stock WordPress install

Slide 20

Slide 20 text

20 requests/second

Slide 21

Slide 21 text

CPU % CPU Usage Packets Disk rate Tiny ~2.5mb/s dos

Slide 22

Slide 22 text

. com @tjasko Don’t let “script kiddies” take you down. SRC: http://www.flickr.com/photos/ lrargerich/3187525211/

Slide 23

Slide 23 text

. com @tjasko My server is supposed to be über fast, right?

Slide 24

Slide 24 text

. com @tjasko Well yes, but there are some caveats.

Slide 25

Slide 25 text

. com @tjasko 1 WordPress is Dynamic

Slide 26

Slide 26 text

. com @tjasko 2 PHP Cannot keep up

Slide 27

Slide 27 text

. com @tjasko 3 MySQL is hit hard

Slide 28

Slide 28 text

How can we fix this? Design a fast stack! SRC: http://www.flickr.com/photos/ edenpictures/6556085943/

Slide 29

Slide 29 text

. com @tjasko The Web server - Apache vs Nginx - Apache Nginx Asynchronous-based Multiple connections per thread process-based every connection needs a new thread Both perform Similar under light loads The major difference: memory usage

Slide 30

Slide 30 text

. com @tjasko So we’re using nginx because it’s FAST! Even wordpress.com uses nginx

Slide 31

Slide 31 text

. com @tjasko “NGINX’s memory and CPU footprints are minimal, and predictable. After switching to NGINX the CPU usage on the load balancing servers dropped three times.”

Slide 32

Slide 32 text

. com @tjasko PHP There’s not much to choose from... CGI FastCGI PHP-fpm They are all technically the same thing... just a different implementation.

Slide 33

Slide 33 text

. com @tjasko MySQL there are few things to keep in mind to keep your databases fast.

Slide 34

Slide 34 text

1 Use the correct config (small, medium, large, huge??) Try to use InnoDB (vs MyISAM) 2 Make sure you are using query caching 3 . com @tjasko make sure that...

Slide 35

Slide 35 text

. com @tjasko SERVER CONFIG 1 Get your own server (dedicated or virtual) Try to use the Linux Kernel v3.2 2 SSDs or RAID is nice... or both ;) 3 Red Hat vs CentOS vs Debian vs... 4

Slide 36

Slide 36 text

. com @tjasko SO there’s the Stack. What about that slowness?

Slide 37

Slide 37 text

. com @tjasko Let’s fix it With back-end caching

Slide 38

Slide 38 text

. com @tjasko What’s the secret? The lil’ bunny rabbit. www.varnish-cache.org

Slide 39

Slide 39 text

. com @tjasko But what is this, “back-end caching?” you speak of?

Slide 40

Slide 40 text

How Back-end caching works

Slide 41

Slide 41 text

How Back-end caching works

Slide 42

Slide 42 text

How Back-end caching works

Slide 43

Slide 43 text

How Back-end caching works

Slide 44

Slide 44 text

How Back-end caching works

Slide 45

Slide 45 text

How Back-end caching works

Slide 46

Slide 46 text

How a cache-hit looks

Slide 47

Slide 47 text

. com @tjasko Which basically PUTS wordpress ON steroids! Let’s test with another DDoS

Slide 48

Slide 48 text

. com @tjasko how fast? REALLY fast!

Slide 49

Slide 49 text

. com @tjasko Is this running on a super powerful server? OS: Processor: Memory: Network: Disk: Debian “Squeeze” i7 -2600 8GB DDR3 1 Gigabit Port 2x 1TB SATA2 (s/w raid 1)

Slide 50

Slide 50 text

. com @tjasko But It’s sadly not plug ‘n play Let’s set this bad boy up!

Slide 51

Slide 51 text

worker_processes 8; worker_connections 1024; use epoll; #for kernel 2.6+ multi_accept on; sendfile on; tcp_nodelay on; gzip on; gzip_disable "MSIE [1-6].(?!.*SV1)"; gzip_comp_level 3; gzip_proxied any; gzip_types text/plain text/css application/x-javascript text/xml application/xml application/xml+rss text/javascript; set_real_ip_from 127.0.0.1; real_ip_header X-Forwarded-For; port_in_redirect off; server_name_in_redirect off; Make Nginx Faster GZIP For Varnish Nginx Config (nginx.conf)

Slide 52

Slide 52 text

pm = dynamic pm.max_children = 50 pm.start_servers = 15 pm.min_spare_servers = 5 pm.max_spare_servers = 25 pm.process_idle_timeout = 60s request_terminate_timeout = 30s process manager Type PHP Config (pool.d/www.conf) limit ON simultaneous requests # OF processes MADE on startup # OF idle processes MAX idle processes TIME TO WAIT TO KILL PROCESS MAX EXECUTION TIME

Slide 53

Slide 53 text

MYSQL Config (my.conf) Just use the right config /usr/share/doc/mysql- server-5.5/examples my-huge.cnf.gz my-large.cnf.gz my-medium.cnf.gz my-small.cnf 1G-2GB RAM MySQL 512MB RAM 128MB RAM & Web Server <= 64M (would not use) . com @tjasko

Slide 54

Slide 54 text

Also make sure to use query caching . com @tjasko query_cache_type=1 query_cache_limit=2M query_cache_size=32M Turns caching on Max size of query to be cached Total size of queries to cache MYSQL Config (my.conf)

Slide 55

Slide 55 text

Varnish + wordPREss = ❤ 1 default.vcl = http://bit.ly/VarnishVCL DAEMON_OPTS="-a :80,:443 \ -T localhost:6082 \ -f /etc/varnish/default.vcl \ -S /etc/varnish/secret \ -p thread_pool_add_delay=2 \ -p thread_pools=8 \ -p thread_pool_min=100 \ -p thread_pool_max=4000 \ -s malloc,2G” 2 3 Have Nginx on port 8080, Varnish on 80 . com @tjasko 4 Use the WP-Varnish Plugin bit.ly/wpvarnish

Slide 56

Slide 56 text

. com @tjasko And you now have a really fast wordpress installation! All on just one server

Slide 57

Slide 57 text

. com @tjasko But it can be even Faster... 1 Cache WordPress in Memcached with W3 Total Cache 2 Install PHP-APC to cache PHP scripts 3 Try out Nginx pagespeed: http://bit.ly/nginxpagespeed

Slide 58

Slide 58 text

. com @tjasko questions? COMMENTS? CONCERNS? General gripes? Feel the need for more speed? see maxcdn.com