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

feat: Add pool connection info to __lbheartbeat__ for ops #985

Merged
merged 7 commits into from
Feb 1, 2021

Conversation

jrconlin
Copy link
Member

Description

This will add several fields to __lbheartbeat__ if
database_pool_max_size is specified. These include:

{
  "active_connections": ... /* Number of active connections */,
  "idle_connections": ... /* number of idle connections */,
  "duration": ... /* how long no idle connections have been availble */,
}

Note that "duration" will only be present if idle_connections has been
zero since the last time a check was performed.

  • this also adds database_pool_max_size as a config option.

Testing

curl http://{server}/__lbheartbeat should return
200 with a body of
{"active_connections":0,"idle_connections":0}

(values may differ depending on the server being queried.

A saturated server should return something like:
{"active_connections":0,"idle_connections":0, "duration_ms": 1000}

indicating that the server has been saturated for 1 second.
Note the saturation is only checked on each call to __lbheartbeat__, however that should be sufficient for most of the instances we've seen.

Issue(s)

Issue: #945

This will add several fields to `__lbheartbeat__` if
`database_pool_max_size` is specified. These include:

```json
{
  "active_connections": ... /* Number of active connections */,
  "idle_connections": ... /* number of idle connections */,
  "duration": ... /* how long no idle connections have been availble */,
}
```

Note that "duration" will only be present if `idle_connections` has been
zero since the last time a check was performed.

* this also adds `database_pool_max_size` as a config option.

Issue: #945
@jrconlin jrconlin requested a review from a team January 28, 2021 01:03
@jrconlin jrconlin requested a review from Micheletto January 28, 2021 15:57
Comment on lines 557 to 559

if let Some(max_size) = deadman.max_size {
if db_state.connections >= max_size && db_state.idle_connections == 0 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here and below when we include it in json: connections isn't the active count

Suggested change
if let Some(max_size) = deadman.max_size {
if db_state.connections >= max_size && db_state.idle_connections == 0 {
let active = db_state.connections - db_state.idle_connections;
if let Some(max_size) = deadman.max_size {
if active >= max_size && db_state.idle_connections == 0 {

src/settings.rs Outdated
@@ -114,6 +121,7 @@ impl Settings {
s.set_default("database_pool_connection_timeout", Some(30))?;
s.set_default("database_use_test_transactions", false)?;
s.set_default("master_secret", "")?;
s.set_default::<Option<String>>("database_pool_max_size", Some("10".to_owned()))?;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

probably want to kill this (was it for debugging?). I'm surprised it even works as a String (it expects u32 here)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be simplified to just Some(10), rather than letting things auto-parse. There was some old debugging that is the source. I do note that we have database_pool_max_size set, but weren't including it as an option?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We just didn't fill in a default here, so it defaults to None. The different db backends do their own default when it's None -- hence suggesting we kill it because it isn't really needed but it also doesn't match the Default impl setting it to None (this method's defaults values setup here and the Default impl values should really match and hopefully one day we won't need both versions of setting defaults #253)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll add a comment in that respect so it's clearer. Thanks!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Heh, although I see the value is 10 for both mysql and spanner.

};

let deadarc = state.deadman.clone();
let mut deadman = *deadarc.read().await;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This confused me for a while (getting a mut here) -- finally realized it's a Copy type

* includes regressing tokio to 0.2.4
@jrconlin jrconlin mentioned this pull request Feb 1, 2021
@jrconlin jrconlin requested a review from pjenvey February 1, 2021 21:46
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

Successfully merging this pull request may close these issues.

2 participants