簡體   English   中英

使用Thrift和CQL3進行Cassandra基准測試

[英]cassandra benchmarking using thrift and CQL3

我正在對cassandra thrift和CQL進行性能測試,我使用以下代碼在使用CQL和thrift的4列標准列系列中輸入1000條記錄。 但是與datastax矛盾的是,與使用CQL相比,節儉使我獲得了更高的吞吐量和更少的延遲。 如果我在某個地方出錯了,誰能幫助我?

公共無效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(String keyspace){System.out.print(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中,該驅動程序更可能被丟棄。

如果將execute()替換為executeAsync()並等待所有任務完成,我希望性能會提高(Guava的Futures.allAsList(...).get()是這樣做的便捷方法)。

目前尚不清楚是在本地還是分布式Cassandra安裝上運行它。 在分布式環境中,性能提升應該更高,尤其是在對Cluster初始化進行一些調整時。 但是,即使在本地Cassandra安裝上,也必須進行明顯的改進。

另外,我建議將循環中的記錄數增加到1M之類,並增加預熱周期。 您可能不是在Cassandra中進行基准測試,而是在Cassandra JVM中對JIT編譯器進行了基准測試:)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM