-
Notifications
You must be signed in to change notification settings - Fork 2.3k
"LOAD DATA LOCAL INFILE" is much slower than mysql command line #364
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
How do you configure?
Have you tried mysql commandline with and without compress? |
I just open one DB connection and use it to do
I use the same strategy to call mysql command line (with compress option) like below:
|
How about mysql client without compress? |
I have not tested that for this case, but I have compared mysql with/without compression with other data, the compression should not possibly reduce the time to 1/8. |
@h12w are each of your 8 goroutines writing to the same table? |
Yes, I run the test based on one table. But the service I built periodically imports data into multiple tables of MySQL. Currently we use the mysql command line tool and the database engine is switched from InnoDB to MyISAM, which improves the performance significantly. |
Interesting. I did a test on ~570MB of data importing into a single table and mysqlimport took ~56s while my Go lang implementation (not using go routines) took around ~57s on average. Both tests used a socket connection, and the table uses MyISAM (truncated before each test run). Appears to be working ok for me for the single table use case. |
It is important to compare mysql client and go-sql-driver/mysql. |
@ryandjurovich, I would have the same result with your configuration. The difference happens when you reuse the same DB connection and load multiple data files simultaneously in multiple goroutines. Please note that a DB connection is implemented as a connection pool that should allows multiple actual DB connections. If I have an 8-core CPU, I would expect about 7-8 seconds loading speed for 570MB data in a 1G Ethernet environment. |
@h12w Have you configured DB.SetMaxIdleConns ? |
SetMaxIdleConns is not set. |
I'm sorry. SetMaxIdleConns shoudn't affect since mysql cli doesn't pool connections. Could you get some stackdump for two programs? import (
"net"
_ "net/http/pprof"
)
func init() {
go http.ListenAndServe(":3000", nil)
} and
|
Multiple process instances of mysql cli are called concurrently, even if mysql cli doesn't pool connections. |
How many concurrency CLI version use? 8? |
Anyway, I think stackdump is best information you can provide us except reproducible example. |
First of all a working test (as in a small, complete program) is missing. We have no idea what you are really doing there. The Line 157 in d4c1329
We just send whatever Read returns. In the worst case it's just a slice of the length 1, which could produce overhead. But I think that's also very unlikely. Usually Read fills the whole buffer unless there is a good reason not to.
|
Thanks. I will try to write a test program for comparison next week. |
I found important difference between libmysqlclient and go-sql-driver/mysql. libmysqlclient uses net_buffer_length buffer size. (default: 16KB). In case of go-sql-driver/mysql, it uses Linux's typical readahed size is 128KB. Larger buffer size may makes inefficient. Additionally, Line 142 in d4c1329
|
Thank you for the efforts. I am planing to use this driver instead of mysql command line tool recently. I will try to test it in the real environment then. |
@h12w Could you take |
Our production code has switched from mysql command line tool to go-sql-driver now, and here is the dstat.log. I am not sure if it is useful because there are other workloads running on the same server besides the MySQL writer: dstat.log:
|
@h12w Thank you. Is this log on MySQL server? or client? |
It is a log from the client side, and the MySQL server is on another machine. |
How was the speed? |
The performance is good enough so we have made the switch. |
Relieved to hear that. Thank you for testing. |
Can this issue be closed? |
Let me just close it. I will report if any further performance issue found. Thank you very much! |
In my test, I am trying to transfer 149MB files (each small file is about 3MB).
With go-sql-driver/mysql, it takes more than 3 minutes, but with mysql command line, it only takes 16 seconds.
Here is my guess:
The text was updated successfully, but these errors were encountered: