Created
January 5, 2012 10:09
-
-
Save santisaez/1564556 to your computer and use it in GitHub Desktop.
SERVER_ERROR out of memory storing object with memcached 1.4.10
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/python | |
import memcache | |
import sys | |
import random | |
MEMCACHED_SERVER = sys.argv[1] | |
MEMCACHED_PORT = '11211' | |
MEMCACHED_KEY = 'testing.' + str(random.randint(1, pow(2,16))) + '.' | |
MEMCACHED_VALUE = 'a' * 1024 | |
MEMCACHED_MIN_EXPTIME = 60 | |
MEMCACHED_MAX_EXPTIME = 600 | |
MEMCACHED_DELETE_RATIO = 1000 | |
DEBUG_RATIO = 100000 | |
count = 0 | |
error_count = 0 | |
delete_count = 0 | |
# connect error = EADDRNOTAVAIL (/proc/sys/net/ipv4/ip_local_port_range) | |
mc = memcache.Client(['%s:%s' % (MEMCACHED_SERVER, MEMCACHED_PORT)], debug=0) | |
while 1: | |
try: | |
key = MEMCACHED_KEY + str(count) | |
# random expiration time | |
exptime = random.randint(MEMCACHED_MIN_EXPTIME, MEMCACHED_MAX_EXPTIME) | |
if count % DEBUG_RATIO == 0: | |
print 'DEBUG: key = %s, exptime = %s' % (key, exptime) | |
mc.set(key, MEMCACHED_VALUE, exptime) | |
stored = mc.get(key) | |
if stored != MEMCACHED_VALUE: | |
print 'ERROR! %d => sent = %s, stored = %s' % (count, MEMCACHED_VALUE, stored) | |
error_count = error_count + 1 | |
print key | |
sys.exit(-1) | |
# key delete with ratio | |
if count % MEMCACHED_DELETE_RATIO == 0: | |
#print 'DEBUG: deleting %s key' % key | |
mc.delete(key) | |
delete_count = delete_count + 1 | |
count = count + 1 | |
except KeyboardInterrupt: | |
mc.disconnect_all() | |
print '\ntotal keys = %d' % count | |
print 'total keys deleted = %d' % delete_count | |
print 'total errors found = %d' % error_count | |
sys.exit() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment