Saturate (max out) Memory Utilization

To Max out memory use:

#!/usr/bin/python
 
# To eat 40GB of RAM and hold it for 5 seconds type:
#./memconsume.py 5 40
 
import time
import sys
 
seconds = int(sys.argv[1])
gb = int(sys.argv[2])
 
mem = gb * 1073741824;
cap = 1 * 1073741824;
calls = ( mem // cap );
print "consuming, using %s" % (mem);
 
memstr = []
for call in range( calls ):
    print " adding: %s" % (cap);
    memstr.append(' ' * cap);
 
print "waiting..."
 
time.sleep(seconds)
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s