-
Notifications
You must be signed in to change notification settings - Fork 24.7k
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
ProfileResult and CollectorResult should print machine readable timing information #22561
Conversation
I think profile api should be consistent with all our other apis and support the human flag. In any case, we should allow for printing out machine readable time rather than only human readable time. I also wonder why we went for nanoseconds here knowing that we have milliseconds everywhere else. |
++ to returning machine readable by default, and supporting Nanos probably make sense since the |
yes it makes sense, I (mis)understood that we were printing out millis on the REST layer although we had nanos on the java object. |
@@ -944,6 +944,14 @@ public XContentBuilder percentageField(String rawFieldName, String readableField | |||
return this; | |||
} | |||
|
|||
public XContentBuilder nanosAsMillis(String rawFieldName, String readableFieldName, long nanos) throws IOException { |
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.
why nanosAsMillis? Does this one print out nanos or millis?
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.
Good point, the "machine readable" value is printed out "as is" (that its a nanos time value is actually only clear by the field and variable names). The human readable string assumes the input is nanos and prints its as millis (adding "ms" suffix, dividing by the appropriate constant). Thats why I choose that name, but now I start to think that this formatting is probably only useful for the two cases in the Profile output and we should makes this more generic?
I was thinking about putting it somewhere else (some static util in one of the Profile response classes), but since this method deals with the "humanReadable" flag its probably best here alongside the similar other methods?
One idea would make the signature (String rawFieldName, String readableFieldName, long rawLong, String formattedLong) and keeping the formatting in the respective classes, wdyt? Then the name could be sth. like "formattedLongField"?
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.
can't you use the existing timeValueField
that takes the TimeUnit too as an argument? Then the conversion to readable should come for free, and the raw field gets printed out as-is.
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 problem is that TImeUnit.toString() is not very accurate, also it rounds to the "larges" unit that needs to be represented, so you get all kinds of variations like "1.1m", "50.9s", "761.5ms", "45585997303" (<- thats nanos then) whereas the current format always prints a fixed-length "ms" with 10 digits precision. I think we need to keep that.
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.
sounds like we never used TimeValue#toString for nanoseconds then? I tend to think that we should fix that instead. WDYT?
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 don't think so. TimeUnit#toString doesn't seem to be used for precise output, but I also don't think we should change that because it is certainly used all over the place. If we are fine with reducing the profile output precision for the human readable format we can use TimeUnit, otherwise we should stick to the current 10-digit-ms format.
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.
Ok then we should stick with the current api, we are already printing out nanoseconds in a few places, I found for instance running_time
in TaskInfo
. We should be consistent with how we do things elsewhere. That means that the human readable time in the profile api will lose some precision, unless we want to go change how we print out nanoseconds at some point later.
We can certainly introduce new fields in 5.x |
Thanks for the input, so starting with for 6.0 we would have
So for the default case where the "human" flag isn't set, the field name and value would change. I think thats okay, but should be marked as "breaking" and we need to adapt the docs etc. For introducing parsing of the profile section in 5.x, it would be great if we could already introduce the "time_in_nanos" field in addition to the "time" field and print out both, regardless of the "human" flag. @clintongormley Is that something we can do in terms of breaking changes? Its an "experimental" API after all. |
@cbuescher our comments crossed in the ether. yes, we can. |
Cool, so I will work in the plan above, introduce the new field in 5.x and make it the default in 6.0 with the optional "human" flag, changing documentation etc... there. |
After discussion with @javanna I added commits to change the human readable |
@polyfractal could you check if changing the human readable |
LGTM! It'll break the profiler UI since I'm a bad person and rely on that in one place for actual calculation (and not display). But it'll be trivial to support in a bwc manner...I can just apply I can make that fix quickly/easily after this merges. |
@polyfractal great, thanks. |
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.
left a couple of comments on docs, LGTM otherwise. I guess that 5.x will have its own separate PR.
|
||
As with other statistics apis, the Profile API supports human readable outputs for the time values. Those can be turned on by adding | ||
`?human=true` to the query string. In this case, in addition to the `"time_in_nanos"` field, the output contains the additional `"time"` | ||
field with the time in milliseconds, (e.g. `"time": "0.3919430000ms"`). |
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.
is that always in milliseconds?
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.
Yes, after the last change (using XContentHelper#timeValueField) this can be other units too, and the format will not be old the fixed 10-digits. I will update this accordingly.
@@ -276,7 +282,7 @@ the equivalent name in Elasticsearch. The `"description"` field displays the Lu | |||
is made available to help differentiating between parts of your query (e.g. both `"message:search"` and `"message:test"` | |||
are TermQuery's and would appear identical otherwise. | |||
|
|||
The `"time"` field shows that this query took ~15ms for the entire BooleanQuery to execute. The recorded time is inclusive | |||
The `"time_in_nanos"` field shows that this query took ~1.8ms for the entire BooleanQuery to execute. The recorded time is inclusive |
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.
it changed from 15ms to 1.8ms?
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 thing the 15ms was an error, the example above used to have "1.873811000ms" in its main node output, so I changed this accordingly. Maybe @polyfractal can confirm this as an existing error in the old docs.
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.
In all likelihood just a typo :) I generated those by running the query and c/p the results. But it changed a few times, so I probably just missed it during one of the changes
@clintongormley I wasn't sure if this change requires a section in the migrate.asciidocs, so I added one an will mark this as "breaking", since it changes the name of the field that we print by default in the profile response (please correct if thats wrong). I will add a warning to the 5.x documentation where we will print out both |
* master: (131 commits) Replace EngineClosedException with AlreadyClosedExcpetion (elastic#22631) Remove HttpServer and HttpServerAdapter in favor of a simple dispatch method (elastic#22636) move ignore parameter support from yaml test client to low level rest client (elastic#22637) Fix thread safety of Stempel's token filter factory (elastic#22610) Update profile.asciidoc Wrap rest httpclient with doPrivileged blocks (elastic#22603) Revert "Add a deprecation notice to shadow replicas (elastic#22025)" Revert "Don'y use `INDEX_SHARED_FS_ALLOW_RECOVERY_ON_ANY_NODE_SETTING` directly as it triggers (many) deprecation logging" Don'y use `INDEX_SHARED_FS_ALLOW_RECOVERY_ON_ANY_NODE_SETTING` directly as it triggers (many) deprecation logging Add a deprecation notice to shadow replicas (elastic#22025) [Docs] Fix section title in profile.asciidoc ProfileResult and CollectorResult should print machine readable timing information (elastic#22561) Add replica ops with version conflict to translog Replace custom Functional interface in ElasticsearchException with CheckedFunction Make RestChannelConsumer extend CheckedConsumer<RestChannel, Exception> replace ShardSearchRequest.FilterParser functional interface with CheckedFunction replace custom functional interface with CheckedFunction in percolate module [TEST] replace SizeFunction with Function<Integer, Integer> Expose CheckedFunction Expose logs base path ...
When trying to write parsing code for the SearchResponse
profile
section I ran into problems getting back the original time information, because bothProfileResult
andCollectorResult
currently print their time parameter in a human readable string format (e.g."time": "55.20315000ms"
). When trying to parse this back to a long value, for example to use in the planned high level java rest client, we can lose precision because of conversion and rounding issues. I was wondering if we should introduce an additional field (e.g.time_in_nanos
) to be able to get the raw value back and only print thetime
field for human consumption if requested with thehuman=true
flag.Another question would be if we can backport this in some way to 5.x, I'm not sure if the fact that the profile API is experimental means we can introduce additional fields in the response in 5.x. This PR is only a basis for discussion, maybe @polyfractal or @clintongormley have an opinion on this.