Learning ColdFusion 9: Virtual File System vs. Actual File System

Posted July 17, 2009 at 5:55 PM by Ben Nadel

Tags: ColdFusion

Earlier today, I blogged about the new Virtual File System available in ColdFusion 9. I explained that the virtual file system was just like the actual file system except that you were writing to the "ram://" disk rather than to the hard drive. I wrote that the biggest benefit of this new virtual file system was the performance gain - that it was much less expensive to read and write to RAM than it was to an actual disk. I knew this was true, but I didn't have any numbers to back up the statement. As such, I decided to run a very simple speed test comparing the performance of the virtual file system to the actual file system.

This is not a scientific test by any means; nor, did I run this under any kind of load. But, as both file systems were tested in the same environment, I believe that we can still take away some meaning from the results:

  • <!---
  • Param the url variable for determining which file system
  • to be testing with this execution.
  • --->
  • <cfparam name="url.vfs" type="boolean" default="false" />
  •  
  • <!--- Depending on the URL, figure out the directory. --->
  • <cfif url.vfs>
  •  
  • <!--- Use the virtual file system. --->
  • <cfset workDirectoryPath = "ram://temp/" />
  •  
  • <cfelse>
  •  
  • <!--- Use the actual file system. --->
  • <cfset workDirectoryPath = (
  • getDirectoryFromPath( getCurrentTemplatePath() ) &
  • "temp/"
  • ) />
  •  
  • </cfif>
  •  
  •  
  • <!--- Check to make sure our target directory exists. --->
  • <cfif !directoryExists( workDirectoryPath )>
  •  
  • <!--- Create it so that our file writes don't fail. --->
  • <cfdirectory
  • action="create"
  • directory="#workDirectoryPath#"
  • />
  •  
  • </cfif>
  •  
  •  
  • <!---
  • Read in a file from the actual file system. This is a
  • moderetly sized file at just under 700KB.
  • --->
  • <cfset dataFile = fileRead( expandPath( "./target.jpg" ) ) />
  •  
  •  
  • <!--- ----------------------------------------------------- --->
  • <!--- ----------------------------------------------------- --->
  •  
  • <!--- Get the start time. --->
  • <cfset startTickCount = getTickCount() />
  •  
  • <!--- Loop over the given file system a number of --->
  • <cfloop
  • index="iteration"
  • from="1"
  • to="1000"
  • step="1">
  •  
  • <!--- Create a path variable for a new file. --->
  • <cfset newFilePath = "#workDirectoryPath##iteration#.jpg" />
  •  
  • <!--- If this new file currently exists, then delete it. --->
  • <cfif fileExists( newFilePath )>
  •  
  • <!--- Delete the existing file. --->
  • <cfset fileDelete( newFilePath ) />
  •  
  • </cfif>
  •  
  • <!--- Write the data file to target file system. --->
  • <cfset fileWrite( newFilePath, dataFile ) />
  •  
  • <!--- Read the new file into memory. --->
  • <cfset newFile = fileRead( newFilePath ) />
  •  
  • <!--- Delete the new file. --->
  • <cfset fileDelete( newFilePath ) />
  •  
  • </cfloop>
  •  
  • <!--- Get the end time. --->
  • <cfset endTickCount = getTickCount() />
  •  
  • <!--- ----------------------------------------------------- --->
  • <!--- ----------------------------------------------------- --->
  •  
  •  
  • <!--- Output results. --->
  • <cfoutput>
  •  
  • <p>
  • <cfif url.vfs>
  • Virtual File System
  • <cfelse>
  • Actual File System
  • </cfif>
  • </p>
  •  
  • <p>
  • <strong>Results:</strong>
  •  
  • #numberFormat( (endTickCount - startTickCount), "," )#
  • </p>
  •  
  • </cfoutput>

As you can see from the code, I am running several file checks, reads, and writes over a thousand iterations. I ran this 5 times with the actual file system and another 5 times with the virtual file system (discarding the first few results for compilation and optimization overhead). Here are my results:

Actual File System

  1. Results: 22,407
  2. Results: 23,969
  3. Results: 22,703
  4. Results: 23,860
  5. Results: 20,922
  6. Average: 22,772

Virtual File System

  1. Results: 5,500
  2. Results: 5,594
  3. Results: 5,844
  4. Results: 5,860
  5. Results: 6,000
  6. Average: 5,759

As you can see, accessing ColdFusion 9's Virtual File System is about 4 times faster than accessing the actual file system. Not a bad performance boost for transient files.


You Might Also Be Interested In:



Reader Comments

Jul 17, 2009 at 7:12 PM // reply »
11 Comments

Only 4 times faster? I was expecting several orders of magnitude faster.. this is somewhat surprising.


Jul 17, 2009 at 7:48 PM // reply »
110 Comments

@Drew,
My sentiments exactly. The gains are nice but I figured they would be more.


Jul 18, 2009 at 2:23 AM // reply »
34 Comments

4 times faster is extremely fast. Imagine if a Lambo could go 4 times faster. WOW!

But I have a question how could you put this to practical use? What information could you store in the RAM?


Jul 18, 2009 at 3:36 AM // reply »
2 Comments

Why is the RAM time increasing. Does it keep increasing if it ran 10 times ?


Jul 18, 2009 at 8:37 AM // reply »
2 Comments

@ Drew & Gareth

I agree with Jody....4 times faster is fast! Not sure what else you would want or could expect.

@ Jody

I am building a back end photo system for a shopping cart admin. Meaning I am building a system that allows admin users with the lack of Photoshop skills to crop, resize, add borders, text and other enhancements to there photos as they upload them into the front end of the store. (all with cfimage and functions!!) Now with the virtual file system I can easily add a small preview window for the user to see their results before finalizing the work. Yes...I could have done this before the virtual way, but it will have a little more zoom zoom this way.


Jul 18, 2009 at 10:03 AM // reply »
110 Comments

You're writing to RAM though (measured in nanoseconds) vs writing to disk (measured in milliseconds). That is a 1000 times faster access. So, yes, I agree that 4 times faster is "faster", but accessing it from ram vs accessing it from the hard drive isn't showing the gains I was expecting.


Jul 18, 2009 at 12:02 PM // reply »
10,640 Comments

Also, to keep in mind, I am running ColdFusion on my work laptop as a stand alone install. This is probably not the most powerful machine.


Jul 18, 2009 at 12:27 PM // reply »
67 Comments

Hi Ben
I'd be interested in seeing the results if you individually time each discrete action (so separate timings for the deletes, writes and reads), rather than timing all four actions together.

--
Adam


Jul 18, 2009 at 12:33 PM // reply »
10,640 Comments

@Adam,

That could be interesting. I'll see if I can run some tests.


Jul 18, 2009 at 2:30 PM // reply »
45 Comments

I'm curious if this is a faster approach to image processing/resizing.

Anyone run image resizing tests?


Jul 18, 2009 at 3:43 PM // reply »
10,640 Comments

@David,

Only if it requires intermediary file writes. There's nothing about the file system that will speed up the image processing itself.


Jul 18, 2009 at 11:52 PM // reply »
3 Comments

Speaking of file systems, I'm working on doing a fix to your system where you can view images, and possibly edit text. All in good time thou.


Jul 19, 2009 at 1:25 AM // reply »
53 Comments

I concur with Mikkel, is there a memory leak in the VFS functionality?


Jul 19, 2009 at 11:46 AM // reply »
10,640 Comments

@Andrew,

I don't think so. If you look at the second test, it's actually lower than the first. I think the ups and downs are just the consequence of other background processes taking processing power.


Jul 22, 2009 at 1:00 AM // reply »
7 Comments

You're using a mapping for ease and cleaner syntax but this is only accessable from one instance (instance specific) and not across CF servers in a cluster right? CF instances in a multi-node enviornment wouldn't be able to share these "files" written to RAM if they had the same mappings would they?


Jul 22, 2009 at 7:48 AM // reply »
10,640 Comments

@Ted,

I don't know much about clustering, but you're probably correct.



Post A Comment

Comment Etiquette: Please do not post spam. Please keep the comments on-topic. Please do not post unrelated questions or large chunks of code. And, above all, please be nice to each other - we're trying to have a good conversation here.

Please review the following issues:

Author Name:


Author Email:

Author Website:

Comment:

Supported HTML tags for formatting: <strong>bold</strong>   <em>italic</em>   <code>code</code>







  • Help Wanted - Find Your Next ColdFusion Job
InVision App - Prototyping Made Beautiful With Prototyping Tools Ben Nadel's Company - Epicenter Consulting Recent Blog Comments
Feb 10, 2012 at 7:21 PM
jQuery AJAX Strips Script Tags And Inserts Them After Parent-Most Elements
Update! Instead of $(eval(options.insertAfter)).after(data['insertData']); I now use: var ajaxNode = document.createElement('span'); var parent = $(eval(options.insertAfter))[0].parentNode; ... read »
Feb 10, 2012 at 6:18 PM
jQuery AJAX Strips Script Tags And Inserts Them After Parent-Most Elements
encountered this same, what I consider, jQuery bug last week. I'm building a site in which I load some content via AJAX. This content contains Linkedin share button placeholders which Linkedin API ne ... read »
Feb 10, 2012 at 11:30 AM
Cross-Origin Resource Sharing (CORS) AJAX Requests Between jQuery And Node.js
After you understand the concepts here, this is an awesome cheatsheet for enabling CORS in just about anything http://enable-cors.org/ ... read »
JM
Feb 10, 2012 at 9:10 AM
My Safari Browser SQLite Database Hello World Example
@Amy, Here is a very good tutorial on how to use JOIN: http://www.sqltutorial.org/sqljoin-innerjoin.aspx ... read »
Feb 10, 2012 at 4:42 AM
Building A Twitter-Inspired RESTful API Architecture In ColdFusion
This is great, very useful Ben. I spotted a small typo in the api.cgm listing: <cfthrow type="Unauthroized" /> Cheers Stefan ... read »
Feb 9, 2012 at 10:35 PM
CFDirectory Filtering Uses Pipe Character For Multiple Filters (Thanks Steve Withington)
I was wondering if there would be a filter you could apply so that you got everything but what you included in the filter. As in show me all docs that are not a .pdf. ... read »
Feb 9, 2012 at 10:29 PM
Learning ColdFusion 9: Application-Specific Data Sources
@Ben, No offence, but if people were really wanting advanced features they would be using a platform like ASP.NET MVC. CFML is so structurally compromised as a tag-based scripting language that ... read »
Feb 9, 2012 at 10:03 PM
Subversion - Cleanup Failed To Process The Following Paths
@Leviaguirre, do you still have problems with this? ... read »