I am working in a desktop application using java. In my application i have to perform a speed test which will show the file uploading and downloading speed.
For uploading test i am uploading a small test file to a FTP server and based on time taken i am calculating the file upload speed. similarly i am downloading a test file form server and calculating download speed.
But result i am getting doesn't match with actual FTP file uploading and downloading speed.it seems that the establishing connection to FTP server is increasing the time, hence the resultant speed i am calculating is less.
here is the file uploading code i am using:
public int getTransferRate(File filename)
{
int trRate = 0;
try {
OutputStream fout = null;
InputStream bin = null;
connect(ftpUser,ftpPass,ftpServer);
ftp.setFileType(FTPSClient.BINARY_FILE_TYPE);
ftp.enterLocalPassiveMode();
fout = ftp.storeFileStream("testuploadfile");
bin = new FileInputStream(filename);
byte[] b = new byte[8192];
int bytesRead = 0;
long startTime = System.currentTimeMillis();
long endTime = 0;
while ((bytesRead = bin.read(b)) != -1) {
fout.write(b, 0, bytesRead);
bytesUploadedSet += bytesRead;
}
endTime = System.currentTimeMillis();
trRate = (int) ((float) bytesUploadedSet / (endTime - startTime));
} catch (IOException ex) {
Logger.getLogger(FTPFileStorageService.class.getName()).log(Level.SEVERE, null, ex);
}
return trRate;
}
Could you suggest any link or some way to get nearest uploading and downloading speed.
i thanks to all your valuable suggestion.
First of all ,filezilla probably uses native code which will be faster than what you are using.
For testing, establish a connection and try uploading many files, about 20 or so..that should give a good idea of the result..usually, also log your output to a comma separated test file or something, which you can later import into excel and analyze. You can use something like JMeter if you want to do some hard core performance testing..
In any kind of performance testing having a large sample size (lot of sample results) gives most accurate results.
http://jmeter.apache.org/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With