-
Notifications
You must be signed in to change notification settings - Fork 502
Update database connections defaults #5853
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
Update database connections defaults #5853
Conversation
b0a5681
to
9b46080
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you @jananiarunachalam for working on this contribution!
defaultConnMaxLifetime, err := time.ParseDuration("30s") | ||
db.DB().SetConnMaxLifetime(defaultConnMaxLifetime) // default value | ||
if err != nil { | ||
return nil, "", false, nil, fmt.Errorf("failed to parse conn_max_lifetime %q: %w", defaultConnMaxLifetime, err) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The SetConnMaxLifetime function is already called later, based on the ConnMaxLifetime setting.
We don't need to make any change there. What we need to adjust is the ConnMaxIdleTime property calling SetConnMaxIdleTime, maybe with a value of 30s.
Also note that you will not need to make any parsing for that (i.e. time.ParseDuration("30s")
), you can just call SetConnMaxIdleTime(time.Second * 30
). We may define this as a constant in the function, and probably the MaxOpenConns and MaxIdleConns numbers too.
Also, could you update the documentation in https://github.com/spiffe/spire/blob/main/doc/plugin_server_datastore_sql.md with the new defaults? |
doc/plugin_server_datastore_sql.md
Outdated
| max_idle_conns | The maximum number of idle connections in the pool (default: 100) | | ||
| conn_max_lifetime | The maximum amount of time a connection may be reused (default: 30s) | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actual change
7fc428b
to
b9ec496
Compare
if cfg.MaxIdleConns != nil { | ||
db.DB().SetMaxIdleConns(*cfg.MaxIdleConns) | ||
} | ||
const connMaxLifetime = time.Second * 30 | ||
db.DB().SetConnMaxLifetime(connMaxLifetime) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The SetConnMaxLifetime function is already called later, based on the ConnMaxLifetime setting. We shouldn't need to make any change here. What we need to adjust is the ConnMaxIdleTime
property calling SetConnMaxIdleTime
, maybe with a value of 30s.
doc/plugin_server_datastore_sql.md
Outdated
| max_idle_conns | The maximum number of idle connections in the pool (default: 2) | | ||
| conn_max_lifetime | The maximum amount of time a connection may be reused (default: unlimited) | | ||
| max_idle_conns | The maximum number of idle connections in the pool (default: 100) | | ||
| conn_max_lifetime | The maximum amount of time a connection may be reused (default: 30s) | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't need to make any change in the conn_max_lifetime
. We need to set ConnMaxIdleTime to 30s and document it (we will not expose a setting for that).
Signed-off-by: jananiarunachalam <[email protected]>
Signed-off-by: jananiarunachalam <[email protected]>
Signed-off-by: jananiarunachalam <[email protected]>
Signed-off-by: jananiarunachalam <[email protected]>
Signed-off-by: jananiarunachalam <[email protected]>
Signed-off-by: jananiarunachalam <[email protected]>
b9ec496
to
0677af5
Compare
Signed-off-by: jananiarunachalam <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you @jananiarunachalam!
Pull Request check list
Affected functionality
Description of change
Which issue this PR fixes
Fixes #5802