Subscribe to Windows IT Pro

 

Get Newsletters

  • Get the Latest News
  • Product Updates
  • Helpful Tricks
  • Productivity Tips

Subscribe Now!

January 14, 2000 10:10 AM

Real-World Scripting: Test Copy Throughput With a Script

Windows IT Pro
InstantDoc ID #7994
Rating: (1)
Downloads
7994.zip

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:

  1. 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 \Perl\html directory for information about how to install PPM.

  2. 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.)

  3. Run FileCopyTest.exe on the source computer with the following arguments:
    FileCopyTest.exe
      \\destination\share
      log_file_location
    

    where \\destination\share 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
       "\\destination\share 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 /?
    
  4. 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.

  5. 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.

  6. For simplicity, you can make shortcuts for the \\destination\share 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\\destination\share argument) is in the Target field and the drive location (i.e., the log_file_location argument) is in the Start in field.

  7. 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
    \\dom1pdc\samples 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.

Related Content:

ARTICLE TOOLS

Comments
  • zach
    4 years ago
    Jun 12, 2008

    good

You must log on before posting a comment.

Are you a new visitor? Register Here

advertisement

advertisement

White Papers

Get your Windows 7 deployment off to the right start by implementing PC lockdown. A locked-down environment is easier and cheaper to support since users are less likely to make unnecessary changes to the core system configuration - read more here!

Essential Guides

Is your iSCSI "lossy"? The reality is that most off-the-shelf Ethernet hardware deployed for iSCSI can lose packets, resulting in slow performance or application downtime. Learn how to assess your current iSCSI infrastructure and engineer an advanced iSCSI SAN infrastructure.

Web Seminars

What's the best way to keep your network safe from malware? In this web seminar, security expert Greg Shields suggests an alternative method to the traditional blacklisting approach that is common with anti-virus and anti-malware solutions.

eLearning Series

We bring the experts direct to you to share their real-world perspective and expertise. During each event, three sessions stream in real time, so you can learn, ask questions, and get solutions.
Upcoming event: Getting the Most with Exchange 2010 with Paul Robichaux

Subscribe to Windows IT Pro!

Windows is a trademark of the Microsoft group of companies. Windows IT Pro is used by Penton Media Inc. under license from owner.