views:

65

answers:

3

Hi,

I am writing a media transcoding server in which I would need to move files in the filesystem and till now I am in the dilemma of whether using java renameTo can be replaced by something else that would give me better performance. I was considering using exec("mv file1 file2") but that would be my last bet. Anyone has had similar experiences or can help me find a solution?

+5  A: 

First of all, renameTo is likely just wrapping a system call.

Secondly, moving a file does not involve copying any data from the file itself (at least, in unix). All that happens is that the link from the old directory is removed, and a link from the new directory is added. I don't think you're going to find any performance improvements here.

danben
@danben: a lot of Un*x systems are equipped with more than one partition (either on the same harddisk or spread over more than one harddisk) and surely moving from one partition to another involves copying data from the file itself ;)
NoozNooz42
@NoozNooz42: The OP says he wants to "move files in the filesystem", not move from one file system to another.
danben
Is there a place I can see the code for the implementation of java renameTo call?
Ankur Chauhan
In the source it just calls a native method; you might need to download OpenJDK and dig around in that.
danben
+1  A: 

I don't think that using the default methods for file has a (mentionable) performance penalty as most of this JVMtoOS functions are wrapping native calls already.

The only case where an exec would be needed is if you wanted to do something with different rights than the program or use a special tool to copy/move the file. (e.g. smart-move when ntfs-junctions are involved)

Johannes Wachter
A: 

If rename is a significant performance bottleneck, then you need to improve your hardware as this is your main contraint. The software is a trivial portion of the time spent and optimising it will make little difference.

What is your disk confiugration? How is it optimised for writes?

Peter Lawrey