Created
April 11, 2014 06:26
-
-
Save wido/10444002 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
''' | |
Simple Python script which endlessly keeps writing 100MB to a temp file. | |
Used to demonstrate a Ceph cluster. This script runs inside a Virtual Machine (KVM) | |
running on a RBD image on a Ceph cluster. | |
The demo is to randomly pull out machines and show that the script can still write | |
and read data. | |
Author: Wido den Hollander <[email protected]> | |
''' | |
import tempfile | |
import time | |
import os | |
# Filesize in MB to write | |
total_size = 1024 | |
# Write in chunks of 4MB | |
chunk_size = 4 | |
def main(): | |
z = open('/dev/zero', 'r') | |
i = 0 | |
while True: | |
try: | |
start = time.time() | |
f = tempfile.NamedTemporaryFile(dir='/tmp', delete=False) | |
print "[ %d ] Starting to write %dMB to %s" % (i, total_size, f.name) | |
o = 0 | |
while o < (total_size * 1024 * 1024): | |
f.write(z.read(chunk_size * 1024 * 1024)) | |
f.flush() | |
o += chunk_size * 1024 * 1024 | |
print "[ %d ] Done writing to %s, calling fsync" % (i, f.name) | |
os.fsync(f) | |
os.unlink(f.name) | |
runtime = time.time() - start | |
bandwidth = total_size / runtime | |
print "[ %d ] Wrote %dMB to %s in %.2f seconds (%.2fMB/sec)" % (i, total_size, f.name, runtime, bandwidth) | |
i += 1 | |
except (KeyboardInterrupt, SystemExit): | |
break | |
z.close() | |
if __name__ =='__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment