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
Puma.stats is now a hash, not JSON. #2086
Conversation
Luckily for us the next release will probably be 5.0. Anyone else have thoughts on this? Consider the proposal basically changing |
lib/puma.rb
Outdated
@@ -19,10 +19,16 @@ def self.stats_object=(val) | |||
@get_stats = val | |||
end | |||
|
|||
def self.stats | |||
@get_stats.stats | |||
def self.stats_hash |
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.
FWIW I don't like the rename. We should either add stats_hash or just change stats to a hash and bump major.
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.
I was guessing this would land on a 4.x release, but happy to change :)
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.
Yeah no way for you to know really but I'm targeting the next release to be a major bump 👍
Done :) |
History.md
Outdated
@@ -3,6 +3,7 @@ | |||
* Features | |||
* Add pumactl `thread-backtraces` command to print thread backtraces (#2053) | |||
* Configuration: `environment` is read from `RAILS_ENV`, if `RACK_ENV` can't be found (#2022) | |||
* `Puma.stats` now returns a Hash instead of a JSON string |
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.
Needs a link to your PR number (#2086).
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.
^^^^ Still needs this.
@@ -94,7 +94,11 @@ def term? | |||
|
|||
def ping!(status) | |||
@last_checkin = Time.now | |||
@last_status = status | |||
captures = status.match(/{ "backlog":(?<backlog>\d*), "running":(?<running>\d*), "pool_capacity":(?<pool_capacity>\d*), "max_threads": (?<max_threads>\d*) }/) |
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.
Shouldn't we just deserialize the JSON response, really?
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.
There seems to have been an intentional decision made in the past to not let Puma rely on the JSON gem. I don't have the context as to why but since this is an internal message being passed I figured it wasn't worth adding the dependency as we don't need more robust parsing. I can change it if you still think it is better to do so.
@@ -352,9 +356,26 @@ def reload_worker_directory | |||
# the master process. | |||
def stats |
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.
this is so much more readable now ❤️
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.
A few minor requests, then I think this is good for inclusion in 5.0
Needs the changelog mod, then it's g2g. |
Having access to the hash allows to produce stats in other ways (such as StatsD) without having to parse JSON of data that is available in memory. An example of this workaround is https://github.com/yob/puma-plugin-statsd/blob/fa6ba1f5074473618643ef7cf99747801a001dec/lib/puma/plugin/statsd.rb#L112-L114
fb8b934
to
bdf5cb5
Compare
Changelog added & squashed to one commit :) |
Thanks! I'll be writing an upgrade guide later, will be sure to mention this. |
I'm going to move to remove this change. It will break the |
That gem has the exact behaviour why I opened this PR, why parse JSON of what you have in memory? It's trivial to work around. |
It's already existing behavior and would break countless apps if it changed. The proposed behavior is good, but lets make a non breaking change to get it |
The change in #2086 is not backwards compatible with existing gems that parse the output of Puma.stats such as barnes. Releasing a version of puma with this change would break anyone using the Barnes app and only in production. I'm proposing to keep the existing interface and instead add a new API. This buys us all the features of #2086 without causing any production facing downtime by customers due to API incompatibilities. Unfortunately it requires that we serialize and the de-serialize the values. One prior benefit of returning json in a string was that it allowed an end user to de-serialize using a faster json algorithm such as `oj` via the "multi json" gem. But the performance penalty will be better than a stability break.
The change in #2086 is not backwards compatible with existing gems that parse the output of Puma.stats such as barnes. Releasing a version of puma with this change would break anyone using the Barnes app and only in production. I'm proposing to keep the existing interface and instead add a new API. This buys us all the features of #2086 without causing any production facing downtime by customers due to API incompatibilities. Unfortunately it requires that we serialize and the de-serialize the values. One prior benefit of returning json in a string was that it allowed an end user to de-serialize using a faster json algorithm such as `oj` via the "multi json" gem. But the performance penalty will be better than a stability break.
The change in #2086 is not backwards compatible with existing gems that parse the output of Puma.stats such as barnes. Releasing a version of puma with this change would break anyone using the Barnes app and only in production. I'm proposing to keep the existing interface and instead add a new API. This buys us all the features of #2086 without causing any production facing downtime by customers due to API incompatibilities. Unfortunately it requires that we serialize and the de-serialize the values. One prior benefit of returning json in a string was that it allowed an end user to de-serialize using a faster json algorithm such as `oj` via the "multi json" gem. But the performance penalty will be better than a stability break.
The change in #2086 is not backwards compatible with existing gems that parse the output of Puma.stats such as barnes. Releasing a version of puma with this change would break anyone using the Barnes app and only in production. I'm proposing to keep the existing interface and instead add a new API. This buys us all the features of #2086 without causing any production facing downtime by customers due to API incompatibilities. Unfortunately it requires that we serialize and the de-serialize the values. One prior benefit of returning json in a string was that it allowed an end user to de-serialize using a faster json algorithm such as `oj` via the "multi json" gem. But the performance penalty will be better than a stability break.
I've got a spiked PR of this in #2253. Tests are passing, can y'all take a look? |
* Revert api change from #2086 introduce Puma.stats_hash api The change in #2086 is not backwards compatible with existing gems that parse the output of Puma.stats such as barnes. Releasing a version of puma with this change would break anyone using the Barnes app and only in production. I'm proposing to keep the existing interface and instead add a new API. This buys us all the features of #2086 without causing any production facing downtime by customers due to API incompatibilities. Unfortunately it requires that we serialize and the de-serialize the values. One prior benefit of returning json in a string was that it allowed an end user to de-serialize using a faster json algorithm such as `oj` via the "multi json" gem. But the performance penalty will be better than a stability break.
Description
Having access to the hash allows to produce stats in other ways (such as StatsD) without having to parse JSON of data that is available in memory. Examples of this workaround are:
Changed
Puma.stats
toPuma.stats_json
to help disambiguate. An alias is provided for backwards compatibility. In a new major releasePuma.stats
could point to the hash version or be removed altogether.Your checklist for this pull request
[changelog skip]
to all commit messages.[ci skip]
to the title of the PR.#issue
" to the PR description or my commit messages.