Jump to content

Cache performance?


starovich
 Share

Recommended Posts

I have activated the Cache module and then configured the cache in Setup -> Templates -> Cache, where I have set the expiration to 3600 seconds for all my templates.

When I run ApacheBench to stress the server, I am seeing exceptionally high load. My throughput is only ~10 requests/s despite the page being cached, and I can see high MySQL traffic, even though cache is supposedly activated.

Is this expected behaviour? Are there any high-performance cache options available? (That preferrably don't query the DB at all when a cached page is requested.)

Link to comment
Share on other sites

That cache module is for selector caches. Try enabling cache per template basis (setup => templates) and rerun your tests. Always interested to hear about results you find so please post the results here if possible.

Link to comment
Share on other sites

Make sure you are logged out too. Pages aren't cached for you when you are logged in. There are other factors that can disable the cache, but most under the template settings. And of course a page is only cached once the cache has been generated, so if you are hitting a bunch of pages for the first time in an hour then it's likely none of them were cached. In general, cache is only used for the 'guest' user.

I am working on a so called super cache module that bypasses both MySQL and PHP. It uses the apache rewrite engine to pull cached urls directly from static files.

  • Like 7
Link to comment
Share on other sites

That cache module is for selector caches. Try enabling cache per template basis (setup => templates) and rerun your tests. Always interested to hear about results you find so please post the results here if possible.

Hi! I did activate the template cache, see screenshot:

https://dl.dropbox.com/u/2758854/pw_cache_conf.png

Now when I run a benchmark on a page with the "question" template i am expecting a fully cached page.

So I run this benchmark:

ab -n 500 -c 10 http://app.mysite.com/questionflow/test-top/step-1/

CPU shoots up, mostly MySQL is being hit:

https://dl.dropbox.com/u/2758854/pw_highcpu.png

Benchmark result:

Concurrency Level:	  10
Time taken for tests:   31.397 seconds
Complete requests:	  500
Failed requests:	    0
Write errors:		   0
Total transferred:	  1873000 bytes
HTML transferred:	   1673000 bytes
Requests per second:    15.92 [#/sec] (mean)

I tried turning cache off and the result was 12 requests/second, so I'm not sure the cache is even working for me... Any ideas?

Link to comment
Share on other sites

Make sure you are logged out too. Pages aren't cached for you when you are logged in. There are other factors that can disable the cache, but most under the template settings. And of course a page is only cached once the cache has been generated, so if you are hitting a bunch of pages for the first time in an hour then it's likely none of them were cached. In general, cache is only used for the 'guest' user.

I am working on a so called super cache module that bypasses both MySQL and PHP. It uses the apache rewrite engine to pull cached urls directly from static files.

Hey, thanks for answering. I am logged out when performing the benchmark (see previous reply). I also tried enabling cache for "Guests and logged-in users", but that didn't make an impact.

I did configure the cache under Template settings, and I am hitting only one page.

Btw, you mentioned the "cache module"

The module I activated is called FieldtypeCache, and its summary is:

"Caches the values of other fields for fewer runtime queries. Can also be used to combine multiple text fields and have them all be searchable under the cached field name. "

I am pretty new to ProcessWire so that might not have been the correct thing, but Template cache isn't working well for me.

I guess what I am asking is:

1.) Is there any way to verify that the template cache is working properly?

2.) Is it normal for cached pages to generate mysql queries?

Link to comment
Share on other sites

A cache file is locked until completed being written. I'm guessing the requests are coming at it before it can complete the cache. That might explain the longer time it takes here, as you might have a few requests trying to both generate and cache the page. Though double check that it has permission to create the cache file in site/assets/cache/Page/. Does your page being rendered save or delete any pages? Also note that a cached page is not the same as a static page. All hooks still get executed, permissions checked and such. Just the template output is cached. That can help a lot in some instances. But if your template isn't doing anything time consuming, then it won't make any difference--no reason to use cache in such an instance.

Link to comment
Share on other sites

To test if cache is working put a sleep(5); in your template. View the page--should take 5 seconds. View it again and it should be instant, as that sleep never gets executed. Again, make sure you are logged out.

Don't bother with FieldtypeCache. That's only useful in specific situations, and they are pretty rare. I will probably remove that module from the core at some point.

Link to comment
Share on other sites

Also note that a cached page is not the same as a static page. All hooks still get executed, permissions checked and such. Just the template output is cached. That can help a lot in some instances.

Thanks for the explanation.

To test if cache is working put a sleep(5); in your template. View the page--should take 5 seconds. View it again and it should be instant, as that sleep never gets executed.

I can confirm this works as you described, so the template cache is indeed working, but the performance isn't stellar.

Essentially I'd like performance similar to static files. The upcoming "super cache module" sounds exactly like what I need. Is there an ETA for when this will be available?

Thanks for the quick replies!

Link to comment
Share on other sites

Not an ETA yet, but it's something that has been started and I've got a proof-of-concept going, so it's at least in the picture. ProcessWire's performance is pretty strong relative to other CMS platforms and there hasn't been a lot of demand for cache solutions. But I like the idea of a "super cache" because it does feasibly give one the potential for holding up to a flood of requests, like one might get from being linked on the reddit homepage or something.

  • Like 1
Link to comment
Share on other sites

  • 4 weeks later...

Not an ETA yet, but it's something that has been started and I've got a proof-of-concept going, so it's at least in the picture. ProcessWire's performance is pretty strong relative to other CMS platforms and there hasn't been a lot of demand for cache solutions. But I like the idea of a "super cache" because it does feasibly give one the potential for holding up to a flood of requests, like one might get from being linked on the reddit homepage or something.

Add me to the list! I would absolutely love to see this module. I did something similar in MODX Revolution. ProcessWire takes approx. 160 ms to load a simple page on my server. In comparison, the same content takes just 22 ms when saved as static html file. You may think "160 ms are not that much!", but when it comes to high traffic, this may become a bottleneck. Loading performance is also critical with regard to Google's page rank.

Hope to see a first beta of "SuperCache" soon...

Thanks a lot, Ryan!

Link to comment
Share on other sites

I am just as interested in the supercache as you guys, so will be continuing to work on it and hope to have this ready by the time 2.4 rolls out. 22ms vs 160ms -- I'm actually surprised the difference isn't greater. There is a lot more difference in what is actually happening then those numbers indicate. But there are also a ton of different things that can affect those numbers, so am thinking it depends where and when you test. If performance optimization is key, you want to make sure you are using a PHP cache like APC or eAccelerator, etc. You'll also want to use PW's built in template cache and MarkupCache where appropriate. Making sure that PHP has enough memory to do it's just and that MySQL is optimized for your traffic situation is also going to make a difference. A supercache can't be used on any page that needs to consider GET variables, session variables, cookies, randomization, etc., so it's not a substitute for a well tuned server. But it's a great addition either way.

  • Like 1
Link to comment
Share on other sites

Add me to the list! I would absolutely love to see this module. I did something similar in MODX Revolution. ProcessWire takes approx. 160 ms to load a simple page on my server. In comparison, the same content takes just 22 ms when saved as static html file. You may think "160 ms are not that much!", but when it comes to high traffic, this may become a bottleneck. Loading performance is also critical with regard to Google's page rank.

Hope to see a first beta of "SuperCache" soon...

Thanks a lot, Ryan!

Were those results obtained over an internet connection, your local lan, or testing on localhost? I did some benchmarking of my own a while back and as part of that I benchmarked static file serving times on Apache2 and nginx. I was getting times in the order of 56μs per read from Apache2 and far less on nginx but that wasn't over the internet.

FWIW, here are some apachebench results for default installs of PW on Apache2...

post-465-0-93140000-1356787885_thumb.png

...the "failed attempts" are false-positives as the default site homepage has a random image. (Apachebench assumes all reads will lead to the same sized data and flags all following reads that return different size pages as "failed requests".)

  • Like 2
Link to comment
Share on other sites

...the "failed attempts" are false-positives as the default site homepage has a random image. (Apachebench assumes all reads will lead to the same sized data and flags all following reads that return different size pages as "failed requests".)

I was wondering where those failures where coming from..thx

Link to comment
Share on other sites

Were those results obtained over an internet connection, your local lan, or testing on localhost?

These results were obtained over an internet connection, the server is a root server (production system) with some more or less moderate load. I used Firebug's network module and did multiple reloads at different times. It's kind of a subjective test, but it was fast to accomplish for me.

By the way, I did a very similar test with a MODX system some time ago. The results of the frontend performance test with an empty template were nearly the same, compared to ProcessWire. But that's just a small footprint.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...