Clickhouse-客户端插入优化

Clickhouse-client insert optimization

我正在将大量 CSV 数据文件插入到已有大量数据的远程 Clickhouse 数据库中。我正在使用这样的简单脚本来完成它:

...
 for j in *.csv; do
      clickhouse-client --max_insert_threads=32 --receive_timeout=30000 --input_format_allow_errors_num=999999999 --host "..." --database "..." --port 9000 --user "..." --password "..." --query "INSERT INTO ... FORMAT CSV" < "$j"
  done
...

所以我的问题是:如何优化这些插入?我已经使用这些选项进行优化:

--max_insert_threads=32 --receive_timeout=30000

clickhouse-client 中是否还有更多选项我应该使用以获得更好的性能以及用于什么目的?一个文件可能有 300-500mb(有时更多)。根据 this article 使用并行进程无济于事,这就是我一次插入一个文件的原因。

max_insert_threads这里不适用,是CH服务器里面的insert select

According to this article using parallel processes won't help

应该有帮助(这取决于 CPU 和磁盘功率),试试看

# parallelism 6 (-P6)

find . -type f -name '*.csv' | xargs -P 6 -n 1 clickhouse-client --input_format_parallel_parsing=0 --receive_timeout=30000 --input_format_allow_errors_num=999999999 --host "..." --database "..." --port 9000 --user "..." --password "..." --query "INSERT INTO ... FORMAT CSV"

我特意设置了input_format_parallel_parsing=0,它在多个并行负载的情况下提高了总体性能。