2013-04-24 55 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

相关问题