Dramatically improve the Speed of Google Pagespeed using TMFS!

Updated on September 1, 2017

Are you using Google PageSpeed? Then you might want to improve its performance by configuring it to save cache in RAM based file system. Google PageSpeed is an open source Apache module developed by Google, which is aimed to improve the website load time by optimizing the web server output and applying some best practices to pages, CSS, JavaScript and image files. Interestingly, PageSpeed does all those optimizations automatically and improves higher visitor engagement, conversion and retention. If you haven’t installed mod_pagespeed on your webserver, then quickly head on to Google’s official document to learn more.

How does Google PageSpeed works?

Google PageSpeed optimizes the HTML pages, CSS, JavaScripts, images etc…When a visitor access your website, Google PageSpeed runs all those optimizations, saves it to the disk and sends the output to the visitor’s browser. Thereafter, PageSpeed need not run optimization scripts for every visitor, instead it serves the client request from the cached data. But all those operations on a disk!! and you know that disk’s I/O performance is not that impressive. It means, if there are thousands of visitors accessing your website at the same time, then fetching the optimized resources from a disk for every request is a serious performance issue. How about storing the optimized files in a RAM based file system, which is expected to be 30x faster than disk filesystem. Using the RAM-based filesystem will really boost the PageSpeed.

Improve google pagespeed

Using TMPFS to boost PageSpeed

According to Google, PageSpeed can be configured to cache optimized resources in a RAM-based filesystem called TMPFS. It means, the optimized output can be served directly from RAM, which should be obviously faster than disk and allows PageSpeed scripts to run faster.

Check if you have TMPFS mounted

On Linux machine, run the below command.

$mount

Sample Output…

tmpfs on /dev/shm type tmpfs (rw,noatime,gid=45,uid=45,size=200m,mode=0775)

 Create TMPFS

$ mkdir -pv /tmp/pgsp

Add the entry in /etc/fstab

tmpfs                   /tmp/pgsp                tmpfs   defaults rw,gid=41,uid=41,size=200m,mode=0775,noatime

Remember to replace the uid and gid to the user id and group id of Apache/Ngnix user.  Done? Run the below command to mount the filesystem.

$mount -a

Configure PageSpeed to save cache in TMPFS

$vi /etc/httpd/conf.d/pagespeed.conf

Lookout for the below line and change the path to the newly created TMPFS filesystem.

ModPagespeedFileCachePath    "/tmp/pgsp/"

Restart Apache or Ngnix and see if pagespeed is caching the optimized files in TMPFS.

My sincere thanks to AskApache.

Was this article helpful?

Related Articles

Leave a Comment