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 »
11,238 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 »
11,238 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 »
11,238 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 »
11,238 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 »
11,238 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
Ben Nadel's Company - Epicenter Consulting Recent Blog Comments
May 17, 2013 at 7:42 PM
HashKeyCopier - An AngularJS Utility Class For Merging Cached And Live Data
Ben - thanks so much for posting these Angular articles and findings, they've been a huge help towards learning one of the more 'complex' JavaScript frameworks out there (IMO). I have been using Angu ... read »
May 16, 2013 at 5:01 PM
UPDATE: Parsing CSV Data Files In ColdFusion With csvToArray()
Your code was the closest thing I've found to obtaining some direction for converting ISO fields to values that CF can translate properly. Thank you for posting! ... read »
May 15, 2013 at 10:37 PM
Very Simple Pusher And ColdFusion Powered Chat
hi id making plz easy ... read »
May 15, 2013 at 6:07 PM
Making SOAP Web Service Requests With ColdFusion And CFHTTP
Ben, you once again saved my bacon at work. Thank you, thank you, thank you! ... read »
May 15, 2013 at 4:15 PM
What If All User Interface (UI) Data Came In Reports?
@Josh, Thanks! @Ben, I definitely recommend the David West book "Object Thinking" I've been quoting from. It goes deeply into the philosophy and history of OO programming. His breadth ... read »
May 15, 2013 at 11:36 AM
Ask Ben: Print Part Of A Web Page With jQuery
I found this helpfull when you need to keep (refresh) the original parent page after closing the iframe child print dialog (Hoping you're not using a form at this time so it won't submit again): On ... read »
May 14, 2013 at 7:13 PM
What If All User Interface (UI) Data Came In Reports?
@Jonah, If there's any books you'd recommend on the subject of domain modelling, I'd love to hear it. I just downloaded the free PDF of "Domain Driven Design Quickly". Figured I'd give it ... read »
May 14, 2013 at 6:57 PM
The UX Of Prototyping: Low-Fidelity Is The New High-Fidelity
@Phillip, I'm not sure I follow what you mean? Are you saying that you looked at the list of widgets provided by the jQuery UI and let that be your style guide? ... read »
InVision App - Prototyping Made Beautiful With Prototyping Tools