FREE THOUGHT · FREE SOFTWARE · FREE WORLD

Home  »  Hosting  »  Boosting Googles PageSpeed Module with TMPFS

by comment

Boosting Googles PageSpeed Module with TMPFS
Google's mod_pagespeed speeds up your site and reduces page load time. This open-source Apache HTTP server module automatically applies web performance best practices to pages, and associated assets (CSS, JavaScript, images), all transparently like a Squid Proxy.

With TMPFS you can dramatically improve the speed of mod_pagespeed and the webpages served by it. TMPFS will store/serve the optimized PageSpeed output directly from RAM!

Super-Boosting with TMPFS

The PageSpeed module in a nutshell applies several optimizations to the output sent by your server before it is sent to the client's browser.

 [ Server Outputs ] ===> [ PageSpeed Module Optimizes Output ] ===>  [ Clients Browser Receives Optimized Output ]

The optimizations are quite impressive indeed, including optimizing images, HTML, CSS/JS, whitespace-minification, etc. However, since maybe 100 visitors to your site may request the same page at the same time, it would be inefficient for the PageSpeed optimization to have to run the same opimizations on the same outputs for every visitor. So, the PageSpeed optimizations are saved to the server disk in a temporary location. That way, the first visitor is the only request that requires PageSpeed to run all the CPU-intensive tasks like optimizing images, and those optimized images are then saved to disk, so that the next 99 visitors will be served directly from the disk and will not have to do all the work over again for each request and visitor.

The downside to this is obvious to anyone with a solid grasp of system-performance.. Disk I/O! The disk can only do so much activity at a time, and it has physical limits to the speed and amount of I/O it can do at any one time. Meaning that if you had 1000 visitors all accessing the same PageSpeed-optimized image file from disk on each request, the Disk I/O would become a serious bottleneck (though still much much faster than having to do the optimizations each time for each request).

TMPFS to the Rescue

A Disk just stores binary 0's and 1's, and likewise RAM does the same. The difference is that RAM is at least 30x faster. This is why Google's internal systems running google.com searches are all RAM-based. They also use RAM-based filesystems to store all the pagerank/linking data which makes parsing and computing that data way faster.

In order to save, retrieve, locate, and modify data on a Disk, you need a filesystem. Windows uses a lot of pathetic filesystems such as NTFS. Linux OTOH, uses cutting-edge filesystems such as ext4, ZFS, XFS, ReiserFS, and of course, GoogleFS.

Unlike Disks, RAM does not retain the 0's and 1's when the power goes off, so having a filesystem on top of RAM didn't make sense... The GNU/Linux developers went for it anyway and several RAM-based filesystems were created. The easiest and best is called TMPFS.

TMPFS lets you save, retrieve, locate, and modify the 0's and 1's on a RAM device in the exact same way you use a hard-drive.. Only, you wouldn't use TMPFS to store things since a reboot or power-outage will always clear RAM.

TMPFS Example: favicon.ico

One of the easiest illustrations of how tmpfs can act like a 30x super-charger is this. Most browsers automatically request a sites favicon.ico file. If you had 10k visitors requesting the favicon.ico file at the same time it could cause a Disk I/O bottleneck. So what you could do instead is create a TMPFS in Ram and put the favicon.ico file there instead, then those 10k visitors requesting it at the same time would be served it directly from RAM!

PageSpeed + TMPFS

So the idea here is to setup PageSpeed so that all the optimized images, white-space minified files, combined js files, etc.. are saved not to the slow Disk but are saved to the fast TMPFS. Then all of those optimized files are served directly from RAM! This not only improves the speed at which visitors receive the files, but also allows many many more visitors to be served at the same time. And it also improves the speed at which the PageSpeed module can generate, create, and update those optimized files.

Prepare the TMPFS

First thing to do is shutdown apache/nginx. Then you will prepare and build the tmpfs filesystem.

Create tmpfs directory

# mkdir -pv /tmp/pgsp

Create Mount option in /etc/fstab

Get the uid and gid first: # id apache, which gives me:

uid=38(apache) gid=38(apache)

Now add this line to your /etc/fstab file.

rw,gid=38,uid=38,size=200m,mode=0775,noatime

Test the Mount

Finally, make sure it mounts automatically

# mount -a

Then check that it is listed in the output of mount

# mount
tmpfs on /tmp/pgsp type tmpfs (rw,noatime,gid=38,uid=38,size=200m,mode=0775)

Configure Apache/Nginx Pagespeed Module

Now that the tmpfs is all setup you just need to setup the Pagespeed Module to use it. Of course you will first need to install the module if you don't already have it.

Install and Enable the mod_pagespeed Apache/Nginx Module

Download and install

Configure mod_pagespeed to use the tmpfs

In the Apache/Nginx configuration file provided by mod_pagespeed, such as /etc/httpd/conf.d/pagespeed.conf, you need to set the directive ModPagespeedFileCachePath to the location of the tmpfs filesystem.

ModPagespeedFileCachePath    "/tmp/pgsp/"

Official PageSpeed Docs

Tags

January 8th, 2014

Comments Welcome

Popular Articles
My Online Tools

Related Articles
Newest Posts
Twitter


  •  t.co/ShKrGdqXuJ 
  • RUN GCC! This is a typical shirt I wear, from the  t.co/46LYbFr4k2  shop. A clerk at the LQ recognized it!  t.co/jjmT0dkCPu 
  • Merlin the Magician  t.co/iMmRbanUi4 
  • ROGUE CODE - Latest novel from @markrussinovich  t.co/apkn0LoPIt 
  • RTFM - surprisingly very helpful and way more comprehensive than it looks! @redteamfieldman #pwnAllTheThings  t.co/xiaJ5g0aC9 
  • Dear Hacker - Letters to the Editor of 2600, from Emmanuel Goldstein  t.co/JCfLab7FAJ 
  • The Mythical Man-Month - Essays on Software Engineering, by Frederick P. Brooks, Jr.  t.co/ilWN5GHElr 
  • "where wizards stay up late" - The Origins of the Internet. Favorite book detailing the birth of the net and IMPs  t.co/gY9VTGJgZz 
  • ZERO DAY - read before Trojan horse  t.co/pPMLGDJv8P 
  • Trojan Horse, a novel!  t.co/Hf8EtYaZVa 
  • The Hacker Playbook - very nice high level overview of attacks  t.co/lHwNVWi61u 
  • Clean Code - A Handbook of Agile Software Craftsmanship  t.co/hnJX0x1qIc 
  • Secrets of the JavaScript Ninja - By my absolute favorite JS hacker John Resig!  t.co/tZ42ljmcCl 
  • Hacking Exposed 7: Network Security Secrets & SolutionsMy all time favorite, basic but thorough and accurate.  t.co/jycW0RDVtZ 

Hacking and Hackers

The use of "hacker" to mean "security breaker" is a confusion on the part of the mass media. We hackers refuse to recognize that meaning, and continue using the word to mean someone who loves to program, someone who enjoys playful cleverness, or the combination of the two. See my article, On Hacking.
-- Richard M. Stallman






[hide]

It's very simple - you read the protocol and write the code. -Bill Joy

Except where otherwise noted, content on this site is licensed under a Creative Commons Attribution 3.0 License, just credit with a link.
This site is not supported or endorsed by The Apache Software Foundation (ASF). All software and documentation produced by The ASF is licensed. "Apache" is a trademark of The ASF. NCSA HTTPd.
UNIX ® is a registered Trademark of The Open Group. POSIX ® is a registered Trademark of The IEEE.

| Google+ | askapache

Site Map | Contact Webmaster | License and Disclaimer | Terms of Service

↑ TOPMain