For a project of mine, I have been using Java RMI to separate my client and server. Now RMI is really cool to transport Java objects for communication, but I have been wondering if I can transport file over RMI. Now I know we can start a flame war over RMI as a file transport medium and I know very well that I can use FTP, SCP, SSH, HTTP and you name it, but I wanted to use something easy short and which fits into my application seamlessly.
To solve this problem I decided to find out how I can actually transport a file over RMI. Small files are not really a problem, just load them in as a byte array and then serialize them over RMI, but you don’t really want to transport multi megabyte files in this way. The larger the file gets, the larger the memory needed just for transportation so I just decided I’d build a session and then transport the file in chunks.
While googling for a solution I came across a few other people trying this, so I decided I’d just blog about it and post my code as well. If someone can use it, then that makes me happy =))
Easy to use:
- Untar to a folder
- run “compile.sh”
- run “runserver.sh 192.168.1.1” on the server
- edit “config.xml” on the client and set the address and the other options
- run “runclient.sh serve.txt” on the client and you will get the test file “serve.txt”
That’s it.
Have fun.
eitch
Update: fixed link to file
Hey h
It would be interesting to measure the performance of this transfer mode and compare it with ftp / ssh protocol. It isn’t said, that the performance is much lower, but I expect, that a difference is measurable.
cheers shortY
Hej h
Would be interesting to compare the performance with an ftp connection.
greetz shortY
I have written a similar code to send file chunks over RMI to remote machine. The application will be used to backup data every few minutes, copying only the additions in 1 file over the network to the other.
I tried using Linux rsync for this, but rsync was too slow only because it compared the entire files to get the difference. But since i already know the difference I thought RMI can help me transport only the difference to the remote file.
After doing all the hard work, I compared the performance with FTP.
Damn! this RMI thing is lazy, it is 1.5 times slower than FTP. If you want some stats:
The time you are looking at is pure network time. I have removed all application time from it.
RMI
Total File Size 521134 MB
Total Milliseconds to Sync = 2371921
Chunk Size = 10 MB
FTP:
533640800 bytes sent in 1385.00Seconds 385.30Kbytes/sec.
I am only looking for ways to get it as close to FTP as I can.
Hi
Thanks for your comment. I always suspected that RMI won’t be very fast compared to real file transport protocols like standard FTP. The reason I wrote this code was to be able to do communication purely in Java. The thing is I have a little “framework” where I have a server side with components and features and a client side which gets the data and does the visualization. If I want to send images from the server to the client, or the client wants to fetch them, then I don’t want to install no FTP-Server for this stuff but stay in a pure Java enviroment. I am also pretty sure that there must be a FTP-Server for Java, I just didn’t take the time to look for it and implement the code.
Thanks anyway for your information. I think I can live with 1.5x longer with RMI since my files probably won’t go over 10MB anyway.
BTW: have you tried what a smaller chunk size would achieve? I don’t think it would speed up the process but it would be interesting what happens if you set the chunksize small enough so that the TCP frame sent is already the right size.
eitch
hi how to compile rmi. and how to create an c# on cart play. help me
Hi, this example is using Java RMI so I can’t help you with c#.