Skip to content

sql: set up foundations for per-application statistics#14092

Merged
knz merged 1 commit intocockroachdb:masterfrom
knz:app-stats
Mar 14, 2017
Merged

sql: set up foundations for per-application statistics#14092
knz merged 1 commit intocockroachdb:masterfrom
knz:app-stats

Conversation

@knz
Copy link
Copy Markdown
Contributor

@knz knz commented Mar 11, 2017

This patch instruments the SQL executor with a data structure aimed at
collecting per-application statistics, then exposes this data
structure via a new virtual table crdb_internal.app_stats.

An "application" is identified by setting the session variable
"application_name".

Each application has a separate instance of a new struct appStats.
The pointer to this struct is cached in the session object and updated
only when the application name is modified.

However since there can be multiple sessions updating a single
appStats instance concurrently, its fields must be properly
synchronized.

The separation of statistics per application is motivated both by a
user-expressed interest in separating statistics per application, and
by a performance concern -- reducing contention on the mutex on the
map holding all the appStats instances.

Needed for #13968.

(This PR is based off #14089 and will be rebased once #14089 merges.)


This change is Reviewable

@knz knz requested review from dt and petermattis March 11, 2017 00:50
@knz knz force-pushed the app-stats branch 2 times, most recently from 81bd32c to 827fe32 Compare March 11, 2017 01:20
@petermattis
Copy link
Copy Markdown
Collaborator

:lgtm:


Reviewed 3 of 3 files at r1, 5 of 5 files at r2.
Review status: 7 of 10 files reviewed at latest revision, 2 unresolved discussions, all commit checks successful.


pkg/sql/app_stats.go, line 50 at r2 (raw file):

}

func (a *appStats) registerQuery() {

I'm not fond of the name registerQuery as that makes me think you're registering some callback or something like that. Also, this is being called for each SQL statement, not just queries. How about recordStatement? And the call site also knows whether the statement was successful or an error, so perhaps this should be recordStatement(err error).


pkg/sql/crdb_internal.go, line 235 at r3 (raw file):

CREATE TABLE crdb_internal.app_stats (
  APPLICATION_NAME STRING,
  QUERY_COUNT      INT

STATEMENT_COUNT? Also, I thought we used lowercase for column names.


Comments from Reviewable

@knz
Copy link
Copy Markdown
Contributor Author

knz commented Mar 13, 2017

Review status: 7 of 10 files reviewed at latest revision, 2 unresolved discussions, all commit checks successful.


pkg/sql/app_stats.go, line 50 at r2 (raw file):

Previously, petermattis (Peter Mattis) wrote…

I'm not fond of the name registerQuery as that makes me think you're registering some callback or something like that. Also, this is being called for each SQL statement, not just queries. How about recordStatement? And the call site also knows whether the statement was successful or an error, so perhaps this should be recordStatement(err error).

Done.


pkg/sql/crdb_internal.go, line 235 at r3 (raw file):

Previously, petermattis (Peter Mattis) wrote…

STATEMENT_COUNT? Also, I thought we used lowercase for column names.

Done (we don't use lowercase for virtual tables, for some reason).


Comments from Reviewable

This patch instruments the SQL executor with a data structure aimed at
collecting per-application statistics and exposes it via a new
virtual table `crdb_internal.app_stats`.

An "application" is identified by setting the session variable
"application_name".

Each application has a separate instance of a new struct `appStats`.
The pointer to this struct is cached in the session object and updated
only when the application name is modified.

However since there can be multiple sessions updating a single
`appStats` instance concurrently, its fields must be properly
synchronized.

The separation of statistics per application is motivated both by a
user-expressed interest in separating statistics per application, and
by a performance concern -- reducing contention on the mutex on the
map holding all the appStats instances.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants