elasticsearch - 为什么频繁写入后elasticsearch索引性能下降
问题描述
当我启动 nodejs 脚本时,它会删除旧索引(如果存在)并根据配置文件创建新索引,然后创建 Websocket-server 并开始监听传入连接。
initES() {
this.elasticsearchClient = new elasticsearch.Client({
host: `${Config.elasticSearchHost}:${Config.elasticSearchPort}`,
log: 'trace'
});
let deletePromise = this.elasticsearchClient.indices.delete({index: `${Config.elasticSearchIndex}`});
deletePromise.then(() => {
console.log(`Index ${Config.elasticSearchIndex} deleted`);
}, function(e) {
console.log(e.toJSON())
}).then(() => {
let createPromise = this.elasticsearchClient.indices.create({
index: `${Config.elasticSearchIndex}`,
body: {
settings: {
index: {
number_of_shards: 1,
number_of_replicas: 0
},
analysis: {
analyzer: {
whitespace_analyzer: {
tokenizer: 'whitespace',
filter: ['lowercase']
}
}
}
}
}
});
createPromise.then(() => {
console.log(`Index ${Config.elasticSearchIndex} created`);
}, (e) => {
console.log(e.toJSON());
})
});
}
脚本仅在启动时(通过 cron)启动一次,它是由我编写的,并使用标准 ES 库( https://www.elastic.co/guide/en/elasticsearch/client/javascript-api /current/api-reference.html )。
在前面,用户选择计算订单(~700 个项目,他们由系统自动计算,使用 gearman 和 phantomjs)
起初(前 8 小时或第一次测试)一切正常,ES 响应良好,websocket 客户端频繁更新数据,数据在 ES 索引中更新。
如果用户取消进程,或者进程完成并且用户决定重新计算(所有数据都在放任何东西之前被删除),ES 中的 IO 进程会变慢。
依此类推,一段时间后,索引填充到 ~340.. ~350 个项目,而不是 700 个。在某些情况下,ES 停止响应。
ES 的拖尾日志文件向我展示了很多行
Entering safepoint region: GenCollectForAllocation
[2019-05-21T13:46:45.611+0000][9630][gc,start ] GC(271) Pause Young (Allocation Failure)
[2019-05-21T13:46:45.611+0000][9630][gc,task ] GC(271) Using 8 workers of 8 for evacuation
[2019-05-21T13:46:45.616+0000][9630][gc,age ] GC(271) Desired survivor size 17891328 bytes, new threshold 6 (max threshold 6)
[2019-05-21T13:46:45.617+0000][9630][gc,age ] GC(271) Age table with threshold 6 (max threshold 6)
[2019-05-21T13:46:45.617+0000][9630][gc,age ] GC(271) - age 1: 987344 bytes, 987344 total
[2019-05-21T13:46:45.617+0000][9630][gc,age ] GC(271) - age 2: 5440 bytes, 992784 total
[2019-05-21T13:46:45.617+0000][9630][gc,age ] GC(271) - age 3: 172640 bytes, 1165424 total
[2019-05-21T13:46:45.617+0000][9630][gc,age ] GC(271) - age 4: 535104 bytes, 1700528 total
[2019-05-21T13:46:45.617+0000][9630][gc,age ] GC(271) - age 5: 333224 bytes, 2033752 total
[2019-05-21T13:46:45.617+0000][9630][gc,age ] GC(271) - age 6: 128 bytes, 2033880 total
[2019-05-21T13:46:45.617+0000][9630][gc,heap ] GC(271) ParNew: 282158K->2653K(314560K)
[2019-05-21T13:46:45.617+0000][9630][gc,heap ] GC(271) CMS: 88354K->88355K(699072K)
[2019-05-21T13:46:45.617+0000][9630][gc,metaspace ] GC(271) Metaspace: 85648K->85648K(1128448K)
[2019-05-21T13:46:45.617+0000][9630][gc ] GC(271) Pause Young (Allocation Failure) 361M->88M(989M) 5.387ms
[2019-05-21T13:46:45.617+0000][9630][gc,cpu ] GC(271) User=0.01s Sys=0.00s Real=0.00s
[2019-05-21T13:46:45.617+0000][9630][safepoint ] Leaving safepoint region
[2019-05-21T13:46:45.617+0000][9630][safepoint ] Total time for which application threads were stopped: 0.0057277 seconds, Stopping threads took: 0.0000429 seconds
[2019-05-21T13:46:46.617+0000][9630][safepoint ] Application time: 1.0004453 seconds
[2019-05-21T13:46:46.617+0000][9630][safepoint ] Entering safepoint region: Cleanup
[2019-05-21T13:46:46.617+0000][9630][safepoint ] Leaving safepoint region
但准确地说,我没有看到任何关键(内存故障分配除外)。即使一切顺利,这些行也会出现在日志中。
如果我重新启动我的脚本(删除旧的并创建新的索引),ES 会快速更新这些项目,因为它只是第一次这样做
所以我的问题是:
如果我,为什么 ES 会失去它的性能
insert/update/read/delete data ... insert/update/read/delete data ...
如果我,它的工作正常
insert/update/read restart script insert/update/read/
吗?
解决方案
与 Elasticsearch 无关。
没有关闭 websocket 连接是我的错,这导致服务器速度变慢,失去了资源。
抱歉各位耽误了你们的时间
推荐阅读
- kubernetes - 通过“port”而不是“nodePort”访问的 LoadBalancer 服务
- c++ - 使用 assemply 文件作为操作函数的 4x4 键盘计算器程序。Mbed 使用 nucleo f401re 微控制器
- java - Java Hadoop MapReduce 按不同字段分组
- python - 并非所有行都是从我的 CSV 文件中打印的
- c - 如何在c程序中的数组中插入多个元素?
- python - 如何将计算列从初始数据帧组合到新数据帧
- julia - Julia中的漂亮物体打印机
- multi-tenant - 安装 Kiwi TCMS 的多租户支持后无法再登录
- java - 如何更改 courgette JVM 报告的时间戳?
- linux - Linux 内核 - 页面缓存、结构地址空间和内存 cgroup 之间的关系是什么?