Introduction

If some of your actions do data transfers, it is valuable to monitor how much data is transferred.

We cannot measure how much data goes over the wire, but we can still get a good idea by using a simple trick.



Example code


As a starting point, we will use the already presented action class called FileTransferActions

We will replace the upload action as follows:

@Action(transferUnit = "Byte")
public Long upload( @Parameter(name = "localFilePath") String localFilePath ) {
 
    // remember the length of the file we will transfer
    long fileLength = new File( localFilePath ).length();
 
    // transfer the file
    transferClient.uploadFile( localFilePath, "/" );
 
    // the file transferred, return its length
    return fileLength;
}

As you see now the Java method returns a Long value which is the length of the transferred file. We have also stated in the @Action annotation this action will return the number of transferred bytes - see the transferUnit attribute.



Result

Here is what you might get as a result:

Our average transfer rate is almost 20 MB/sec

It is easy for us to calculate the transfer rate as we always know the action execution time and additionally your action is giving us the transfer size as well.



Change the transfer unit

The presented example shows very large numbers.

This can be changed by returning the transfer size in KBytes (you have to divide the numbers by 1024) or in MBytes (you have to divide the numbers by 1024*1024). Do not forget to change accordingly the transferUnit attribute.



Back to parent page

Go to Table of Contents