javacassandrapelops

Reading the data from Pelops client and benchmark the read operation


I am trying to read the data from Cassandra database using Pelops client. I am successfully able to do that.

Now I have started doing benchmarking, meaning how much time read takes from Cassandra database. So I have added my benchmarking code in below code.

Now I am not sure whether I have added my benchmarking code at correct place to measure the read latency of Cassandra database using Pelops client or not?

Below is my code-

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

Can anyone take a look and let me know whether I am doing right or not?


Solution

  • Yes that's correct, you want the timer to start exactly before the query, and stop immediately after your query.

    As a side note, you're not doing anything with the timer, assign it to a variable so you can use it later.