行动是治愈恐惧的良药,而犹豫、拖延将不断滋养恐惧。

indices.memory.translog_buffer_size translog大小配置好像不生效

Elasticsearch | 作者 code4j | 发布于2018年03月22日 | 阅读数:2984

日志索引按小时创建新的索引,配置信息如下:
"settings": {
"index": {
"xxx": {
"size": "10mb"
},
"number_of_replicas": "0",
"translog": {
"flush_threshold_ops": "10000000",
"flush_threshold_size": "5120m",
"flush_threshold_period": "30m",
"sync_interval": "30s",
"durability": "async"
},
"search": {
"slowlog": {
"threshold": {
"fetch": {
"warn": "1s"
},
"query": {
"warn": "3s"
}
}
}
},
"merge": {
"policy": {
"merge_factor": "15",
"max_merged_segment": "1g",
"segments_per_tier": "20"
}
},
"indexing": {
"slowlog": {
"threshold": {
"index": {
"warn": "500ms"
}
}
}
},
"indices": {
"store": {
"throttle": {
"max_bytes_per_sec": "100mb"
}
},
"memory": {
"index_buffer_size": "15%",
"max_shard_translog_buffer_size": "128mb",
"translog_buffer_size": "3%"
}
},
"number_of_shards": "8",
"refresh_interval": "-1"
}
}
但是这个配置好像并没有生效:translog_buffer_size
 
因为集群日志中隔三十秒会打印一个日志,内容是这样的:
recalculating shard indexing buffer, total is [1.5gb] with [7] active shards, each shard set to indexing=[222.3mb], translog=[64kb]
 
translog的阈值为64KB?这个是默认值,并不是我修改的。
 
看了下源码:

ShardsIndicesStatusChecker类是每隔半个小时做一次检查,然后会校验translog大小,有这么一段:
ByteSizeValue shardIndexingBufferSize = new ByteSizeValue(indexingBuffer.bytes() / activeShardCount);
if (shardIndexingBufferSize.bytes() < minShardIndexBufferSize.bytes()) {
shardIndexingBufferSize = minShardIndexBufferSize;
}
if (shardIndexingBufferSize.bytes() > maxShardIndexBufferSize.bytes()) {
shardIndexingBufferSize = maxShardIndexBufferSize;
}

ByteSizeValue shardTranslogBufferSize = new ByteSizeValue(translogBuffer.bytes() / activeShardCount);
if (shardTranslogBufferSize.bytes() < minShardTranslogBufferSize.bytes()) {
shardTranslogBufferSize = minShardTranslogBufferSize;
}
if (shardTranslogBufferSize.bytes() > maxShardTranslogBufferSize.bytes()) {
shardTranslogBufferSize = maxShardTranslogBufferSize;
}


translog 默认是按百分比分配的,我配置了堆内存的3%,堆16G,也就是说应该是48mb左右,分成8个shard差不多60M一个,但是从上面的日志看,还是64KB。
 
实际现象也确实证明translog刷新大小阈值不是我配置的大小,translog每秒都在,但是我更新的速度并没有6M这么高。正常情况应该是内存中达到6m后再fsync translog到磁盘上。
 
不知道这个配置怎么做才能生效呢?
 
已邀请:

kennywu76 - Wood

赞同来自:

 64k是默认的buffered translog的配置,不知道translog_buffer_size这个配置你是从哪里看来得,我从来不知道有这个配置参数,官网查了下也没看到。 但是根据经验,trasnlog的buffer是不用调整的,因为即使不buffer,直接写磁盘文件,数据也不是立即持久化,Linux os层面还有文件系统的cache。 特别是你已经配置了translog的持久化方式为async和30秒的间隔,我可以确定translog的配置不会引起索引速率的下降。

要回复问题请先登录注册