3

I have a piece of code which writes a file in Java to a shared Samba folder on a virtual server, but I have a performance issue/question.

The first thing my code does, is checking if the Samba folder exists. If it does, it instantiates the file it is going to write. Then more irrelevant stuff happens.

If I check my log file, there are always 6 seconds between Instantiated destination samba directory... and Checking if the file already exists.... This means that the if(!destination.exists) takes 6 seconds, which looks awefully long, since the if(smbOutputFile.exists)) doesn't even take 1 second. (In my testcase, both of them do exist).

What could be any of the factors of this performance issue? And is there a way to speed this up?

SmbFile destinationShare = new SmbFile(sambaDestinationPath, destinationAuthentication);
logger.info("Instantiated destination samba directory : " + destinationShare);

if (!destinationShare.exists()) { //destinationShare = a directory 
    destinationShare.mkdir();
    logger.debug("Shared directory created");
}

smbOutputFile = new SmbFile(sambaDestinationPath + filename, destinationAuthentication);

logger.debug("Checking if the file already exists and rename it to '.old'");
if (smbOutputFile.exists()) { //smbOutputFile = a file 
    //Do something 
}

Thanks!

Lewis
  • 225
  • 1
  • 6
  • 18
  • FYI, I also use this class I've written in another application using a different Samba share and there it works fine and takes less than a second instead of 6 seconds. So I'm not sure it's directly a Java issue, but rather a Samba or server issue. – Lewis Oct 21 '15 at 08:58
  • I believe this is a rather ambiguous issue. Since you've tried it using a different Samba share which resulted in less than a second to execute, I don't think this is related to the code. Are the two Samba shares you tested located on different servers? If so, one of the servers could be under a heavier load than the other. Have you tried pinging each server? – Tom Nijs Oct 21 '15 at 15:44
  • @TomNijs Ping to the hostname of the slow one = 2ms & ping to the other one = <1ms – Lewis Oct 22 '15 at 06:08

0 Answers0