cassandra基准测试使用节俭和CQL3



我正在进行cassandra节俭与CQL的性能测试,我使用以下代码在标准列族中输入了1000条记录,其中4列使用CQL和节俭。但与数据税相矛盾的是,与使用CQL相比,使用节俭可以获得更高的吞吐量和更少的延迟。如果我哪里出了问题,有人能帮我吗?

public void insertUsingCql(){

    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();
    }
}

public void insertUsingThrift(字符串密钥空间){系统输出打印(keyspace);

    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);
    }
}

不,你没有做错什么,因为这个低容量的节俭驱动程序平均看起来会更快,但它在第95和第99百分位会有更高的峰值,而且随着负载的增加,它会变得最差。尝试使用性能测试指标http://metrics.codahale.com/并查看延迟分布,而不仅仅是平均响应时间。还要注意cassandra缓存,这样就不会用冷缓存运行一个测试,而用热缓存运行下一个测试。根据我的经验,使用本机驱动程序是因为它得到了广泛的支持,并且在更可能放弃节俭驱动程序的地方使用,特别是在C*2.0中。

如果用executeAsync()替换execute()并等待所有任务完成,我希望性能会提高(Guava的Futures.allAsList(...).get()是一种方便的方法)。

目前还不清楚您是在本地还是分布式Cassandra安装上运行它。在分布式环境中,性能增益应该更高,尤其是当您在Cluster初始化时进行一些调优时。但即使在当地的Cassandra安装上,也必须有明显的改进。

此外,我建议将循环中的记录数增加到1M左右,并添加预热周期。可能您的基准测试不是Cassandra,而是Cassandra JVM中的JIT编译器:)

最新更新