Live data from Hacker News

Performance and Speed Optimizations of WordPress [pdf]

lamosty.com

11–20 of 25 posts

Re: Performance and Speed Optimizations of WordPress [pdf]

#11

Lead Developer of TheDirty.com here. Nice work. We're built on WordPress, running on a single machine, using Nginx + PHP-FPM, and currently serving ~20,000,000 pageviews a month. Before I took over development we were running on apache w/ vanilla PHP and CPU's would be > 75% on a regular basis. The site frequently ran into the Apache 10k issue you mentioned in your paper as well. After getting the new server setup &…

I think people are saying APC is dead because another opcode cache was included in PHP 5.5 and APC has not seen a release since 2012. https://en.wikipedia.org/wiki/List_of_PHP_accelerators#Alter... http://pecl.php.net/package/apc

Ah gotcha. The ol' "it's old so it must be dead" way of thinking. That makes sense. Thanks.

Re: Performance and Speed Optimizations of WordPress [pdf]

#12

Lead Developer of TheDirty.com here. Nice work. We're built on WordPress, running on a single machine, using Nginx + PHP-FPM, and currently serving ~20,000,000 pageviews a month. Before I took over development we were running on apache w/ vanilla PHP and CPU's would be > 75% on a regular basis. The site frequently ran into the Apache 10k issue you mentioned in your paper as well. After getting the new server setup &…

I think people are saying APC is dead because another opcode cache was included in PHP 5.5 and APC has not seen a release since 2012. https://en.wikipedia.org/wiki/List_of_PHP_accelerators#Alter... http://pecl.php.net/package/apc

There is still a need for a ucache (in addition to built in opcode cache)... although a lot of high traffic WP sites are turning to redis over memcache for this.

Re: Performance and Speed Optimizations of WordPress [pdf]

#13
I've run wordpress sites for more than a decade. I've never had an experience with opcode caching that wasn't unhappy.

I've used all of them. They all crash like a demolition derby in a brewery.

At one point I put Wordpress into a profiler and found that a only a few percent of total time was spent compiling PHP; most of the time spent was in waiting for MySQL and concatenating strings. So I just gave up on opcode caching.

The biggest improvements I got were:

* Whole page caching. In my case, WP-supercache spitting out gzip'd pages, with Nginx configured to find and serve those gzip'd pages.

* MySQL query caching.

* Moving MySQL into another server. This was a decent win when I was on spinning rust.

* SSDs. MySQL is a major chokepoint for Wordpress, because until recently its idea of a query plan was "let's join half the workloads on disk in gigantic join tables".

* Killing bad plugins. Even the "recent comments" plugin that ships with mainline is horrendous.

Re: Performance and Speed Optimizations of WordPress [pdf]

#14
post #5

WordPress is slow by design! I have managed to create a blogging engine (in PHP) that it only takes 2ms to create the page dynamically (without caching) from the database + ~20ms for Nginx to serve it. One might argue that my engine does not have as much features... and you are right. Incase you are interested: SunSed.com

You can do faster than that as well if you use C++ - I can render pages dynamically in 0.1 ms or so.

Re: Performance and Speed Optimizations of WordPress [pdf]

#15

Lead Developer of TheDirty.com here. Nice work. We're built on WordPress, running on a single machine, using Nginx + PHP-FPM, and currently serving ~20,000,000 pageviews a month. Before I took over development we were running on apache w/ vanilla PHP and CPU's would be > 75% on a regular basis. The site frequently ran into the Apache 10k issue you mentioned in your paper as well. After getting the new server setup &…

Thanks for the kind words Justin, they are the hugest approval of my work so far. :) Not getting this in uni where everybody is about matrices and stuff.

Have you tried using HHVM instead of PHP-FPM? Although you are definitely having a fast site, HHVM could potentially double the numbers.

Yes, one slow DB query can ruin all the fun. That's why using Redis for in-memory DB caching can help. In some cases, it might be more optimal than using full page caching because DB caching works for logged in users too while page caching has to be bypassed.

Using JavaScript for better performance helps too, I like how you optimized that menu. I've noticed that profiling the code with, for example xhprof, can be really useful during development. Found myself doing some slow code/queries, ran the profiler and immediately discovered the bad parts. It's quite easy and straightforward to fix them if you know where they are.

----

They probably meant that APC, which was a separate PHP caching module back then, is dead. However, caching is now part of PHP and as far as I can remember, it is using the same API as APC was, so basically it still lives and W3TC supports it.

Re: Performance and Speed Optimizations of WordPress [pdf]

#16

I've run wordpress sites for more than a decade. I've never had an experience with opcode caching that wasn't unhappy. I've used all of them. They all crash like a demolition derby in a brewery. At one point I put Wordpress into a profiler and found that a only a few percent of total time was spent compiling PHP; most of the time spent was in waiting for MySQL and concatenating strings. So I just gave up on opcode ca…

You got some good points here though I don't know why opcode caching didn't work for you. Nowadays, it's just a matter of putting some configuration lines into PHP-FPM config and it works like a charm (at least for me, you might have a special site, idk).

Yes, compiling PHP shouldn't take that much (even though typical WordPress site consists of thousands of PHP files). But as you can see from some of the charts from my work, it can potentially double the amount of concurrent requests the server is able to respond to.

Whole page caching (I call it page cache) is the biggest improvement one can make. However, instead of using WP plugins, in my work I configured Nginx to cache the output of PHP interpreter (FastCGI). The advantages are that you can use Nginx's location directives to bypass the cache early (e.g. logged in users, shopping cart, etc) and that Nginx stores the pages in RAM in a tree-like structure with pretty fast access times. In a heavy WP site (plenty of large plugins, etc), you can go from 200 concurrent requests at 8 seconds to 1000 concurrent requests at 2 seconds, which is a pretty huge improvement.

MySQL query caching should definitely help, though in my testing it did not. Maybe I need a real benchmark with a real 100 people requesting different subpages. Then the DB (MariaDB in my case) might become a bottleneck.

Yeah, SSDs are superb-useful, in any cases. I made all the tests on a non-SSD server. At least the WordPress DB structure is quite flexible, though, as you mentioned, it now suffers from the gigantic joins.

Bad plugins and themes are the root of all the performance problems. But sometimes it is easier to implement caching and replacing Apache with Nginx on the server side than replacing plugins that you really need. That's the main point of the thesis: Time of an experienced developer fixing plugins and themes is more expensive than optimizing the server. But yeah, if you are a developer, learning to write clean and fast plugins is crucial.

Re: Performance and Speed Optimizations of WordPress [pdf]

#17
post #16

I've run wordpress sites for more than a decade. I've never had an experience with opcode caching that wasn't unhappy. I've used all of them. They all crash like a demolition derby in a brewery. At one point I put Wordpress into a profiler and found that a only a few percent of total time was spent compiling PHP; most of the time spent was in waiting for MySQL and concatenating strings. So I just gave up on opcode ca…

You got some good points here though I don't know why opcode caching didn't work for you. Nowadays, it's just a matter of putting some configuration lines into PHP-FPM config and it works like a charm (at least for me, you might have a special site, idk). Yes, compiling PHP shouldn't take that much (even though typical WordPress site consists of thousands of PHP files). But as you can see from some of the charts from…

It wasn't that configuring opcode caches is complicated or difficult. It's that they locked up every few days, no matter which one I used or how I configured them.

At the point where I wrote a cron script to kill PHP every 24 hours, I realised the extra few percent weren't worth it.

Maybe it's improved, but: four times bitten, twice shy.

> Nginx stores the pages in RAM in a tree-like structure with pretty fast access times.

On disk caching delegates this to the OS, which is pretty good at it.

Badly behaved plugins and themes are not a solvable problem on Wordpress, because it's essentially a cooperative multitasking environment. One bad actor can hog all the resources and there's no way to constrain it.

It seems as though very few plugin authors know what O-notation means (so many nested loops), what EXPLAIN QUERY is or that tinkering and and firing up a copy on your laptop isn't really testing.

Re: Performance and Speed Optimizations of WordPress [pdf]

#18
post #16

Earlier quoted context omitted.

You got some good points here though I don't know why opcode caching didn't work for you. Nowadays, it's just a matter of putting some configuration lines into PHP-FPM config and it works like a charm (at least for me, you might have a special site, idk). Yes, compiling PHP shouldn't take that much (even though typical WordPress site consists of thousands of PHP files). But as you can see from some of the charts from…

It wasn't that configuring opcode caches is complicated or difficult. It's that they locked up every few days, no matter which one I used or how I configured them. At the point where I wrote a cron script to kill PHP every 24 hours, I realised the extra few percent weren't worth it. Maybe it's improved, but: four times bitten, twice shy. > Nginx stores the pages in RAM in a tree-like structure with pretty fast access…

> Maybe it's improved, but: four times bitten, twice shy.

I see, happens all the time.

> On disk caching delegates this to the OS, which is pretty good at it.

Yeah, it's just a matter of preference and convenience.

> It seems as though very few plugin authors know what O-notation means (so many nested loops), what EXPLAIN QUERY is or that tinkering and and firing up a copy on your laptop isn't really testing.

This is the real issue. I know a very few WordPress developers who have a formal technical education. While you can learn it yourself, school forces you to learn this in a great detail. In a near future, I will hopefully write on these topics, though, I need to study on this a bit more first.

Re: Performance and Speed Optimizations of WordPress [pdf]

#19
post #5

WordPress is slow by design! I have managed to create a blogging engine (in PHP) that it only takes 2ms to create the page dynamically (without caching) from the database + ~20ms for Nginx to serve it. One might argue that my engine does not have as much features... and you are right. Incase you are interested: SunSed.com

You can do faster than that as well if you use C++ - I can render pages dynamically in 0.1 ms or so.

templates are mostly not the problem, even on python, when you use jinja templates getting generated really fast. However the problem mostly comes through the database. A single page view could hit like 10 queries.

Re: Performance and Speed Optimizations of WordPress [pdf]

#20
post #19

Earlier quoted context omitted.

You can do faster than that as well if you use C++ - I can render pages dynamically in 0.1 ms or so.

templates are mostly not the problem, even on python, when you use jinja templates getting generated really fast. However the problem mostly comes through the database. A single page view could hit like 10 queries.

Yeah. Avoid the database, just read from RAM :)
Post reply on HN