prepare:
create keyspace ycsb WITH REPLICATION = {'class' : 'SimpleStrategy', 'replication_factor': };
USE ycsb;
CREATE TABLE users (
firstname text,
lastname text,
age int,
email text,
city text,
PRIMARY KEY (lastname)
);
用bash开5个python进程来测试写入性能,注意:当集群数目增加,应当增加bash脚本的并发进程数!
test_cass.py
from cassandra.cluster import Cluster
from cassandra.query import BatchStatement from time import time cluster = Cluster(["10.178.204.225"])
#session = cluster.connect('my_keyspace')
session = cluster.connect('ycsb')
#session.execute("TRUNCATE my_keyspace.users;")
session.execute("TRUNCATE ycsb.users;") start = time()
data_cnt = 1000000
bulk_cnt = 100
for i in range(data_cnt/bulk_cnt):
insert_user = session.prepare("insert into users (lastname, age, city, email, firstname) values (?, ?, 'Austin', '[email protected]', 'Bob')")
batch = BatchStatement()
for j in range(bulk_cnt):
batch.add(insert_user, ("Jones"+str(i*bulk_cnt+j), j))
session.execute(batch) end = time()
interval = end-start
print "time:", interval, "through ops/per second:", data_cnt/interval result = session.execute("select * from users where lastname='Jones0'")
for x in result:
print x.age, x.firstname, x.lastname
#result = session.execute("select count(*) from users")
#for x in result:
# print x result = session.execute("select * from users where lastname='Jones%s'" % (data_cnt-1))
for x in result:
print x.age, x.firstname, x.lastname
bash run.sh
for((i=;i<;i++)) do
python test_cass.py &
done
wait
echo "done"