Real-World Scripting: Test Copy Throughput With a Script
This monthly column offers practical scripts for systems administrators. The February column provides a script, FileCopyTest.pl, that measures and logs copy throughput (i.e., the transfer rate of files) between machines.
January 14, 2000
As the administrator of a resource domain that services several thousand users, management has asked you to determine benchmarks for the transfer rate of files (i.e., copy throughput) between the domain servers and the lab computers. You've noticed a decrease in performance but haven't been able to diagnose conclusively which servers, hard disk arrays, and network links are having problems. You decide to develop a script that measures and logs copy throughput. Specifically, you want the script to
Capture the length of time it takes to copy a 100MB test file from a source computer (i.e., the server or workstation from which you're sending the test file) to a destination computer (i.e., the server or workstation to which you're sending the test file)
Calculate the copy throughput in megabytes per minute
Have a configurable test-file size
Display the current results onscreen, and append the results to a log file
Make all the files needed to perform the test small enough to fit on a 3.5" disk
Meeting the Script Requirements
Although you could write the FileCopyTest script in Windows NT shell scripting, using Perl is better because Perl provides more accurate math functions than NT shell scripting. However, to use Perl, you must overcome two hurdles.
The first hurdle is how to make the script portable given the 100MB test file. One solution is to put the test file on a network server. However, with this solution, the script takes longer to execute because the source computer must copy the test file from the network server before the testing begins. A better solution is to include a section of code in the script that creates the test file on the source machine. At the end of the test, the user has the option of deleting the test file or leaving the test file in place for another test operation. As the code in Listing 1 shows, if the script detects an existing test file, the script skips the test-file creation code and proceeds directly to the testing code. Listing 1 is only an excerpt from FileCopyTest.pl. You can find the entire script, complete with comments, in the Code Library on the Win32 Scripting Journal Web site at http://www.win32scripting.com.
The second hurdle is that the Perl library must be on all the source computers that you want to test. In this instance, that number is in the thousands, so installing the Perl library on all of them would be too time-consuming. One solution is to place the Perl library on a server and have the script point to that library. However, this solution requires that you set up and maintain a share point just for testing copy throughput. Some companies try to avoid using formal shares (even hidden ones) for short-term administration purposes because these shares tend to become orphaned but never deleted for no one can remember who created them or why they were created. A better solution is to convert your completed Perl script into an .exe file with a command-line conversion program, such as DynamicSTATE's Perl2Exe or ActiveState's PerlApp. If you convert FileCopyTest.pl to an executable, you don't need to install the Perl library on all the source computers. In addition, with an executable, you can distribute the code on a disk yet protect the code from accidental or intentional modification. The Code Library on the Win32 Scripting Journal Web site includes the executable FileCopyTest.exe.
You can download free trial versions of Perl2Exe and PerlApp. Perl2Exe is available at http://www.dynamicstate.com. PerlApp, which is part of ActiveState's Perl Dev Kit, is available at http://www.activestate.com/pdk. If you plan to regularly distribute code to remote machines or machines on which users haven't installed Perl, you might consider purchasing a command-line conversion program.
Preparing, Converting, and Running the Script
I wrote and tested FileCopyTest.pl on servers and workstations running NT 4.0 with Service Pack 5 (SP5) and on workstations running Windows 2000 Professional (Win2K Pro) Professional pre-release. Here are the steps to prepare, convert, and run this script for your system:
Download and install Perl for Win32 and the Win32::AdminMisc and Win32::Message extensions on the NT workstation or server on which you're editing, testing, and converting the script. Perl for Win32 is part of ActivePerl. (I used ActivePerl build 522.)
ActivePerl and the Win32::AdminMisc and Win32::Message extensions are available as free downloads. You can download ActivePerl from ActiveState at http://www.activestate.com. ActivePerl installs easily from a self-extracting executable. The Win32::AdminMisc and Win32::Message extensions are available from Roth Consulting at http://www.roth.net/perl. Follow the online instructions to install the extensions. You can also use ActivePerl's Perl Package Manager (PPM) to locate, install, and verify your Perl extensions. Consult the ppm.html file in the Perlhtml directory for information about how to install PPM.Use the command-line conversion program to create an .exe version of the script. The command to prompt the conversion process depends on the program you use. For example, the command for Perl2Exe is
Perl2exe FileCopyTest.pl
This command prompts Perl2Exe to convert FileCopyTest.pl into FileCopyTest.exe and place that executable in the directory in which you ran the command (typically the C directory). Optional switches for the command are available. (For information about the switches, see the Perl2Exe User Manual at http://www.dynamicstate.com/pxman.htm.)
Run FileCopyTest.exe on the source computer with the following arguments:
FileCopyTest.exe \destinationshare log_file_location
where \destinationshare is the Uniform Naming Convention (UNC) path to the log file in which you want to log the results and log_file_location is the log file's drive (e.g., C). If you have a share name with a space in it, enclose the UNC path in double quotes with code such as
FileCopyTest.exe "\destinationshare XYZ" C:
Because the script's comments aren't visible after you convert the script into an executable, the script includes code to display Help information if you forget to enter the arguments. The Help information also appears if you type either of these commands:
FileCopyTest.exe ?FileCopyTest.exe /?
Check for disk space on both the source and destination computers. The script tries to locate the temp directory on your source computer. If the script can't locate that directory from the Temp system environment variable, the script puts the file in the C: root location.
Make sure that both the source and destination computers have Change permission. If the copy operation fails, a pop-up message appears specifying whether the wrong permission, lack of disk space, or incorrect syntax caused the copy failure.
For simplicity, you can make shortcuts for the \destinationshare and log_file_location arguments. Most environments have a limited number of destination computers, so you can make a shortcut for each computer. After you create the shortcut, right-click it and select Properties, Shortcut. Make sure the path (i.e., the\destinationshare argument) is in the Target field and the drive location (i.e., the log_file_location argument) is in the Start in field.
To make FileCopyTest.exe portable, copy the executable and the log file onto a disk. If you plan to use shortcuts on the disk, set the Target shortcut property to
A:FileCopyTest.exe\dom1pdcsamples A:
and the Start in: shortcut property to
A:
The Code Library on the Win32 Scripting Journal Web site includes a shortcut to run the FileCopyTest.exe script from the A drive.
Viewing the Results
After you run FileCopyTest.exe, the results will appear both on screen and in the log file. Figure 1 contains an example of a resulting log file.
About the Author
You May Also Like