 My name is Aaron Edwards I am the CTO for Incza, which is the parent company of WPMU dev edgy blogs in campus press WPMU dev We have more than a hundred premium plugins and themes and support services lots of cool stuff there edgy blogs It's one of the largest multi-site installs online with hosting more than three million wordpress blogs Which is pretty crazy in campus press, which is a VIP like hosting service for education So we have a lot of experience with dynamic websites hosting all that stuff One size doesn't fit all Normally when you do or go to a performance talk like this at a word camp they'll be talking more about the front end of your site and speeding that up and Caching plugins configuring all that kind of stuff and a big focus goes to full-page caching The problem is if you have a dynamic site like you run BB press e-commerce wordpress multi-site buddy press Membership sites pretty much any site where a lot of your visitors are going to be logged in They're going to be skipping that full-page cache almost all the time, which means it's not helping you out at all So today we're going to be talking about fixing the page generation time that part of that stack Now if you look at a normal request to your website when you're logged in it might look something like this You'll see this big bar Where it's waiting for your page to be generated and sent to you and then after that your browser can download all the Assets and things like that So just talking about this page generation time and how we can improve that can make a huge impact on your site Especially when inside that dynamic site now Google recommends Maximum 200 milliseconds for your page generation time and really you want to get that much lower than that as much as possible But that can be a huge challenge when you have a large Plug-in a lot of large plugins and themes that are running code all the time can be a big challenge to meet that mark Now when I first started this presentation I thought I'd be talking more about scaling out to multiple servers and different architectures like that But I realized from my own experience that doing that does not actually solve your performance issues All it's going to do is multiply that multiply that if you don't fix those underlying performance issues that you're having So to look at how to fix that if you look at that normal page Generation time you can divide it up in a few chunks that you see right here The biggest chunk is usually your database. That's the big bottleneck that you run into on your site To fix the database problems is you want to optimize things as much as possible So you want to look at your queries? There's an awesome plugin called query monitor that you can install and it allows you to analyze the queries That all your plugins are making and see where the problem areas are where you can add an index where you can get rid of that Plug-in completely because it's terrible Also optimizing your MySQL configuration so query cache is a big thing It's surprising how many people don't have the query cache enabled in MySQL But that can be a big help if you have a lot of read-only tables Also, MySQL tuner is a little script that you can run and that just analyzes your config and gives you advice for how you can improve your database also Converting tables to NODB. I say high-write tables only and not all tables because if you're running a large WordPress multi-site install Like we are on edgy blogs Converting all your tables to NODB can cause some major headaches trust me We've experienced that so we focus more on the tables that have a lot of right requests going to them So like the global tables and a multi-site install Also, MariaDB is an alternative to MySQL. It was actually a fork of it with newer code You can get about 10 to 20 percent performance boost by switching to that And if you're lucky enough to be hosting on Amazon Aurora is a new service or alternative for MySQL that has two to three times better benchmarks and speed which is pretty amazing But ultimately the best way to optimize your time spent in the database is never letting the queries get there in the first place And that's where the WordPress object cache comes in So normally PHP is talking to MySQL directly which is disk based and slow But if you have an object cache configured you can be caching a lot of those queries and requests in memory Which is so much faster a few object caching plugins are memcache and redis Those are the ones I recommend because they're memory based and if you scale out to multiple servers They can share the same cache they can work in that aspect if you try to do file based or APC Final base is just sometimes slower than not using one at all. So I highly recommend against that Alright The other thing you need to look at is that PHP chunk of the page load generation time One of the most important thing is optimizing the code that's running the PHP code for beginners There's a cool plugin called p3 and allows you to basically see is this plug-in causing this amount of resources And you can say oh this plug-in is a hog. I don't really need it. I'll get rid of it Very easy for beginners to use if you're more advanced You can use X debug and PHP and you can analyze the cache grind files and actually Profile the code and say this function is bad This loop is running too many times etc etc and on a production site Or you're getting a lot of traffic new relic is an awesome service that you can use as a paid service But it does wonders and helping you analyze and profile your PHP code Some of the things that I've run into when analyzing PHP code These are the worst offenders that I've seen First of all unnecessary unoptimized queries You can cache a lot of them into the object cache and that will save you a lot of times on WPMU dev We run a lot of our own plugins on our own sites high-skill sites So we spend a lot of time trying to optimize those plugins with the object cache Also look out for plugins like stats plugins redirection logging. I've seen oftentimes They try to write to the database on every page load. That is a big no-no It's gonna slow down your site incredibly when you have a high traffic site Watching out for remote requests So when PHP has to call like an external API like Google or what Facebook whatever it is It has to wait for response for them before it can finish generating your page And if that other API service is running slow, it's gonna slow down your site incredibly Could even crash it if that service goes down So you want to make sure you use low timeouts there that you cash them as long as possible and do not cash them in Transients even though the codex says that's what they're for Because if that transit runs out and the API service goes down It's gonna be making an external call every single time the page loads and that will crash your site like it's done to edgy bugs before So watch out for that. Also some plugins. They'll try to flush the rewrite rules every single page load Still a problem out there watch out for that and anything that tries to write to your file system directly That'll slow down your site too Also part of increasing the PHP speed is to work on that architecture directly So using engine access highly recommend it I haven't used Apache for five years because Apache has to load PHP for every single page load even for loading CSS JavaScript that kind of stuff in Gen X that's only gonna pass your dynamic requests over to PHP So that gives you a lot of headroom if you're running multi-site Make sure you're using a CDN or varnish cache in front of your media files because many people don't know this But your uploads are actually rewritten through PHP and multi-site It's a weird thing that they do but that will give you a lot of headroom if you can keep those requests from hitting PHP for media Also, make sure you're using the latest versions of PHP because you can get five five five six You can get ten to twenty percent more speed by using that than if you're back on some older version of five two And finally if you're not using the op-cache You're crazy because that is built into PHP You just got to enable it and it will speed up your request by two times at least usually and there's a few rules here That I don't have time to cover for how you can optimize that op-cache to Finally think about switching to PHP 7 so exciting on Thursday PHP 7 was released And I'm very excited to be rolling it out in edgy blogs and dev and some of the sites that we host soon It's showing two to three times higher speed than the previous version of PHP. That's a huge thing And it's very exciting. I'm excited about that. So look at switching your server to using the latest versions of PHP if possible Another thing that you need to look at once you have a live site that's going and it's at scale and running a lot of requests Is how do you monitor that site? For our sites we use stats D. It's a awesome open-source project from Etsy And we use it with the WordPress plug plug in that I've written you can see the link to that plug in if you Want to use it and it allows you without causing into any latency on your site to be able to analyze your code Analyze what's going on in your WordPress site and for our developers They can just put in a one-line piece of code anywhere in our stack and they can see oh, how long does this query take? Oh, how many times does this query fire all that kind of stuff to help optimize the code So I highly recommend looking into that if you're able to roll that your own if you're not new relic is a great service again That I talked about before it's a paid service and It's good But if you have multiple servers you can start getting expensive really fast But something to look into and if all this sounds too technical for you And you don't have the ability to hire some experienced sys admin that can take care of this for you Check out some of these managed hosts that are out here in the hallway today A lot of them implement a lot of these suggestions already like object cash using engine x etc most of them support HHVM in certain plans and A lot of them that I've talked to you are getting ready to release PHP 7 supports very soon too So talk to them about that. They can help you out with a lot of these things So thank you so much for being here the link to the slides is on here And feel free to catch up with me after anywhere today if you want to pick my brain ask questions Or check out WPMU dev where you can bug me every single day to get more knowledge about this stuff. Thank you