Giter Site home page Giter Site logo

Comments (16)

vaintroub avatar vaintroub commented on June 3, 2024

Do not do many inserts in individual statements. wrap them in a transactions of reasonable size (e.g BEGIN 1000 statements COMMIT).

from mariadb-connector-nodejs.

markddrake avatar markddrake commented on June 3, 2024

I'll give it a try ? Is there any concept of a batch / bulk insert or prepared statement ?

Is 200/s in the ball park for single inserts

from mariadb-connector-nodejs.

markddrake avatar markddrake commented on June 3, 2024

That gets me to about 1250 rows per second..

from mariadb-connector-nodejs.

rusher avatar rusher commented on June 3, 2024

btw, this is still not released, but as indicated in https://github.com/MariaDB/mariadb-connector-nodejs#road-map, next version will permit fast bulk. (https://jira.mariadb.org/projects/CONJS/issues/CONJS-21)

from mariadb-connector-nodejs.

vaintroub avatar vaintroub commented on June 3, 2024

there is a lot of concept of batch bulk inserts, and there is a dedicated page on how to speedup inserts https://mariadb.com/kb/en/library/how-to-quickly-insert-data-into-mariadb/

I recommend multivalue inserts, so far those were the best.

from mariadb-connector-nodejs.

rusher avatar rusher commented on June 3, 2024

until then The fastest way to insert data for now, if you can is to rewrite query :
example :

connection.query("INSERT INTO myTable(col1, col2) values (?, ?)", [1, 'john']);
connection.query("INSERT INTO myTable(col1, col2) values (?, ?)", [2, 'jack']);

transform to :

connection.query("INSERT INTO myTable(col1, col2) values (?, ?), (?, ?)", [1, 'john', 2, 'jack']);

from mariadb-connector-nodejs.

vaintroub avatar vaintroub commented on June 3, 2024

yes, this is multivalue insert :)

from mariadb-connector-nodejs.

rusher avatar rusher commented on June 3, 2024

cross-post :)

from mariadb-connector-nodejs.

markddrake avatar markddrake commented on June 3, 2024

Since I am generating everything, that would be relatively simple I think. Is there a recommend number of rows to process in a single insert

from mariadb-connector-nodejs.

rusher avatar rusher commented on June 3, 2024

not really, the real limit is that query size must not be > to server max_allowed_packet value.
(default to 16M)

from mariadb-connector-nodejs.

markddrake avatar markddrake commented on June 3, 2024

Now we're cooking... 15000/s thanks

from mariadb-connector-nodejs.

markddrake avatar markddrake commented on June 3, 2024

Actually with comments removed I am getting ~25000/s on tables with a small number of columns.

C:\Development\YADAMU\MariaDB>node client\import.js --USERNAME=root --HOSTNAME=192.168.1.250 --PORT=3307 --PASSWORD=oracle --DATABASE=mysql --File=..\JSON\Oracle\18c\SH_DATA_ONLY.json touser=SH1
2018-10-10T16:03:02.444Z: Table "COSTS". Rows 0. Elaspsed Time 0ms. Throughput NaN rows/s.

2018-10-10T16:03:38.263Z: Table "SALES". Rows 918843. Elaspsed Time 35775ms. Throughput 25684 rows/s.

2018-10-10T16:03:38.507Z: Table "TIMES". Rows 1826. Elaspsed Time 201ms. Throughput 9085 rows/s.

2018-10-10T16:03:38.549Z: Table "CHANNELS". Rows 5. Elaspsed Time 0ms. Throughput Infinity rows/s.

2018-10-10T16:03:38.572Z: Table "PRODUCTS". Rows 72. Elaspsed Time 0ms. Throughput Infinity rows/s.

2018-10-10T16:03:38.630Z: Table "COUNTRIES". Rows 23. Elaspsed Time 0ms. Throughput Infinity rows/s.

2018-10-10T16:03:43.327Z: Table "CUSTOMERS". Rows 55500. Elaspsed Time 4691ms. Throughput 11831 rows/s.

2018-10-10T16:03:43.426Z: Table "PROMOTIONS". Rows 503. Elaspsed Time 59ms. Throughput 8525 rows/s.

Closing Pool
Import operation completed successfully.

C:\Development\YADAMU\MariaDBC:\Development\YADAMU\MariaDB>mysql -uroot -poracle -h192.168.1.250 -Dmysql -P3307 -v -f
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 712
Server version: 10.3.9-MariaDB mariadb.org binary distribution

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [mysql]> use SH1;
Database changed
MariaDB [SH1]> select count(*) from SALES;

select count(*) from SALES

+----------+
| count(*) |
+----------+
| 918843 |
+----------+
1 row in set (0.262 sec)

MariaDB [SH1]>

from mariadb-connector-nodejs.

markddrake avatar markddrake commented on June 3, 2024

If you need a test for the new bulk insert let me know.

from mariadb-connector-nodejs.

vaintroub avatar vaintroub commented on June 3, 2024

To explain 200 inserts per second, with individual inserts. I suspect disk is the bottleneck here

With default durability settings (innodb-flush-log-at-trx-commit=1) , for each insert, there is a small amount of log data written and flushed to stable storage in the redo log.
A flush is expensive on hard disk , where with 7200 RPM you can only get 120 sectors written this way.
With less strict durability (innodb-flush-log-at-trx-commit=2) would be orders of magnitude faster, however if OS crashes, some of data can be lost.
Transactions, or multivalue inserts combine a lot of small redo log writes into one large single write on commit, therefore they are faster.

from mariadb-connector-nodejs.

markddrake avatar markddrake commented on June 3, 2024

FWITW the disk is a Samsung 860 EVO M.2 on an Intel NUC with an i7-6770HQ

from mariadb-connector-nodejs.

vaintroub avatar vaintroub commented on June 3, 2024

Thanks. Network latency is certainly a factor as well (the multiple send-receive roundtrips in case of individual statements vs batch that is sent once)

from mariadb-connector-nodejs.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.