====== Should I Turn on Both PageSpeed and LSCache at the Same Time? ======
In some cases, you may want to know if mod_pagespeed works with LiteSpeed Cache. Let's find out with a testing benchmark experiment.
=====Introduction =====
Before we dive into the differences between LSCache and PageSpeed, let's take a quick look at the background of these two functions and their general characteristics.
* [[https://www.litespeedtech.com/support/wiki/doku.php/litespeed_wiki:cache | LSCache]] is a server-side page cache. Page caches save time and resources, and they do so by storing the full content of dynamically-generated pages so that static copies may be served to the user. A page cache allows the server to bypass the process of dynamic page creation and database queries altogether. Unlike Varnish, LiteSpeed cache is built into LiteSpeed's web server, thus eliminating one layer of reverse proxy. This translates into higher efficiency for static content.
* PageSpeed is an open-source module which automatically applies web performance best practices to pages and associated assets (CSS, JavaScript, images) without requiring that you modify your existing content or workflow. This module can reduce website loading times by automatically optimizing web pages and the resources within them.
=====Test Environment=====
==== Hardware====
- Client: 4 cores of Intel(R) Xeon(R)E7-4870 @ 2.40GHz CPU + 4G RAM
- Server: 4 cores of Intel(R) Xeon(R)E7-4870 @ 2.40GHz CPU + 4G RAM
==== OS and Settings====
- Client:
- CentOS 7*64
- [[http://httpd.apache.org/docs/2.0/programs/ab.html | ApacheBench]]
- Server
- CentOS 7*64
- LSWS v5.2
- Disable Keep alive
- Increase max connection 200000
- WooCommerce demo data, page size = 68k
- WP-Plugin v1.2.0.1
- mod_pagespeed rules
- pagespeed FileCachePath /tmp/lshttpd/pagespeed;
pagespeed RewriteLevel CoreFilters;
- htop v2.0.2
* To verify PageSpeed is working, see [[https://www.litespeedtech.com/support/wiki/doku.php/litespeed_wiki:config:enable_pagespeed#verify_pagespeed_is_enabled | this article]]\\
* To verify LSCache is working, see [[https://www.litespeedtech.com/support/wiki/doku.php/litespeed_wiki:cache:no-plugin-setup-guidline#verify_that_pages_are_served_from_the_cache | this article]]\\
==== Testing Method====
There are four scenarios in our experiment:
- Do not use LSCache or mod_pagespeed
- Only use mod_pagespeed
- Only use LSCache
- Use both LSCache and mod_pagespeed
Regardless of whether we are testing with LSCache or mod_pagespeed, we follow the same procedure:
* Test the web servers using ApacheBench (an HTTP server benchmarking tool). In each test, the client sends 10,000 requests of 68kB each to the server's webpage.
* Before each test the web server in question is restarted to clear out any potential caching or other issues that may interfere with results.
* Each test is run with the same concurrent numbers of requests to gauge performance for different cases.
* The commands that are used in this test follow this format: \\ ab -n 10000 -H "Accept-Encoding: gzip,deflate" -c 10 http://$Server_IP/wordpress/
=====Benchmarks=====
==== Comparison Table ====
^ Case ^ LSCache ^ Mod_PageSpeed ^ Requests/s ^ Memory usage(MB)^ CPU Load 1min ^
| 1 | X | X | 16 | 210 | 7.33 |
| 2 | X | O | 21 | 300 | 8.42 |
| 3 | O | X | 8152 | 1 | 2.50 |
| 4 | O | O | 4469 | 100 | 3.52 |
* CPU Load default average value is 0.3
* Memory usage numbers do not include the system's base memory usage, which has been subtracted from the total
==== Comparison Chart ====
===Requests per second===
LSCache clearly dominates in the raw number of requests per second it can serve. The difference between cases with LSCache and cases without LSCache is too large to chart them side-by-side, so we've created two separate charts.
* Comparing Case 1 and Case 2 by requests per second, we can see there is 20% increase with mod_pagespeed \\ {{:litespeed_wiki:config:cp-1.png?500|}}
* You will notice from this graph that with LSCache and PageSpeed both enabled, the numbers are lower than that of just LSCache but greater than just PageSpeed. The reason for this is that on a normal load of the webpage, LSWS will serve the cached file and all of the static files that are requested without having to do any CPU-intensive tasks. When PageSpeed comes into play LSWS will serve the cached page, removing any need for PHP. This will be quicker, but then it has to optimize all of the other static content via mod_pagespeed before it gets served to the user. In return, one receives optimized static files but at a cost of server resources and less requests per second.\\ {{:litespeed_wiki:config:cp-2.png?500|}}
===CPU Load===
* For this test, we continually send requests for the duration of exactly 1 minute. Comparing all cases, we can see CPU Load is highest with only mod_pagespeed is enabled. Cases 3 & 4, in which LSCache is enabled, are not overloading.\\
{{:litespeed_wiki:config:cp-4.png?500|}}
===Memory usage===
* This is important to measure, especially on a VPS where your memory usage has a hard cap and raising it costs you additional money. Comparing all cases by memory usage, we can see there is a 30% increase with mod_pagespeed running than with nothing enabled. \\
{{:litespeed_wiki:config:cp-3.png?500|}}\\
//Remember, the results shown are good only for measuring relative (and not absolute) performance, as the tests were conducted locally on the server.//
===== Conclusion =====
After going over the benchmark testing of both LSCache and mod_pagespeed enabled cases, you may have a better idea of which combination is more suited to your needs.
- Using LSCache and mod_pagespeed together is a workable scenario, but it will slow down your page loading time and increase CPU and Memory usage. If your LSWS includes LiteSpeed Cache already, then you don't need to enable the PageSpeed module to shorten the loading time.
- If your LSWS does not include LSCache, then PageSpeed does speed up your site by around 20%. It will require significant resources and should be avoided in shared hosting environment. For more information, please see [[ https://www.litespeedtech.com/support/wiki/doku.php/litespeed_wiki:config:enable_pagespeed#using_a_control_panel_in_a_shared_hosting_environment| Using a Control Panel in a Shared Hosting Environment]].
- Seeing these results, you may want to [[https://www.litespeedtech.com/support/wiki/doku.php/litespeed_wiki:licenses:add-lscache | add LSCache to your existing LSWS license]]. \\
We welcome your feedback on our [[https://www.litespeedtech.com/support/forum/ | forum]].
=====Reference:=====
- [[https://www.modpagespeed.com/doc/config_filters | Pagespeed doc]]
- [[ https://scotthelme.co.uk/pagespeed-performance-optimisation-made-easy/ | scotthelme post]]