Java 从Pelops客户端读取数据并对读取操作进行基准测试
我正在尝试使用Java 从Pelops客户端读取数据并对读取操作进行基准测试,java,cassandra,pelops,Java,Cassandra,Pelops,我正在尝试使用Pelops客户端从Cassandra数据库读取数据。我成功地做到了这一点 现在我开始做基准测试,这意味着从Cassandra数据库读取数据需要多少时间。因此,我在下面的代码中添加了我的基准测试代码 现在我不确定是否在正确的位置添加了基准测试代码,以使用Pelops客户端测量Cassandra数据库的读取延迟 下面是我的代码- public Map<String, String> getAttributes(final String rowKey, final Coll
Pelops客户端
从Cassandra数据库
读取数据。我成功地做到了这一点
现在我开始做基准测试
,这意味着从Cassandra数据库读取数据需要多少时间。因此,我在下面的代码中添加了我的基准测试代码
现在我不确定是否在正确的位置添加了基准测试代码
,以使用Pelops客户端测量Cassandra数据库
的读取延迟
下面是我的代码-
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;
}
publicmap getAttributes(最终字符串行键、最终集合属性名、最终字符串列族){
最终映射属性=新的ConcurrentHashMap();
试一试{
final SlicePredicate myPredicate=Selector.newColumnsPredicate(attributeNames.toArray(新字符串[attributeNames.size()]);
最终选择器=Pelops.createSelector(CassandraPelopsConnection.getInstance().getPoolName());
//这是启动计时器的正确位置?
CassandraTimer计时器=CassandraTimer.getInstance();
final List columnList=selector.getColumnsFromRow(columnFamily,rowKey,myPredicate,ConsistenceLevel.ONE);
//在Pelops客户端的情况下,这是结束计时器的正确位置?
timer.getDuration();
for(列:列列表){
put(新字符串(column.getName()),新字符串(column.getValue());
}
}捕获(例外e){
}
返回属性;
}
有人能看一看,让我知道我做的是否正确吗?是的,没错,您希望计时器在查询之前启动,在查询之后立即停止
作为补充说明,您没有对计时器执行任何操作,请将其分配给一个变量,以便以后使用。谢谢您的帮助。我仅通过这一行假设selector.getColumnsFromRow(columnFamily,rowKey,myPredicate,ConsistencyLevel.ONE)代码>它将从Cassandra数据库获取数据。因此,如果我的假设是正确的,我把计时器放在了正确的位置。是的,关于计时器,我已经在get duration方法中有了一个静态映射,我稍后将使用这个方法。