easy-swoole / easyswoole

swoole,easyswoole,swoole framework
https://www.easyswoole.com/
Apache License 2.0
4.73k stars 512 forks source link

ElasticSearch协程客户端批量插入问题 #560

Open ArgoVesta opened 1 year ago

ArgoVesta commented 1 year ago

elasticsearch批量写入,这里只会插入前10W条,新的却写入不进?(假如我sql里面写50W条,也可以写入,后面的却写不进去)

XueSiLf commented 1 year ago

你好,我是XueSi,很抱歉,之前太忙没有及时处理,今天我复现下这个问题然后再尝试修复。

XueSiLf commented 1 year ago

你好,我这边测试导入 20w 条数据时是正常的,使用 ElasticSearch 官方PHP客户端 导入 50w 条数据时也报异常。异常如下:

{"error":{"root_cause":[{"type":"es_rejected_execution_exception","reason":"rejected execution of coordinating operation [coordinating_and_primary_bytes=0, replica_bytes=0, all_bytes=0, coordinating_operation_bytes=110388603, max_coordinating_and_primary_bytes=103887667]"}],"type":"es_rejected_execution_exception","reason":"rejected execution of coordinating operation [coordinating_and_primary_bytes=0, replica_bytes=0, all_bytes=0, coordinating_operation_bytes=110388603, max_coordinating_and_primary_bytes=103887667]"},"status":429}

根据异常提示应该是达到了内存上限,max_coordinating_and_primary_bytes是内存的10%,建议你进行分批导入。

XueSiLf commented 1 year ago

其实本质还是取决于你这10w条数据占用的大小,导入大量数据时非常吃内存的,特别是bulk这种操作,也会导致ElasticSearch服务端线程池占满,从而导致 ElasticSearch 拒绝响应。所以建议你分批导入,例如每次导入10w 或者 20w。 针对导入失败的情况你需要查看原因: 查看原因,统一导入成功和失败的代码

$errorNums = 0;
$sucNums = 0;
foreach ($r['items'] as $row) {
    if (!empty($row['create'])) {
        $create = $row['create'];
        if (isset($create['error'])) {
            var_dump($create['error']['reason']);
            $errorNums += 1;
        } else if (isset($create['result']) && $create['result'] == 'created') {
            $sucNums += 1;
        }
    }
}
XueSiLf commented 1 year ago

你好有问题的话再QQ联系我

ArgoVesta commented 1 year ago

好的,我试试