我正在对 cassandra thrift 与 CQL 进行性能测试,我使用以下代码在标准列族中输入 1000 条记录,其中 4 列使用 CQL 和 thrift。但是与datastax相反,我使用thrift比使用CQL获得更高的吞吐量和更少的延迟。如果我在某个地方出错了,谁能帮助我?
公共无效插入使用Cql(){
try {
long start = System.currentTimeMillis();
System.out.println("Inserting using cql started at: " + System.currentTimeMillis());
for (int i = 0; i < 10000; i++) {
session.execute(boundStatement.bind(Integer.toString(i), Integer.toString(i), Integer.toString(i), Integer.toString(i)));
}
System.out.println("Inserting using cql ended at: " + System.currentTimeMillis());
long end = System.currentTimeMillis();
long diff = end - start;
System.out.println("Time taken is= " + diff);
} catch (Exception e) {
e.printStackTrace();
}
}
公共无效插入使用Thrift(字符串键空间){ System.out.print(键空间);
try {
Column col;
ColumnOrSuperColumn column;
client.set_keyspace(keyspace);
long start = System.currentTimeMillis();
System.out.println("Inserting using thrift started at: " + System.currentTimeMillis());
for (int j = 0; j < 1000; j++) {
for (int i = 0; i < 4; i++) {
col = new Column();
col.setName(ByteBuffer.wrap(Integer.toString(i).getBytes()));
col.setValue(ByteBuffer.wrap(Integer.toString(i).getBytes()));
col.setTimestamp(System.currentTimeMillis());
column = new ColumnOrSuperColumn();
column.setColumn(col);
mutations.add(new Mutation().setColumn_or_supercolumn(column));
}
mutationMap.put("data", mutations);
record.put(ByteBuffer.wrap(Integer.toString(j).getBytes()), mutationMap);
client.batch_mutate(record, ConsistencyLevel.ONE);
mutations.clear();
mutationMap.clear();
record.clear();
}
System.out.println("Inserting using thrift ended at: " + System.currentTimeMillis());
long end = System.currentTimeMillis();
long diff = end - start;
System.out.println("Time taken is= " + diff);
} catch (InvalidRequestException ex) {
Logger.getLogger(PerformaceTest.class.getName()).log(Level.SEVERE, null, ex);
} catch (UnavailableException ex) {
Logger.getLogger(PerformaceTest.class.getName()).log(Level.SEVERE, null, ex);
} catch (TimedOutException ex) {
Logger.getLogger(PerformaceTest.class.getName()).log(Level.SEVERE, null, ex);
} catch (TException ex) {
Logger.getLogger(PerformaceTest.class.getName()).log(Level.SEVERE, null, ex);
}
}