2013-04-24 101 views
-1

我正在嘗試使用Pelops clientCassandra database讀取數據。我成功地做到了。從Pelops客戶端讀取數據並基準讀取操作

現在我已經開始做benchmarking,這意味着從Cassandra數據庫中讀取多少時間。所以我在下面的代碼中添加了我的benchmarking code

現在我不確定是否在正確的位置添加了我的benchmarking code,以便使用Pelops client來測量Cassandra database的讀取延遲?

下面是我的代碼 -

public Map<String, String> getAttributes(final String rowKey, final Collection<String> attributeNames, final String columnFamily) { 

    final Map<String, String> attributes = new ConcurrentHashMap<String, String>(); 

    try { 
     final SlicePredicate myPredicate = Selector.newColumnsPredicate(attributeNames.toArray(new String[attributeNames.size()])); 

     final Selector selector = Pelops.createSelector(CassandraPelopsConnection.getInstance().getPoolName()); 

     // this is the right place to start the timer? 
     CassandraTimer timer = CassandraTimer.getInstance(); 

     final List<Column> columnList = selector.getColumnsFromRow(columnFamily, rowKey, myPredicate, ConsistencyLevel.ONE); 

     // And this is the right place to end the timer incase of Pelops client? 
     timer.getDuration(); 

     for (Column column : columnList) { 
      attributes.put(new String(column.getName()), new String(column.getValue())); 
     }  
    } catch (Exception e) { 

    } 

    return attributes; 
} 

任何人都可以看看,讓我知道我是否在做正確與否?

回答

2

是的,這是正確的,您希望定時器在查詢之前準確啓動,並在查詢後立即停止。

作爲一個方面說明,你沒有對計時器做任何事情,把它分配給一個變量,以便以後使用它。

+0

感謝您的幫助。我假設這行只有'selector.getColumnsFromRow(columnFamily,rowKey,myPredicate,ConsistencyLevel.ONE);'它會去並從Cassandra數據庫中獲取數據。所以如果我的假設是正確的,我已經把計時器放在正確的地方。是的,關於計時器,我已經有一個靜態地圖,在我以後使用的持續時間方法中。 – ferhan 2013-04-24 16:33:44