May
12
2009

speeding up firefox with tmpfs and automatic rsync

Comzeradd posted a great article recently on how to speed up firefox by moving your ~/.mozilla folder on a tmpfs mount.

As you probably know, firefox keeps track of everything you visit while you browse the web infinity, then allows you to quick-search that history just by typing in its awesome bar –err, address bar :)

Unfortunately, after a while the whole thing slows down and gets a bit annoying. So what Comzeradd tried was to move ~/.mozilla (which includes the history database) on a tmpfs mount.

The difference is staggering! Searches are snappy again and even firefox itself feels faster!

Comzeradd offers a script that syncs your tmpfs ~/.mozilla with a folder on your hdd to make sure you won’t lose your data on reboot/shutdown/powerfail.

I took this a step further by creating a firefox wrapper script. After you move your ~/.mozilla folder to a safe place, this script makes sure that your data is always synced between the tmpfs folder and your hdd folder on a fixed interval.

what the script does, in steps:

  1. check that we don’t have any stale ~/.mozilla folder
  2. rsync our hdd copy of .mozilla with our tmpfs
  3. launch a background process that syncs any changes on the tmpfs .mozilla folder back to our hdd copy every one minute (adjustable)
  4. launch firefox
  5. when firefox ends, kill background process and sync back to the hdd one last time

To use the script, you’ll first need to mount tmpfs to a folder. On my laptop I have my /var/tmp as tmpfs (useful for gentoo emerges too). To make /var/tmp a tmpfs folder, you need to edit your /etc/fstab file and add the following line:

tmpfs              /var/tmp    tmpfs  size=768M,mode=0777         0 0

You should adjust the size= option based on the ram you have available.

Then just mount the “partition” with:

mount /var/tmp

and execute the script

chmod +x speedfox

speedfox

Thats it! This simple process gives firefox a real boost!

If you start speedfox from a terminal, you can see the rsync info at the beginning and after each minute =]

You can get the script here.

Don’t forget to edit it, read the instructions and configure its variables!

tags: , , , , ,
posted in general by Alex “wired” Alexander

Follow comments via the RSS Feed | Leave a comment | Trackback URL

16 Responses to “speeding up firefox with tmpfs and automatic rsync”

  1. I just installed a similar ‘hack’ on my laptop to use an mfs(4) filesystem for ~keramida/.mozilla and periodically run rdiff-backup to keep copies of this to ~keramida/cache/mozilla.

    One of the things I would like to note about using a memory filesystem for ~/.mozilla is that one should be careful to avoid one gotcha:

    If the memory filesystem is not mounted, running rsync from ~/.mozilla to ~/cache/mozilla may *delete* all files from the ‘persistent cache’. In my version of the cron job I used (a) a lockfile to avoid having multiple copies of the cron job running at the same time and (b) the following snippet of shell code:

    # The runtime mozilla-settings directory.
    MOZILLAHOME=”${MOZILLAHOME:-${HOME}/.mozilla}”

    # The cache directory for .mozilla application settings.
    MOZILLACACHE=”${MOZILLACACHE:-${HOME}/cache/mozilla}”

    :

    # If the cache directory does not exist, we can’t update it.
    if [ ! -d “${MOZILLACACHE}/.” ]; then
    debug “${MOZILLACACHE} is not mounted.”
    exit 0
    fi

    # If the original .mozilla directory is not an md(4) mount point, we
    # haven’t created the memory filesystem for it yet, so skip the update
    # to avoid emptying the cache by mistake.
    mount | fgrep “${HOME}/.mozilla” > /dev/null 2>&1
    if [ $? -ne 0 ]; then
    debug “${MOZILLAHOME} is not mounted.”
    exit 0
    fi

    Excellent post & idea. Thanks for sharing it :-)

    • wired says:

      The lock idea is something I wanted to implement as well but i didn’t get around doing so.

      The reverse sync check is also a good idea, although the possibility of my tmpfs unmounting is rather small.

      I’ll update the script with those recommendations to make it safer to use.

      Thanks for commenting :D

  2. […] 还好,有位同学给我们写了一份脚本,参见这里。 […]

  3. Aimin says:

    Hello, can this works on Mac?

  4. wired says:

    @Aimin
    Maybe, assuming you have rsync and tmpfs support.

  5. Aimin says:

    @wired
    Oh, it’s a pity, I don’t have tmpfs support.
    by the way, there is no ~/.mozilla folder on my mac, if I install tmpfs support, could i use this trick to speed up my firefox?
    thank you.

  6. […] 首先提供speedfox.sh脚本一枚[这里,via]~请修改它的前四个变量保存待用。 # 同步到/dev/shm MOZTMPFS=/dev/shm/mozilla_`whoami`_profile # 原始的火狐profile目录存放点,如果你的firefox只有一个profile, # 那么一般是结尾为default的那个目录。我常用的profile是shellex,我的选择是在后面加 .backup MOZHDD="/home/shellex/.mozilla/firefox/yj6mxdhg.shellex.backup" # 火狐启动时的连接点 MOZHOME="/home/shellex/.mozilla/firefox/yj6mxdhg.shellex" # 同步的时间间隔,单位秒 INTERVAL=600 […]

  7. Awesome job, thank you for sharing it!

    BTW, maybe you know any way to adopt this great idea for Windows (and for Windows Server)?
    (I know this is no the best place to ask, :) but I think you may have some thoughts on this as a developer)

    All the best,
    Dave

  8. AskApache says:

    Great tip, that is awesome. I can’t believe anyone would’t have tmpfs support.. its 2.4 for goodness sake.

  9. Bastiaan says:

    Hi,Great article,

    I ended up to your post because I was looking for the normal mount option to get the fstab executed: mount -a is the trick btw.

    I did also setup the tmpsf for my gentoo tmp folders in make.conf:
    PORTAGE_TMPFS=”/mnt/portagetmpfs”
    PORTAGE_TMPDIR=”/mnt/portagetmpfs”
    BUILD_PREFIX=”/mnt/portagetmpfs”
    CCACHE_DIR=”/var/tmp/ccache”
    CCACHE_SIZE=”2G”

    How about using the inotify option for syncing files to the harddisk?
    There is also an other tool that syncs quicker, but is more used in clouds if I remember correctly. (…searching…) ah found it (2 days later ;-)) csync2

  10. some kid says:

    something is really wrong with my tmpfs. see, this is what happens. i forget to use crontab script and somehow firefox restores itself? whats up with that?

  11. tort says:

    Thanks, man. Best article among similar.

  12. […] ,以及后来的改进:用tmpfs让Firefox在内存中飞驰II ,其中提到的脚本来自speeding up firefox with tmpfs and automatic rsync […]

  13. […] 最常见的用途是用内存空间来放Firefox的配置,可以让慢吞吞的FF快很多,参见Shellex的博文:用tmpfs让Firefox在内存中飞驰,以及后来的改进:用tmpfs让Firefox在内存中飞驰II,其中提到的脚本来自speeding up firefox with tmpfs and automatic rsync。 […]

  14. […] speeding up firefox with tmpfs and automatic rsync (shell-script) Original […]

Leave a Reply

 
Powered by Wordpress and MySQL. Original theme by openark.org - customization by me :)