-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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
rpc,sql: propagate pprof labels for SQL queries to KV #86012
Comments
Would we always annotate contexts with profiler labels containing statement data? Even if that node wasn't currently being profiled? Seeing as how we might be grabbing a CPU profile on a remote node where the statement didn't originate and would be relying on propagation to have happened. We should evaluate the overhead, if any, if always annotating. #85948 describes some techniques we use in KV to make this more alloc efficient. |
That's a good point. If the originator of the work sits elsewhere, we need to tell it to put the labels. We could also try to always add labels but it involves a longer performance fight and I tend to think that fleet-wide profiling is a good enough workaround. |
I would really like for us to build per-statement distributed CPU profiling. In a past life this has been invaluable in understanding slow queries, and driving system performance improvements, in a way that tracing was inadequate for. It is very hard to understand what code paths are responsible for a slow query, in a production environment, since there are other queries running concurrently (this can be non-trivial even in complex benchmarks where many queries are running) and it is hard to even know which nodes a query will touch. See https://github.com/cockroachlabs/support/issues/2033#issuecomment-1409654095 of an example where traces did not help us understand the root cause of the slowness. This would roughly work as follows:
|
Thanks for the heads up Kevin! cc @nkodali for your awareness |
DistSQL flow requests carry their initiating SQL in the request. So, to enable this for DistSQL, it should be straightforward: we can run |
Update: #82464 solved the missing DistSQL label propagation in 22.2, but there's still a need to propagate the pprof labels into the KV layer as per the original issue. |
That's great! This is a significant improvement over the status quo. Are we aware of cases where this wouldn't have been enough? I think if we had a node which had lots of leases for write-heavy ranges, but the writes originated from a remote gateway, we would still be flying blind (if there were lots of reads, it's likely though not guaranteed that there'd be a local DistSQL leaf, which would have the tags). |
Yeah, there are still plenty of cases where we'd need the KV tag propagation, like the cases you mention as well as point reads (don't use DistSQL), index joins, zigzag joins, lookup joins, etc. My comment about "solving" was just about the DistSQL but it wasn't entirely clear, I've edited it to prevent confusion. |
Summarizing the current state. The motivating example: two nodes A, B where A drives all of the load (i.e. is SQL gateway) for B, and we want to understand which query/user/app drives the load. Currently, if we profile on B, we don't get any labels (note that we don't necessarily know which node A is; there might be 100s of nodes in this cluster). Scope of this issue:
Related ideas (please discuss them on their respective tracking issues):
Footnotes |
I hadn't! Great, that's the missing piece. We could always do this "more holistically" but this is fine, let's close this issue since all follow-up items are tracked separately. |
Is your feature request related to a problem? Please describe.
While CPU profiling, we usually generate pprof labels that could help pinning work to queries. This is all pretty half-baked (I think as is it misses lots of queries due to the code path it annotates), but it has been helpful in some investigations.
cockroach/pkg/sql/conn_executor_exec.go
Lines 138 to 146 in 477d1e8
However, these profiler labels don't propagate across RPC boundaries, and so for any query that fans out, only the local portion will have the labels (since there is a direct goroutine descendancy relationship between the goroutine we annotated and the goroutines that do the work). In particular, if the expensive portion of the processing happens on a remote node, it will not be annotated. The investigator may then be mislead into thinking that another query that is local (but maybe not expensive) is driving the load, which would could lead to a lengthy detour.
Describe the solution you'd like
Propagate pprof labels across RPC boundaries. The right way to do this is likely gRPC interceptors. I wrote them as part of a past prototype, #60508, so some code exists but isn't merged.
Ideally while revisiting this we also move the label annotation to a more useful place, noting what was done (but not merged) in #85977 as I realized there that we weren't capturing all classes of statememts. If we are to use this feature, it can't have big blind spots; wrong information is worse than no information in this case.
Describe alternatives you've considered
We could decide that we don't wish to leverage profiler labels to find offending queries, and instead rely on something else, for example #85977. However, pprof labels seem like a good stopgap measure and I think most of the work is already done.
Additional context
Jira issue: CRDB-18526
The text was updated successfully, but these errors were encountered: