cassandra lookup by list of primary keys in java

后端 未结 1 376
一整个雨季
一整个雨季 2021-01-15 12:25

I am implementing a feature which requires looking up Cassandra by a list of primary keys.

Below is an example data where id is primary key

mytable
id          


        
相关标签:
1条回答
  • 2021-01-15 13:09

    If the id is the full primary key, then Cassandra supports this, although it's not recommended from performance point of view:

    • request is sent to coordinator node
    • coordinator node finds a replica for each of the id, and send individual request to them
    • wait for results from every node, collect them to result set & send back

    As result:

    • all your sub-queries need to wait for slowest of the replicas
    • you have an additional network hope from coordinator to replica
    • you put more pressure to the coordinator node as it need to keep results in memory

    If you do a lot of parallel, asynchronous requests for each of the id values from application, then you:

    • avoid an additional hop - if you're using prepared statements with token-aware load balancing, then query is sent directly to replicas
    • you may start to process results as you get them, not waiting for everything

    So sending parallel asynchronous requests could be faster than sending one request with IN...

    0 讨论(0)
提交回复
热议问题