Skip to content
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

timeout option is invalid!!! #488

Closed
duyanghao opened this issue Oct 17, 2016 · 12 comments
Closed

timeout option is invalid!!! #488

duyanghao opened this issue Oct 17, 2016 · 12 comments

Comments

@duyanghao
Copy link

duyanghao commented Oct 17, 2016

go version:
go version go1.7.1 linux/amd64
mysql version:
Server version: 5.5.24

As the document described below:
https://github.com/go-sql-driver/mysql#timeout

i set timeout option to 30s, and run a test for 10 concurrent http requests(producing 10 mysql sockets).
but the problem is that the above 10 sockets still exist instead of disappearing after 30s.
In addition,i have done nothing but waiting for several minutes after 10 http requests.

@methane
Copy link
Member

methane commented Oct 17, 2016

You may misunderstoods the option.
See https://golang.org/pkg/database/sql/#DB.SetConnMaxLifetime

(FYI, SetConnMaxLifetime limits maximum time to reuse, closing expired connection may be deferred. In other words, if you set SetConnMaxLifetime(time.Second*30), you need to wait
more than 30sec.)

@duyanghao
Copy link
Author

duyanghao commented Oct 17, 2016

So,what about the keep-alive timeout option as i mean above? @methane
After all, the socket can not keep open all the time!

@methane
Copy link
Member

methane commented Oct 17, 2016

Sorry, I can't get what you mean.
What is "keep-alive timeout"? Do you mean TCP keep-alive?

@methane
Copy link
Member

methane commented Oct 17, 2016

The doc says "Driver side connection timeout."
It means "how long wait to connect".
For example, resolving hostname may be included in connection timeout.

After connection made, this option has no meaning.

@duyanghao
Copy link
Author

duyanghao commented Oct 17, 2016

@methane what i mean is the max wait time when there is no interaction(Similar to the wait_timeout on the side of server).
for example:
the client socket will close itself after 30 seconds without any interaction with server.

@methane
Copy link
Member

methane commented Oct 17, 2016

That's one of motivations of SetConnMaxLifetime.
Set it lower than wait_timeout. I recommend lower than wait_timeout/2.

@duyanghao
Copy link
Author

@methane As far as i know,the SetConnMaxLifetime means the lifetime starting from created,but what i need is the lifetime starting from no-interaction.
Do you get what i mean?

@methane
Copy link
Member

methane commented Oct 18, 2016

(I replied at golang/go#9851 (comment))

@duyanghao
Copy link
Author

duyanghao commented Oct 19, 2016

@methane thank for your reply!
Here is another question not related to the above one:
Consider this:
i want to insert many data into mysql,but i am curious about which way is more efficicent!
Scheme 1:
Execute each insert statement respectively.
Scheme 2:
combine these insert action into only one statement,and execute it.

as the document outlines:

Connection pooling means that executing two consecutive statements on a single database might open two connections and execute them separately. It is fairly common for programmers to be confused as to why their code misbehaves. For example, LOCK TABLES followed by an INSERT can block because the INSERT is on a connection that does not hold the table lock.

So,what my question is how the connection pool processes the above two schemes?
Will the sql connection pool open many connections and execute them separately,or will the sql connection pool only open one connection and execute it on Scheme 2?

for example:
INSERT INTO tbl_name (a,b,c) VALUES(1,2,3),(4,5,6),(7,8,9);

@pjebs
Copy link

pjebs commented Oct 19, 2016

if it's a multi insert, it'll be done once using same connection.

@duyanghao
Copy link
Author

duyanghao commented Oct 19, 2016

@pjebs you mean it will only open one connection to process insert on Scheme 2?
in other words,the Scheme 2 is more efficient than Scheme 1, right?

@methane
Copy link
Member

methane commented Oct 19, 2016

Right.

More faster option is: Save data into csv file, then execute "LOAD LOCAL INFILE" statement.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants