Skip to content

Instantly share code, notes, and snippets.

@sing1ee
Created July 11, 2012 01:40
Show Gist options
  • Save sing1ee/3087394 to your computer and use it in GitHub Desktop.
Save sing1ee/3087394 to your computer and use it in GitHub Desktop.
practise for pycassa and multiprocessing
# !/usr/bin/python
# -*- encoding: utf-8 -*-
import pycassa
from multiprocessing import Pool
cassa = pycassa.ConnectionPool('test', server_list=['10.1.1.41'])
cf = pycassa.ColumnFamily(cassa, 'data')
insert_count = 1000000
del_count = 10000
insert_value = 'i'
update_value = 'u'
for i in range(1023):
insert_value += 'i'
update_value += 'u'
def insert(arr=()):
cf.insert(arr[0], {'c1' : arr[1]})
def delete(key):
cf.remove(key)
def process_insert(pool, start, count):
pool.map(insert, [(str(i), insert_value) for i in range(start, start + count)])
def process_del(pool):
pool.map(delete, [str(i) for i in range(del_count)])
def process_update(pool):
pool.map(insert, [(str(i), update_value) for i in range(100000)])
def test(key, value):
cf.insert(key, {'c1' : value})
print cf.get(key)
if __name__ == '__main__':
# pool = Pool(8)
# for i in range(10):
# process_insert(pool, 0, 1000000)
# process_del(pool)
# process_insert(pool, 1000000, 100000)
# process_update(pool)
# pool.close()
# pool.join()
for i in range(1100000):
try:
value = cf.get(str(i))['c1']
l = len(value)
if l != 1024:
print str(i), 'wrong'
break
print str(i),l, value[0]
except Exception, e:
print str(i),'del'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment