Skip to content

Provide DB level Read/Write timeout settings. #486

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

Closed
sjmudd opened this issue Sep 26, 2016 · 4 comments
Closed

Provide DB level Read/Write timeout settings. #486

sjmudd opened this issue Sep 26, 2016 · 4 comments

Comments

@sjmudd
Copy link
Contributor

sjmudd commented Sep 26, 2016

Issue description

The dsns used to connect to a server have a new optional readTimeout and writeTimeout parameter. This assumes that all queries want these values to be applied when in real life some queries may need to use a different value.

It would be convenient to have a mechanism to set these values at the query level, that is prior to db.Query(), db.Exec() calls, so maybe as part of the DB layer, in a call similar to the existing:

func (db *DB) SetConnMaxLifetime(d time.Duration)

Context

Applications like orchestrator (https://github.com/outbrain/orchestrator) need to connect frequently to a number of MySQL servers to monitor them or to do maintenance on them. In this case the number of servers being monitored could potentially be high.

I am already using the DSN timeout values but the problem is the single connections to a monitored server may try to do two different things:
(a) monitoring: check the server is reachable , get some status information from it. In cases like this the short timeouts are good as the server may sometimes not respond properly or even at all and it's better to find out fast.
(b) maintenance operations on a server may require reconfiguring it, changing settings and running tasks that if not completed correctly could break the server. Consequently a longer timeout is acceptable and probably better to avoid issues.

(a) and (b) have conflicting requirements and currently require me to setup different pools to the same server using different timeouts in the dsn. That's not efficient and makes coding more complex when a large number of connections are being used.

Thus moving this "timeout" layer if possible to the DB connection seems like a better solution.

Example interface

Suggestion: consider adding an interface similar to:

func (db *DB) SetReadTimeout(d time.Duration)
func (db *DB) SetWriteTimeout(d time.Duration)

Other ways to address this same problem would also be fine.

@methane
Copy link
Member

methane commented Sep 26, 2016

I think this issue should be in Go's issue tracker.

Pesonally speaking, I don't think write_timeout is useful enough. Adding context to each APIs is better.
e.g. func (db *DB) QueryCtx(ctx context.Context, query string, args ...interface{}) (*Rows, error)

@dgryski
Copy link

dgryski commented Sep 26, 2016

golang/go#15123

@methane
Copy link
Member

methane commented Oct 27, 2016

This issue seems be superseded by #496.
Can I close this?

@methane
Copy link
Member

methane commented Nov 7, 2016

I close this, in faver of context support.
Feel free to add comment with realistic and common example which isn't happy with context.

@methane methane closed this as completed Nov 7, 2016
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

3 participants