Comments (16)
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.
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.
That gets me to about 1250 rows per second..
from mariadb-connector-nodejs.
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.
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.
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.
yes, this is multivalue insert :)
from mariadb-connector-nodejs.
cross-post :)
from mariadb-connector-nodejs.
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.
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.
Now we're cooking... 15000/s thanks
from mariadb-connector-nodejs.
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.
If you need a test for the new bulk insert let me know.
from mariadb-connector-nodejs.
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.
FWITW the disk is a Samsung 860 EVO M.2 on an Intel NUC with an i7-6770HQ
from mariadb-connector-nodejs.
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)
- 3.2.2 Packets out of Order error inserting large document on Linux. Same code works with 2.5.6 on Linux and 3.2.2. on Windows HOT 3
- TypeError: Cannot read properties of undefined (reading '0') : Inserting rows with batch. HOT 5
- Connection stops responding after exception thrown by 'batch' operation. HOT 1
- Feature Request: Copy cmdParams to custom error logger HOT 2
- batch result insertId should be last one or documentation should be updated HOT 1
- TIME format 00:00:00 return 102278627328:00:34 HOT 1
- batch bulk insert gaps HOT 13
- Best option connection with PHP 8.3 HOT 1
- Issue with a client... for some reason got those strange messages. HOT 4
- importFile throws when default database was not set HOT 1
- Big Array Batch Not Support HOT 1
- retrieve connection from pool timeout HOT 6
- Read-only Connections (feature request) HOT 2
- can I disable prepare when use execute ? HOT 2
- Unexpected symbol 'n' in int\bigint field HOT 2
- Large Insert never completes with .batch() and node 3.2.3 HOT 3
- Insert of Long Rows causes "ECONNRESET" or "Got packets out of order" with 3.2.3. Same code works with 2.5.6 HOT 4
- Insert fails with SQL Error with mariadb 3.2.3 on Linux. Same code works with 2.5.6 on Linux and works with 3.2.3 on Windows HOT 7
- COALESCE returning string instead of number when comparing SIGNED and UNSIGNED HOT 2
- decimal values still string in result of query with decimalAsNumber true HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mariadb-connector-nodejs.