Skip to content

Conversation

jjb
Copy link
Contributor

@jjb jjb commented Oct 11, 2024

Description

adds busy_threads to stats and also DRYs related code

the DRYing code (worker_handle.rb and worker.rb) can go into another PR or removed if preferred

Your checklist for this pull request

  • I have reviewed the guidelines for contributing to this repository.
  • I have added (or updated) appropriate tests if this PR fixes a bug or adds a feature.
  • My pull request is 100 lines added/removed or less so that it can be easily reviewed.
  • If this PR doesn't need tests (docs change), I added [ci skip] to the title of the PR.
  • If this closes any issues, I have added "Closes #issue" to the PR description or my commit messages.
  • I have updated the documentation accordingly.
  • All new and existing tests passed, including Rubocop.

@jjb jjb force-pushed the add-busy_threads-stat branch from be96f05 to 1eda2aa Compare October 11, 2024 23:05
@jjb jjb force-pushed the add-busy_threads-stat branch from 1eda2aa to 2f37c84 Compare October 11, 2024 23:16
Copy link
Contributor

@schneems schneems left a comment

Choose a reason for hiding this comment

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

I like the idea. I didn't actually realize running wasn't this metric until you mentioned it in slack chat.

I've made a perf change request. I also ask that you update the doc/stats.md to document this new feature.

I made a comment about a locking call to the thread pool. I would like to think more on it or hear more thoughts on it before figuring out how I think we should move. Basically: What do we think our guarantees are or should be for these metrics regarding threadsafety and race conditions?

@jjb
Copy link
Contributor Author

jjb commented Oct 13, 2024

okay i took a stab at at documentation, take a look.

please note that I have now written most of this document, starting in #2525 when i created it. this is, frankly, ridiculous 😅 - someone with a better understanding of this stuff should spruce is up and fill in the ?

@jjb jjb requested a review from schneems October 13, 2024 17:51
jjb and others added 3 commits October 13, 2024 13:52
@jjb
Copy link
Contributor Author

jjb commented Oct 14, 2024

Do we have multiple locking calls in this stats collection? If so, we should refactor to a single one, otherwise individual metrics might be correct, but the collective total suffers from a race condition.

# running
attr_reader :spawned

# backlog
with_mutex { @todo.size }

# pool_capacity
waiting + (@max - spawned)

# busy_threads
with_mutex { @spawned - @waiting + @todo.size }

# max thread: doesn't need mutex
# request count: theoretically can also be incorrect number in the stats snapshot
# but i'm guessing we are okay with that, because it doesn't have an interesting relationship
# to the other stats 

@jjb
Copy link
Contributor Author

jjb commented Oct 14, 2024

i propose that improvements to stat locking should go into another PR, since status quo is already inconsistent locking for stats

@dentarg
Copy link
Member

dentarg commented Oct 14, 2024

i propose that improvements to stat locking should go into another PR, since status quo is already inconsistent locking for stats

Not sure about that, don't we want stats we can trust?

@jjb
Copy link
Contributor Author

jjb commented Oct 14, 2024

Not sure about that, don't we want stats we can trust?

I’m saying, this PR doesn’t introduce new phenomenon or behavior - the stats in master already don’t use the same mutex-controlled timeslice. putting all stats in the same mutex could be done in a PR before or after this one (I could put it together if interested).

@jjb
Copy link
Contributor Author

jjb commented Oct 17, 2024

@dentarg WDYT?

@MSP-Greg
Copy link
Member

@jjb

I'm assuming that #3527 addresses @schneems issue with multiple locking calls. My question to you is if #3527 and #3528 are merged/accepted, are you ok with rebasing and adjusting this to work with the updates?

Or, we could flip the order and merge this first. Not sure which is easier 'collectively'...

@jjb
Copy link
Contributor Author

jjb commented Oct 22, 2024

definitely discuss and merge the other PRs first

@jjb jjb requested a review from MSP-Greg October 26, 2024 01:01
@jjb
Copy link
Contributor Author

jjb commented Oct 26, 2024

@schneems @dentarg @MSP-Greg ready! i'll clean up the commits after discussion

@MSP-Greg
Copy link
Member

MSP-Greg commented Oct 26, 2024

@jjb

definitely discuss and merge the other PRs first

I've only merged the 'lib' PR, but I can update the 'test' PR (#3528) for this. LGTM, I'll wait a bit to see if anyone else looks at it. Thanks.

@MSP-Greg
Copy link
Member

MSP-Greg commented Nov 7, 2024

@schneems You ok with this as is?

@MSP-Greg MSP-Greg merged commit 9d7ab82 into puma:master Nov 26, 2024
78 checks passed
@jjb jjb deleted the add-busy_threads-stat branch November 26, 2024 02:33
benoittgt added a commit to benoittgt/prometheus_exporter that referenced this pull request Feb 3, 2025
Expose a prometheus metric new thread stats from Puma

- puma/puma#3517
benoittgt added a commit to benoittgt/prometheus_exporter that referenced this pull request Apr 17, 2025
Expose a prometheus metric new thread stats from Puma

- puma/puma#3517
benoittgt added a commit to benoittgt/prometheus_exporter that referenced this pull request Apr 17, 2025
Expose a prometheus metric new thread stats from Puma

- puma/puma#3517
tgxworld pushed a commit to discourse/prometheus_exporter that referenced this pull request May 9, 2025
New Puma version has a [nice addition](puma/puma#3517) of metric on busy threads.

> busy_threads: running - how many threads are waiting to receive work + how many requests are waiting for a thread to pick them up. this is a "wholistic" stat reflecting the overall current state of work to be done and the capacity to do it.
[source](https://github.com/puma/puma/blob/master/docs/stats.md#single-mode-and-individual-workers-in-cluster-mode)
f1sherman added a commit to f1sherman/integrations-extras that referenced this pull request May 20, 2025
This new stat was [added about 6 months
ago](puma/puma#3517) to track "the overall
current state of work to be done and the capacity to do it". It seems
like it could be useful to track, potentially for autoscaling or other
applications.
f1sherman added a commit to f1sherman/integrations-extras that referenced this pull request May 20, 2025
This new stat was [added about 6 months
ago](puma/puma#3517) to track "the overall
current state of work to be done and the capacity to do it". It seems
like it could be useful to track, potentially for autoscaling or other
applications.
f1sherman added a commit to f1sherman/integrations-extras that referenced this pull request May 20, 2025
This new stat was [added about 6 months
ago](puma/puma#3517) to track "the overall
current state of work to be done and the capacity to do it". It seems
like it could be useful to track, potentially for autoscaling or other
applications.
f1sherman added a commit to f1sherman/integrations-extras that referenced this pull request May 20, 2025
This new stat was [added about 6 months
ago](puma/puma#3517) to track "the overall
current state of work to be done and the capacity to do it". It seems
like it could be useful to track, potentially for autoscaling or other
applications.
github-merge-queue bot pushed a commit to DataDog/integrations-extras that referenced this pull request Jun 3, 2025
* Add `busy_threads` metric to Puma integration

This new stat was [added about 6 months
ago](puma/puma#3517) to track "the overall
current state of work to be done and the capacity to do it". It seems
like it could be useful to track, potentially for autoscaling or other
applications.

* Update puma/metadata.csv

Co-authored-by: May Lee <may.lee@datadoghq.com>

* Update puma/metadata.csv

Co-authored-by: Steven Yuen <steven.yuen@datadoghq.com>

---------

Co-authored-by: May Lee <may.lee@datadoghq.com>
Co-authored-by: Steven Yuen <steven.yuen@datadoghq.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants