[英]Cassandra read performance with Astyanax client
我们Cassandra database in production environment
中使用Cassandra database in production environment
。 我们有single cross colo cluster of 24 nodes
的single cross colo cluster of 24 nodes
这意味着12 nodes in PHX
12 nodes in SLC colo
。 replication factor of 4
,这意味着2 copies will be there in each datacenter
。
以下是我们的Production DBA's
创建keyspace
和column families
Production DBA's
。
使用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;
我们正在运行Cassandra 1.2.2
,它具有org.apache.cassandra.dht.Murmur3Partitioner
, KeyCaching
启用了KeyCaching
, SizeTieredCompactionStrategy
和Virtual Nodes
。 Cassandra节点部署在HDD instead of
SSD上。
我正在使用Astyanax client
以consistency level as ONE
从Cassandra database
读取数据。 我使用Astyanax client
在生产集群中插入了50 Millions records
(跨24个节点,总共约285GB数据),在压缩完成后,我开始read against the Cassandra production database
进行read against the Cassandra production database
。
以下是我使用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());
}
大多数时候,我在8/9/10 ms
左右获得95th percentile read performance
。
我想看看有什么办法可以使Cassandra database
获得更好的read performance
。 我的印象是,在1 or 2 ms
后我将获得95%的百分位数,但是在对生产集群进行一些测试之后,我所有的假设都错了。 从我运行客户端程序的地方到Cassandra生产节点的Ping时间0.3ms average
为0.3ms average
。
以下是我得到的结果。
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
任何人都可以阐明我可以尝试其他哪些方法以达到良好的读取延迟性能吗? 我知道在同样的情况下可能会有相似的人在生产中使用Cassandra。 任何帮助将不胜感激。
谢谢您的帮助。
我会尝试以下方法:
将ConnectionPoolType设置为TOKEN_AWARE而不是ROUND_ROBIN。
另外,我将使用一些Astyanax延迟感知连接池功能。 例如:
.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))
)
延迟设置是通过ScoreStrategy的构造函数提供的。 例如SmaLatencyScoreStrategyImpl 。
我也在解决这个问题,因此,如果我学到其他内容,我会在这里发帖。
请参阅: 延迟和令牌感知配置
您可以做几件事来优化读取。 注意:我没有尝试过这些,但是它们在我要调查的事情清单上(所以我认为我愿意分享)。
快取
启用密钥缓存和行缓存。
键缓存
bin/nodetool --host 127.0.0.1 --port 8080 setcachecapacity MyKeyspace MyColumnFam 200001 0
行缓存
bin/nodetool --host 127.0.0.1 --port 8080 setcachecapacity MyKeyspace MyColumnFam 0 200005
然后,在您的应用程序场景中,在该节点上敲击一段时间后,检查点击率:
bin/nodetool --host 127.0.0.1 --port 8080 cfstats
一致性
考虑“读取一致性”为“一”。请参见“数据一致性” (这是DataStax文档,但仍然相关)
考虑降低读取修复的机会。
update column family MyColumnFam with read_repair_chance=.5
降低read_repair_chance之后,请考虑调整复制因子以帮助提高读取性能(但这会杀死写入,因为我们将写入更多节点)。
create keyspace cache with replication_factor=XX;
磁碟
不知道这里是否有任何事情要做,但我认为应该包括在内。 确保最佳文件系统(例如ext4)。 如果您有很高的复制因子,我们可以围绕它优化磁盘(知道我们将从Cassandra获得持久性)。 即哪种RAID级别最适合我们的设置。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.