Symfony scaling: moving your uploads to a NFS share

A few weeks back a client relaunched a Facebook App that commended me to rewrite. The growth since then has been tremendous, with over 2000 registered users everyday, who upload pictures, make friends and comment on other users’ profiles. My application has been able to handle that growth perfectly in terms of responsiveness, but I was told that if the growing rate persisted, within only a few days the content would exceed the hard drive capacity.

The natural solution for these scenarios is a NFS mount, so that the content can be distributed across a network, which gives your application virtually limitless storage capacity. Joyent provides this service reliably.

The biggest challenge was to minimize the downtime, so these were the steps we took:

  1. Move all current files to the NFS mount to clear up disk space
  2. Override the sf_upload_dir configuration directive. In settings.yml

    all:
           upload_dir:      /nfsmount/site/uploads
  3. Adjust the Apache VHost configuration with an alias that points outside the DocumentRoot (hence the need for a special <Directory>)

    Alias /uploads /nfsmount/site/uploads
    <Directory "/nfsmount/site/uploads">
           Order allow,deny
           Allow from all
    </Directory>
  4. Clear symfony cache and reload Apache. If your application is well-written, the change should be transparent to all the modules that deal with file uploads.

  5. Use cp -uvR to make sure no images were left out from the initial copy.
  1. Wow, nfs really…really ?
    NFS mounts are netorious for there instability. The main service likes to hangs from time to time and the mount points them selfs like to just “go stale”. Forcing you to have to “forcefull” restart of NFS at *least* nightly. And all this is independent of the load placed on the servers.

    • Guillermo Rauch 11 months ago

      We never experienced such a thing, and it’s pretty much a de facto in Joyent accelerators :)