jQuery in Action, 2nd edition*
The moose likes Testing and the fly likes Ejb Performance testing tool Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Engineering » Testing
Bookmark "Ejb Performance testing tool" Watch "Ejb Performance testing tool" New topic
Author

Ejb Performance testing tool

Steve Grant
Ranch Hand

Joined: Nov 24, 2003
Posts: 106
Dear Sir,
Which is the best tool for Ejb performance testing.
I have seen JunitPerf tool on internet but i dont know whether I should go for it.
Thanks & regards ,
Siddharth


SCJP1.4<br />IBM Certified System Administrator -- WebSphere Application Server V5.0 (340)
Lasse Koskela
author
Sheriff

Joined: Jan 23, 2002
Posts: 11962
    
    5
What do you really want to test? Do you want to test how long it takes for your EJB code to execute for a single call? Do you want to test how many simultaneous users your EJB container as a whole can accomodate? Something else?
You could take a look at black-box testing tools such as Mercury LoadRunner, WinRunner, Grinder, etc. Also, it is possible to exercise your system using tools such as JUnitPerf and HttpUnit in combination. The biggest differences come in the usability aspects (GUI versus writing Java code), and whether you want to verify or measure (JUnitPerf can only verify that the execution times stay below what's expected, it can't report average throughput, response times, CPU usage, etc.).


Author of Test Driven (2007) and Effective Unit Testing (2013) [Blog] [HowToAskQuestionsOnJavaRanch]
Steve Grant
Ranch Hand

Joined: Nov 24, 2003
Posts: 106
Originally posted by Lasse Koskela:
What do you really want to test? Do you want to test how long it takes for your EJB code to execute for a single call? Do you want to test how many simultaneous users your EJB container as a whole can accomodate? Something else?
You could take a look at black-box testing tools such as Mercury LoadRunner, WinRunner, Grinder, etc. Also, it is possible to exercise your system using tools such as JUnitPerf and HttpUnit in combination. The biggest differences come in the usability aspects (GUI versus writing Java code), and whether you want to verify or measure (JUnitPerf can only verify that the execution times stay below what's expected, it can't report average throughput, response times, CPU usage, etc.).

Dear Sir,
Actually i have written a ejb(stateless session ejb) which calls a class called VFIOService. This class is responsible for writing and reading files from hard disk .I want such a tool which will simulate number of users who will be writing and reading their files with this ejb . Also i want to check the performance of this implemented ejb which will be in terms of response times . Can u plzzz suggest me a good tool for this purpose.
Lasse Koskela
author
Sheriff

Joined: Jan 23, 2002
Posts: 11962
    
    5
So you want to check that with a given number of simultaneous users, the EJB invocations execute within a given response time expectation? If that's the case, I think you should try JUnitPerf (or plain JUnit and write the threading/multi-user stuff yourself).
Steve Grant
Ranch Hand

Joined: Nov 24, 2003
Posts: 106
Dear Sir,
I have implemented JunitPerf in my project and I have started getting results. My stateless session ejb is using a class called VFSIOservice which writes 3 Mb byte array size to the hard disk.
With JunitPerf I have silmulated 10 users who will be uploading their data of 3mb each . each user is taking 10 secs to upload the file . Now how should i achieve the result so that i can achieve 3 to 4 secs for each user.My VfsIOService is just using BufferedOutputStream to write the file.
Now my ejb is on the remote machine .I have deployed my ejb on that machine and I run it from my machine through JunitPerf. The machine on which ejb was deployed was having 512 mb ram with websphere running and 1.4ghz CPU.
I just wanted to ask that because the remote machine was having this configuration and the memory was so less that is why the response time was so slow???. I cannot run the ejb on my machine locally though i have websphere because when i deployed the ejb on my server and tested it with JunitPerf ,my server became slow and the response time was some where between 5 to 6 secs
Can u plzz help in this matter.
Lasse Koskela
author
Sheriff

Joined: Jan 23, 2002
Posts: 11962
    
    5
What size of buffer are you using with your BufferedOutputStream? You could try increasing or decreasing that and see whether it makes a difference. If the bottleneck is your network interface, I'm afraid there's nothing much you can do...
Steve Grant
Ranch Hand

Joined: Nov 24, 2003
Posts: 106
my bufferedoutputstream is of 1024 size. i tested it by increasing its size but still no major affect is seen. sir , if this java io api does not give proper performance then should i go for some external io api which are written in c or c++. my ejb will call this api.
Lasse Koskela
author
Sheriff

Joined: Jan 23, 2002
Posts: 11962
    
    5
Actually, 3 megabytes in 10 seconds is 300 kilobytes per second, which is really not too bad and may very well be in the upper limit of your network connection (unless you're using localhost instead of a physically remote machine).
I doubt you can improve the performance much without dropping the EJB (which first reads the input parameter into memory, and only then starts writing it into the BufferedOutputStream, I assume?) and switching into a streaming connection.
You could see some performance benefits by using C++ but the difference would be most probably insignificant compared to what you can achieve with Java (using the same approach that you would use in your C++ implementation).
Steve Grant
Ranch Hand

Joined: Nov 24, 2003
Posts: 106
Dear Sir,
Actually my project architecture is as follows:
1 First there is a stateless session ejb called RFS which sends the file data in the form of byte array to the other stateless session ejb which is called as VFS.Now this VFS calls the VFSIOService (a normal class) for writing this byte array to the hard disk.
2 Now in my project I have to do the VFS module of which i have finished the coding part.The RFS module which is to be done by another programmer is not finished yet.Now i have been told to do the performance testing of this VFS.
3 Sir what is this streaming connection which u have metioned in ur previous reply.can u plzz clarify ....
Lasse Koskela
author
Sheriff

Joined: Jan 23, 2002
Posts: 11962
    
    5
With a "streaming connection", I meant that you would start writing the file right after receiving the first bytes from the caller. In other words, use an InputStream and OutputStream instead of passing around byte arrays. However, it sounds like you don't have that choice so maybe you should just leave it as it is.
Steve Grant
Ranch Hand

Joined: Nov 24, 2003
Posts: 106
Dear Sir,
Thanks for ur previous replies.Sir , I had gone through the java.io source code and for BufferedInputStream it is specified that this stream by default specifies 2048 bytes.Sir can i override this method and provide more buffering.Can i apply the same for BufferedOutputStream
Following is the source code of VFSIOService class which does reading and writing:
public class VFSIOService {
/**
* This is the constant which holds the byte size
* which can be used while reading and writing.
*/
public static final int BYTE_SIZE = 1024;
/**
* This is the constant which represents start offset in the array
*/
public static final int START_OFFSET = 0;
/**
* This is the constuctor .
*/
public VFSIOService() {
}
/**
* This method writes the file to the hard disk.
* This method calls the security service if the vault type is secure
*
* @param FileTOThe File object contains file related details
* @return void
* @throws VFSException
*/
public void addFile(FileTO fileTO) throws VFSException
{

//create the file object from absolute path
File file = null;
File fileParentPath = null;
BufferedOutputStream bout = null;
file = new File(fileTO.getAbsolutePath());

//get the parent path of the file
fileParentPath = new File(file.getParent());

//check parent path exists
if (fileParentPath.exists() == false)
{
//create directories
fileParentPath.mkdirs();
}

try
{
// Check the vault type
if (fileTO.getVaultType() == StorageTypeConst.TYPE_SECURE)
{
//get the security facade home
SecurityFacadeHome securityServiceHome = (SecurityFacadeHome)
ServiceLocator.getHome(JNDIConst.JNDI_SECURITYFACADE_HOME,
SecurityFacadeHome.class);

//get the remote reference
SecurityFacade securityServiceremote = securityServiceHome.create();

// call the encode method
securityServiceremote.encode(fileTO);

}
else if (fileTO.getVaultType() ==
StorageTypeConst.TYPE_REGULAR)
{

// create buffered output stream to the file
bout = new BufferedOutputStream(new
FileOutputStream(file),BYTE_SIZE);

//write the bytes to the file
bout.write(fileTO.getFileBytes(),
START_OFFSET,fileTO.getFileBytes().length);

}
else
{
//delete the above created folder
fileParentPath.delete();

// throw exception for invalid valut type
throw new VFSException(ExceptionMsg.VFS.FILE_CREATION_ERROR);

}
}
catch(ServiceLocatorException exception)
{
throw new VFSException(ExceptionMsg.VFS.FILE_CREATION_ERROR);
}
catch(SecurityException exception)
{
throw new VFSException(ExceptionMsg.VFS.FILE_CREATION_ERROR);
}
catch(CreateException exception)
{
throw new VFSException(ExceptionMsg.VFS.FILE_CREATION_ERROR);
}
catch(FileNotFoundException exception)
{
throw new VFSException(ExceptionMsg.VFS.FILE_CREATION_ERROR);
}
catch(IOException exception)
{
// deleting the destination file
if(file != null)
file.delete();

throw new VFSException(ExceptionMsg.VFS.FILE_CREATION_ERROR);
}
finally
{
try{
if(bout != null)
bout.close();
}
catch(IOException exception)
{
// deleting the destination file
if(file != null)
file.delete();
throw new VFSException(ExceptionMsg.VFS.FILE_CREATION_ERROR);
}

}

}

/**
* This method writes the file to the hard disk and it calls
* the security service if the vault type is secure. This method is used when
* the file has to be overwritten on the disk
*
* @param FileTOThe File object contains file related details
* @param originalFilePathThe path of existing file which is to be deleted
* @return void
* @throws VFSException
*/
public void addFile(FileTO fileTO, String originalFilePath)
throws VFSException
{
try{
// call the above addFile method
addFile(fileTO);

//Check the absolutePath and originalFilePath are not same
if(!fileTO.getAbsolutePath().trim().equals(originalFilePath.trim()))
{
if(deleteFile(originalFilePath) == false )
{
throw new VFSException(ExceptionMsg.VFS.FILE_CREATION_ERROR);
}
}
}
catch(VFSException exception)
{
throw new VFSException(ExceptionMsg.VFS.FILE_CREATION_ERROR);
}
}
/**
* This method deletes the original file from the hard disk.
*
* @param originalFilePathThe original file path which is to be deleted
* @return boolean
*/
private boolean deleteFile(String originalFilePath)
{
File file = new File(originalFilePath );

//returns true if delete is successful else false
return file.delete();
}
/**
* This method reads the file from the hard disk.
* This method calls the security service if the vault type is secure
*
* @param FileTOThe File object contains file related details
* @return FileTO
* @throws VFSException
*/
public FileTO downLoadFile(FileTO fileTO) throws VFSException
{
BufferedInputStream bis = null;
try
{
//create file object from absolute path
File file = new File(fileTO.getAbsolutePath());

// Check for file existence
if( !file.exists() )
{
throw new VFSException(ExceptionMsg.VFS.FILE_DOWNLOAD_ERROR);

}
else
{
// Check the vault type
if (fileTO.getVaultType() == StorageTypeConst.TYPE_SECURE)
{

//get the security facade home
SecurityFacadeHome securityServiceHome = (SecurityFacadeHome)
ServiceLocator.getHome(JNDIConst.JNDI_SECURITYFACADE_HOME,
SecurityFacadeHome.class);

//get the remote reference
SecurityFacade securityServiceRemote =
securityServiceHome.create();

fileTO = securityServiceRemote.decode(fileTO);

}
else if (fileTO.getVaultType() ==
StorageTypeConst.TYPE_REGULAR)
{
bis = null;

// create input and output stream
bis = new BufferedInputStream(new
FileInputStream(file));
// create the byte array of file length
byte fileBytes[] = new byte[(int)file.length()];

// read the file and copy its contents into array
bis.read(fileBytes,START_OFFSET,fileBytes.length);

// set the file bytes read to fileTO file bytes
fileTO.setFileBytes(fileBytes);

}
else
{
// throw exception if vault type is invalid
throw new VFSException(ExceptionMsg.VFS.INVALID_VAULT_TYPE);

}

}//end of else

return fileTO;
}
catch(SecurityException exception)
{
throw new VFSException(ExceptionMsg.VFS.FILE_DOWNLOAD_ERROR);
}
catch(ServiceLocatorException exception)
{
throw new VFSException(ExceptionMsg.VFS.FILE_DOWNLOAD_ERROR);
}
catch(FileNotFoundException exception)
{
throw new VFSException(ExceptionMsg.VFS.FILE_DOWNLOAD_ERROR);
}
catch(IOException exception){

throw new VFSException(ExceptionMsg.
VFS.FILE_DOWNLOAD_ERROR);
}
catch(CreateException exception)
{
throw new VFSException(ExceptionMsg.
VFS.FILE_DOWNLOAD_ERROR);
}
finally
{
try{

if(bis != null)
bis.close();

}catch(IOException exception){

throw new VFSException(ExceptionMsg
.VFS.FILE_DOWNLOAD_ERROR);
}
}

}

}
Steve Grant
Ranch Hand

Joined: Nov 24, 2003
Posts: 106
Dear Sir,
the above source code has two methods.The method addFile does the file writing. and downLoadFile reads the file from hard disk. The FilTO class will have fileBytes member variable which are to be written to the file.
Thanks & regards,
Siddharth K
Lasse Koskela
author
Sheriff

Joined: Jan 23, 2002
Posts: 11962
    
    5
Again, I believe the only way to improve the performance is to start doing the work earlier (using Input/OutputStreams instead of byte[] and File). I'll move this discussion into the performance forum. Maybe you could get more advice there.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Ejb Performance testing tool