File Read/Write test program

andy andy at eastonwest.co.uk
Tue Jan 7 15:11:33 EST 2003


I had to write a program to test raw read-write speed to several network 
servers today, as we needed to prove that some changes we've made to our 
setup had yielded good results.

It doesn't have any trouble saturating a 100Mb/s link, and seems to yield 
reasonably consistent results.

It gets run under Windows XP, talking to Windows 2000 servers.  

Any comments?

One Q - is there a more intelligent way to generate the required 50MB string?

regards, 
-andyj

# file read/write performance monitor
# repeatedly writes/reads back large file

# modify the following to alter the behaviour of this program:

chunksize=50 # Size (in MB) of file chunks to write - MAX 60

numchunks=2  # Number of chunks to write to file
testcycles=5 # how many times to write the test file
testfile="/testfile.txt" # name of file to write to

megabyte=1048576 # 1024*1024 - REAL megabytes
#megabyte=1024000 # 1000*1024 - DISK megabytes

# test servers - unc name of test directory.
# note must use forward "/" rather than "\" back slashes!
# each pair consists of "//server":"/path"
servers={"//srv01":"/test", # main windows server
         "//srv02":"/test", # tivoli server
         "//srv12":"/test", # main print server
         "c:":"/test"}         # test local drive as control

import os,time

def generate_chunk(megabytes):
    """ returns a string containing megabytes*1048576 asterisks """
    meg="*"
    for n in range(20):
        meg=meg+meg
    chunk=""
    for n in range(megabytes):
        chunk=chunk+meg
    return chunk

def test(path,chunk,count):
    """ writes chunk to file 'path', count times, then reads it all back """
    global chunkin
    t=time.time()
    # write the file
    f=open(path,"wb",1024*1024)
    for n in range(count):
        f.write(chunk)
    f.close()
    # read it back
    f=open(path,"rb",1024*1024)
    chunkin=f.read()
    f.close()
    # delete the file
    os.remove(path)
    dur=time.time()-t
    return dur

def report():
    global servers
    print
    print 
"================================================================================"
    print
    print "Results"
    print "======="
    print
    for server in servers.keys():
        print "%19s" % server,
        servers[server]=0.0
    for cycle in range(testcycles):
        for server in servers.keys():
            print "  %6.2f %6.2fMB/s" 
%(results[cycle][server],(len(chunk)*2.0)/results[cycle][server]/megabyte),
            servers[server]+=(len(chunk)*2.0)/results[cycle][server]/megabyte
        print
    print " Average",    
    for server in servers.keys():
        print "        %6.2fMB/s" % (servers[server]/(testcycles*2)),

# main code
print "Performance test in progress..."
print "==============================="
print
print "Creating data chunk and read buffer..."
results={}
chunk=generate_chunk(chunksize)
# preallocate memory for chunk-in
chunkin=""
for n in range(testcycles):
    chunkin=chunkin+chunk
print
print "Performing test..."
print 
print "Pass",
for server in servers.keys():
    print "%15s" % server,
print
for cycle in range(testcycles):
    print "  %2i" % (cycle+1),
    results[cycle]={}
    for server in servers.keys():
        
results[cycle][server]=test(server+servers[server]+testfile,chunk,numchunks)
        print "     %6.2f" % results[cycle][server],
    print
# print the report        
report()






More information about the Python-list mailing list