3

I'm new to Cassandra and I'm trying to figure out how I should store data in order to be able to perform fast reads in parallel. I have read that partitioning data can give performance issues? Is it possible to read data from Cassandra tables in the same partition in parallel?

CrapDeveloper
  • 156
  • 1
  • 3
  • 9

1 Answers1

5

DataStax's Oliver Michallat has a good blog post which discusses this:

Asynchronous queries with the Java Driver

In that article, he describes how to code in-parallel queries to solve the issues associated with multi-partition-key queries.

The example he uses, is instead of running a single query (from Java) for something like this:

SELECT * FROM users WHERE id IN (
    e6af74a8-4711-4609-a94f-2cbfab9695e5,
    281336f4-2a52-4535-847c-11a4d3682ec1);

A better way is to use an async "future" like this:

Future<List<ResultSet>> future = ResultSets.queryAllAsList(session,
    "SELECT * FROM users WHERE id = ?",
      UUID.fromString("e6af74a8-4711-4609-a94f-2cbfab9695e5"),
      UUID.fromString("281336f4-2a52-4535-847c-11a4d3682ec1")
);

for (ResultSet rs : future.get()) {
    ... // here is where you process the result set    
}

As for querying data from within the same partition, of course you can. I assume that you mean with differing clustering keys (otherwise there would be no point), and that should work in a similar way to what is listed above.

Aaron
  • 55,518
  • 11
  • 116
  • 132
  • Hi Aaron, thank you for your answer. Would it be possible to read from a single table in parallel where each thread would query the table with different partition keys? – CrapDeveloper Apr 25 '16 at 10:52
  • 1
    @CrapDeveloper Yes, of course. When you have a lot of data to read from one table, that's actually the best way to go about it. – Aaron Apr 25 '16 at 11:51
  • This would be the same case for a single node Cassandra system? – CrapDeveloper Apr 25 '16 at 12:18
  • 1
    @CrapDeveloper Obviously you'll get better performance with *more* nodes, but yes, I would still use that approach with a single node. – Aaron Apr 25 '16 at 13:13
  • Thanks for your help Aaron. I appreciate it! – CrapDeveloper Apr 25 '16 at 13:18