简体   繁体   English

Cassandra使用Astyanax客户端读取性能

[英]Cassandra read performance with Astyanax client

We are using Cassandra database in production environment . 我们Cassandra database in production environment中使用Cassandra database in production environment We have a single cross colo cluster of 24 nodes meaning 12 nodes in PHX and 12 nodes in SLC colo . 我们有single cross colo cluster of 24 nodessingle cross colo cluster of 24 nodes这意味着12 nodes in PHX 12 nodes in SLC colo We have a replication factor of 4 which means 2 copies will be there in each datacenter . replication factor of 4 ,这意味着2 copies will be there in each datacenter

Below is the way by which keyspace and column families have been created by our Production DBA's . 以下是我们的Production DBA's创建keyspacecolumn families Production DBA's

create keyspace profile with placement_strategy = 'org.apache.cassandra.locator.NetworkTopologyStrategy' and strategy_options = {slc:2,phx:2}; 使用placement_strategy ='org.apache.cassandra.locator.NetworkTopologyStrategy'和strategy_options = {slc:2,phx:2}创建密钥空间配置文件;

 create column family PROFILE_USER with key_validation_class = 'UTF8Type' and comparator = 'UTF8Type' and default_validation_class = 'UTF8Type' and gc_grace = 86400; 

We are running Cassandra 1.2.2 and it has org.apache.cassandra.dht.Murmur3Partitioner , with KeyCaching , SizeTieredCompactionStrategy and Virtual Nodes enabled as well. 我们正在运行Cassandra 1.2.2 ,它具有org.apache.cassandra.dht.Murmur3PartitionerKeyCaching启用了KeyCachingSizeTieredCompactionStrategyVirtual Nodes Cassandra nodes is deployed on HDD instead of SSD's`. Cassandra节点部署在HDD instead of SSD上。

I am using Astyanax client to read the data from Cassandra database using consistency level as ONE . 我正在使用Astyanax clientconsistency level as ONECassandra database读取数据。 I inserted 50 Millions records (total around 285GB of data across 24 nodes) in the production cluster using the Astyanax client and after the compaction is finished, I started doing read against the Cassandra production database . 我使用Astyanax client在生产集群中插入了50 Millions records (跨24个节点,总共约285GB数据),在压缩完成后,我开始read against the Cassandra production database进行read against the Cassandra production database

Below is the code by which I am creating connection configuration using Astyanax client - 以下是我使用Astyanax client创建连接配置的代码-

/**
 * Creating Cassandra connection using Astyanax client
 *
 */
private CassandraAstyanaxConnection() {

    context = new AstyanaxContext.Builder()
    .forCluster(ModelConstants.CLUSTER)
    .forKeyspace(ModelConstants.KEYSPACE)
    .withConnectionPoolConfiguration(new ConnectionPoolConfigurationImpl("MyConnectionPool")
        .setPort(9160)
        .setMaxConnsPerHost(100)
        .setSeeds("cdb03.vip.phx.host.com:9160,cdb04.vip.phx.host.com:9160")
        .setLocalDatacenter("phx") //filtering out the nodes basis on data center
    )
    .withAstyanaxConfiguration(new AstyanaxConfigurationImpl()
        .setCqlVersion("3.0.0")
        .setTargetCassandraVersion("1.2")
        .setConnectionPoolType(ConnectionPoolType.ROUND_ROBIN)
        .setDiscoveryType(NodeDiscoveryType.RING_DESCRIBE))
    .withConnectionPoolMonitor(new CountingConnectionPoolMonitor())
    .buildKeyspace(ThriftFamilyFactory.getInstance());

    context.start();
    keyspace = context.getEntity();

    emp_cf = ColumnFamily.newColumnFamily(
        ModelConstants.COLUMN_FAMILY, 
        StringSerializer.get(), 
        StringSerializer.get());
}

Most of the time I am getting 95th percentile read performance around 8/9/10 ms . 大多数时候,我在8/9/10 ms左右获得95th percentile read performance

I am trying to see is there any way I can get much better read performance with Cassandra database . 我想看看有什么办法可以使Cassandra database获得更好的read performance I was in the impression that I will be getting 95th percentile as 1 or 2 ms but after doing some tests on the production cluster all my hypothesis went wrong. 我的印象是,在1 or 2 ms后我将获得95%的百分位数,但是在对生产集群进行一些测试之后,我所有的假设都错了。 Ping time to Cassandra production nodes from where I am running my client program is 0.3ms average . 从我运行客户端程序的地方到Cassandra生产节点的Ping时间0.3ms average0.3ms average

Below is the result I am getting. 以下是我得到的结果。

Read Latency(95th Percentile)      Number of Threads    Duration the program was running(in minutes)    Throughput(requests/seconds)    Total number of id's requested    Total number of columns requested
    8 milliseconds                         10                      30                                               1584                              2851481                        52764072

Can anyone shed some light on what other things I can try it out to achieve good read latency performance? 任何人都可以阐明我可以尝试其他哪些方法以达到良好的读取延迟性能吗? I know there might be similar people in my same situation as well who are using Cassandra in production. 我知道在同样的情况下可能会有相似的人在生产中使用Cassandra。 Any help will be appreciated. 任何帮助将不胜感激。

Thanks for the help. 谢谢您的帮助。

I'd try the following: 我会尝试以下方法:

Astyanax 腹膜炎

Set the ConnectionPoolType to TOKEN_AWARE instead of ROUND_ROBIN. 将ConnectionPoolType设置为TOKEN_AWARE而不是ROUND_ROBIN。

Additionally, I'd use some of the Astyanax latency aware connection pool features. 另外,我将使用一些Astyanax延迟感知连接池功能。 For example: 例如:

.withConnectionPoolConfiguration(new ConnectionPoolConfigurationImpl("MyConnectionPool")
        .setPort(9160)
        .setMaxConnsPerHost(100)
        .setSeeds("cdb03.vip.phx.host.com:9160,cdb04.vip.phx.host.com:9160")
        .setLocalDatacenter("phx") //filtering out the nodes basis on data center
        .setLatencyScoreStrategy(new SmaLatencyScoreStrategyImpl(10000,10000,100,0.50))
    )

The latency setting are provided via the constructor of the ScoreStrategy. 延迟设置是通过ScoreStrategy的构造函数提供的。 eg SmaLatencyScoreStrategyImpl . 例如SmaLatencyScoreStrategyImpl

I am in the process of figuring this out as well, so I'll post back here if I learn anything additional. 我也在解决这个问题,因此,如果我学到其他内容,我会在这里发帖。

See: Latency and Token Aware configuration 请参阅: 延迟和令牌感知配置

Cassandra 卡桑德拉

You could do a couple of things to optimize reads. 您可以做几件事来优化读取。 Note: I have not tried these, but they are on my list of things to investigate (so I figured I'd share). 注意:我没有尝试过这些,但是它们在我要调查的事情清单上(所以我认为我愿意分享)。

Cache 快取

Enable the Key cache and Row cache. 启用密钥缓存和行缓存。

KeyCache 键缓存

bin/nodetool --host 127.0.0.1 --port 8080 setcachecapacity MyKeyspace MyColumnFam 200001 0

RowCache 行缓存

bin/nodetool --host 127.0.0.1 --port 8080 setcachecapacity MyKeyspace MyColumnFam 0 200005

Then check the hit rates after banging on that node for a while with your app scenarios: 然后,在您的应用程序场景中,在该节点上敲击一段时间后,检查点击率:

bin/nodetool --host 127.0.0.1  --port 8080 cfstats

Consistency 一致性

Consider Read Consistency to ONE See this on Data Consistency (this is DataStax docs but still relevant) 考虑“读取一致性”为“一”。请参见“数据一致性” (这是DataStax文档,但仍然相关)

Consider lowering the read repair chance. 考虑降低读取修复的机会。

update column family MyColumnFam with read_repair_chance=.5

After lowering the read_repair_chance consider tweaking the replication factor to help with read performance (but this will kill writes as we'll be writing to more nodes). 降低read_repair_chance之后,请考虑调整复制因子以帮助提高读取性能(但这会杀死写入,因为我们将写入更多节点)。

create keyspace cache with replication_factor=XX;

Disk 磁碟

Not sure if there is anything to be done here but thought I should include it. 不知道这里是否有任何事情要做,但我认为应该包括在内。 Ensure optimal file system (eg ext4). 确保最佳文件系统(例如ext4)。 If you have a high replication factor we could optimize the disk around that (knowing that we'll get our durability from Cassandra). 如果您有很高的复制因子,我们可以围绕它优化磁盘(知道我们将从Cassandra获得持久性)。 ie what RAID level is best for our setup. 即哪种RAID级别最适合我们的设置。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM