gpt4 book ai didi

java - Cassandra 对具有不同分区键的表的批量查询性能

转载 作者:行者123 更新时间:2023-12-01 17:58:15 25 4
gpt4 key购买 nike

我有一个测试用例,每秒从客户端收到 150k 个请求。

我的测试用例需要将UNLOGGED批处理插入到多个表并具有不同的分区键

BEGIN UNLOGGED  BATCH
update kspace.count_table set counter=counter+1 where source_id= 1 and name='source_name' and pname='Country' and ptype='text' and date='2017-03-20' and pvalue=textAsBlob('US')
update kspace.count_table set counter=counter+1 where source_id= 1 and name='source_name' and pname='City' and ptype='text' and date='2017-03-20' and pvalue=textAsBlob('Dallas')
update kspace.count_table set counter=counter+1 where source_id= 1 and name='source_name' and pname='State' and ptype='text' and date='2017-03-20' and pvalue=textAsBlob('Texas')
update kspace.count_table set counter=counter+1 where source_id= 1 and name='source_name' and pname='SSN' and ptype='text' and date='2017-03-20' and pvalue=decimalAsBlob(000000000);
update kspace.count_table set counter=counter+1 where source_id= 1 and name='source_name' and pname='Gender' and ptype='text' and date='2017-03-20' and pvalue=textAsBlob('Female')
APPLY BATCH

有比我目前遵循的方式更好的方法吗?

因为目前,我批量插入到可能存在于不同集群中的多个表,因为它们具有不同的分区键,并且据我所知,将批量查询插入到具有不同分区键的不同表需要额外的权衡。

最佳答案

首先,了解批处理的用例很重要。

Batches are often mistakenly used in an attempt to optimize performance.

批处理用于维护多个表之间的数据一致性。如果需要原子性,则使用记录的批处理。如果在您的情况下,这是一个计数器表,并且表之间的计数不需要保持一致,则不要使用批处理。如果集群没问题,Cassandra 将确保所有写入成功。

Unlogged batches require the coordinator to manage inserts, which can place a heavy load on the coordinator node. If other nodes own partition keys, the coordinator node needs to deal with a network hop, resulting in inefficient delivery. Use unlogged batches when making updates to the same partition key.

请关注以下文章:

https://docs.datastax.com/en/cql/3.1/cql/cql_using/useBatch.html

https://medium.com/@foundev/cassandra-batch-loading-without-the-batch-keyword-40f00e35e23e#.npmx2cnsq

关于java - Cassandra 对具有不同分区键的表的批量查询性能,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42929928/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com