cockroach icon indicating copy to clipboard operation
cockroach copied to clipboard

sql: add memory budget info to node_statement_statistics

Open tbg opened this issue 8 years ago • 10 comments

The crdb_internal.node_statement_statistics table keeps a blueprint of each type of query encountered along with latency information.

It would be helpful to feed memory accounting information into this table as well. For each individually executed query, I think it's enough to hold on to the maximum budget used by the respective query (on the local node), and to track the average, variance, and perhaps max of that.

@knz does this seem straightforward to implement and/or do you have a better suggestion for where this should live? There's interest from an external contributor to tackle this.

tbg avatar Mar 26 '18 17:03 tbg

I think this needs to keep the high water mark in each monitor, which we haven't done so far. It's doable, but will need some benchmarking to evaluate the overhead.

Once the metric is in place, adding the stuff to node_statement_statistics is relatively trivial and well-contained, so indeed a good project for an external contributor.

knz avatar Mar 26 '18 22:03 knz

Thanks @knz! So two steps here, track the high water mark in each monitor and see whether that shows up in profiling (what would we profile?) and, pending success of that, do the crdb_internal plumbing.

cc @garvitjuniwal in case this is something you're interested in tackling on your end.

tbg avatar Mar 27 '18 01:03 tbg

I wasn't thinking about profiling but rather a straight before/after latency delta measurement.

knz avatar Mar 27 '18 05:03 knz

Should we consider whether or not we want to continue building out crdb_internal.node_statement_statistics? I think it may be time for us to consider making this more user facing, and include some toggles in case people don't want to track all of this profiling all the time?

dianasaur323 avatar Apr 02 '18 00:04 dianasaur323

@tschottdorf @knz I've started looking at this. I've some questions on what we want to measure, that you could help clarify.

  • Completed statements in-scope (at least for first cut) - this is in-line with existing latency measurements.
  • How do we measure distSQL statements? From reading, the latency measurements are computed only on the gateway node. What would be appropriate for memory usage? Some ideas: only consider memory usage on gateway node, aggregate mem usage across all nodes that participate in the distSQL flow, show breakdown of mem usage by node.

neeral avatar Apr 27 '18 19:04 neeral

cc @asubiotto who has been working on collecting this info for distsql queries. Alfonso perhaps you can provide some feedback / guidance?

knz avatar Apr 27 '18 19:04 knz

I recently put up a PR to collect this information in the hashJoiner: https://github.com/cockroachdb/cockroach/pull/24909, however, I'm going to go with a simpler approach of adding a high watermark to a memory account. This will allow us to collect the high water mark of memory used per processor participating in a distsql query.

I think it's important to note that this sort of statistic collection should not be on by default and thus should not appear in the node_statement_statistics table due to the cost of collecting this information. The general approach we discussed a couple of weeks ago that I still agree with is that node_statement_statistics should offer a high level view by default which can provide information for deeper dives into a query's execution by tracing it. These statistics could be collected by some form of EXPLAIN (DISTSQL,ANALYZE) that would annotate a visual query plan with processor statistics, aggregate node statistics, and general query statistics.

The nice thing that node_statement_statistics does is make this collection relatively automatic so I think that the step after the above is to allow the user to specify some sampling rate which would cause some queries to be traced and have some execution stats output to the table. I believe sampling is part of the opentracing specification so this would not be too much work.

I'm actively working on all this stuff except the last paragraph. Here is a tracking issue: https://github.com/cockroachdb/cockroach/issues/19476.

asubiotto avatar Apr 27 '18 20:04 asubiotto

Great @asubiotto. I'll wait for #19476.

neeral avatar Apr 27 '18 22:04 neeral

We have marked this issue as stale because it has been inactive for 18 months. If this issue is still relevant, removing the stale label or adding a comment will keep it active. Otherwise, we'll close it in 5 days to keep the issue queue tidy. Thank you for your contribution to CockroachDB!

github-actions[bot] avatar Jun 07 '21 02:06 github-actions[bot]

This is done.

jordanlewis avatar Jul 13 '21 15:07 jordanlewis