Skip to content

How to improve insert CSV data efficiency? #538

Closed

Description

@sangli00
[root@localhost ~]# time clickhouse-client --query="INSERT INTO atomic.LINEITEM FORMAT TabSeparated" <   /home/pg/clickhouse/lineitem.csv

real	17m50.733s
user	20m4.970s
sys	0m5.692s
[root@localhost ~]# ls -alh /home/pg/clickhouse/lineitem.csv
-rw-r--r--. 1 pg postgres 17G Feb 17 16:01 /home/pg/clickhouse/lineitem.csv

Is very slowly ....

Activity

  1. ztlpn commented on Mar 1, 2017

    @ztlpn
    Contributor

    You can try splitting the file into several smaller files and inserting them in parallel. This should speedup insertion somewhat.

  2. vavrusa commented on Mar 2, 2017

    @vavrusa
    Contributor

    You can break it by parts and insert in parallel.

  3. sangli00 commented on Mar 3, 2017

    @sangli00
    Author

    @ztlpn
    If i insert 1TB data to Clickhouse,How to do it?

  4. ztlpn commented on Mar 3, 2017

    @ztlpn
    Contributor

    If i insert 1TB data to Clickhouse,How to do it?

    Inserting 1TB shouldn't be a problem. But in your case performance is indeed suspiciously low: ~16MB/s (should be ~100MB/s), and as the output of time suggests, the client is the bottleneck. Could you provide some info on the specs of the machine you are running this on?

  5. sangli00 commented on Mar 4, 2017

    @sangli00
    Author

    @ztlpn If i used Native interface and parallel write to ClicHouse is OK?

  6. pondix commented on Nov 29, 2017

    @pondix

    I seem to be having a similar issue, here are the details:

    - APPLICATION LOG (Python subprocess loading CSV file via stdin to clickhouse-client):
    
    ERROR:root:2017-11-30 04:38:01: Failed loading file /data/mysql-files/adscore.history_details-20171130-043301-3210999986.csv into Clickhouse table test.historyplay - Duration: 300.076040983
    CRITICAL:root:2017-11-30 04:38:01: Failed to load file history_details-20171130-043301-3210999986.csv into Clickhouse table test.history
    
    
    - Clickhouse client exception
     - Code: 209. DB::NetException: Timeout exceeded while reading from socket (127.0.0.1:9000): while receiving packet from localhost:9000, 127.0.0.1
    

    Details of the CSV being loaded:

    root@super-server:~/popads-mysql-2-clickhouse# cat /data/mysql-files/adscore.history_details-20171130-043301-3210999986.csv |wc -l
    111111
    root@super-server:~/popads-mysql-2-clickhouse# head -n1  /data/mysql-files/adscore.history_details-20171130-043301-3210999986.csv
    3209999995,"2015-11-14",1447430400,424,5803,"33779",4,173
    

    The server cluster has 128GB RAM and 40x cores (3x shards with 3x node replicas).

    These files were taking between 2 - 8 seconds to load with 10,000,000 rows. After inserting 923,765,380 clickhouse-client is timing out after 300 seconds - have I hit some limit?

  7. kmatt commented on Nov 16, 2018

    @kmatt

    I started seeing similar issues when changing to a set of partition columns that created several hundred to a few thousand partitions instead of one per day - partitioning on the primary key to reduce query times. One possible solution is to use a lower cardinality partition scheme.

  8. alexey-milovidov commented on Jan 26, 2019

    @alexey-milovidov
    Member

    I cannot reproduce timeouts while loading huge CSV through clickhouse-client. Tested with 600 GB CSV file.

    For lineorder table from "star schema benchmark", ClickHouse can parse about 1.5 million rows per second (170 MB/sec) on single decent CPU core - that's definitely not slow.

  9. pondix commented on Jan 27, 2019

    @pondix

    @alexey-milovidov - apologies, how very rude of me to not follow up on my previous comment after resolving the issue 😄 For the sake of completeness, I'll write it down here so perhaps it can help someone else in future.

    The problem I was facing was actually due to the files having RANDOM dates... this was because I was generating test data to simulate "real world" load but the oversight was that I was using random dates stretching across hundreds of years all within each file being loaded. I would start with an empty database but in a very short timeframe I had generated thousands of "date" partitions... each row in the CSV had to be put into a different partition and this was killing performance (as a side note we have 3x replicas for each shard located in different continents which is also "not recommended" in terms of performance however it is a business requirement for us).

    After using more "real world" test data and later production data ClickHouse started behaving as expected 😂and I'm also glad to say we've had ClickHouse loading CSVs in production for several months and reading the results via MySQL Protocol through ProxySQL without any hiccups!

  10. alexey-milovidov commented on Jan 27, 2019

    @alexey-milovidov
    Member

    Thank you for the follow up!

    We are aware that it's very easy to create too many partitions. We are thinking about how we can avoid this issue from the usability perspective. (For example, the user can by mistake create partitioning schema with one partition per second of input data - then the filesystem quickly becomes totally unusable.)

  11. added a commit that references this issue on Jan 7, 2025
  12. added a commit that references this issue on Nov 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    question

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions