Skip to content
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

YSQL: Cache sys catalog read request on local t-server side #10821

Closed
d-uspenskiy opened this issue Dec 9, 2021 · 4 comments
Closed

YSQL: Cache sys catalog read request on local t-server side #10821

d-uspenskiy opened this issue Dec 9, 2021 · 4 comments
Assignees
Labels
area/ysql Yugabyte SQL (YSQL) kind/enhancement This is an enhancement of an existing feature priority/critical Critical issue

Comments

@d-uspenskiy
Copy link
Contributor

d-uspenskiy commented Dec 9, 2021

Jira Link: DB-3251
After landing the #9936 it will be possible to cache sys catalog read request on a local t-server side to improve postgres catalog cache refresh process.

@d-uspenskiy d-uspenskiy added the kind/enhancement This is an enhancement of an existing feature label Dec 9, 2021
@d-uspenskiy d-uspenskiy self-assigned this Dec 9, 2021
@patriknw
Copy link
Contributor

patriknw commented Apr 8, 2022

Related to #11997

pkj415 pushed a commit to pkj415/yugabyte-db that referenced this issue Jul 19, 2022
…er side [WIP]

Summary: TBD

Test Plan: Jenkins

Reviewers: sergei, mihnea, jason

Subscribers: yql, bogdan

Differential Revision: https://phabricator.dev.yugabyte.com/D17824
@tverona1 tverona1 added the area/ysql Yugabyte SQL (YSQL) label Aug 22, 2022
@yugabyte-ci yugabyte-ci added the priority/medium Medium priority issue label Aug 22, 2022
@yugabyte-ci yugabyte-ci added priority/critical Critical issue and removed priority/medium Medium priority issue labels Nov 1, 2022
d-uspenskiy added a commit that referenced this issue Nov 22, 2022
Summary:
On cache refresh YSQL sends RPC to a master which reads multiple system tables.
Nowadays they are:
- pg_database
- pg_class
- pg_attribute
- pg_opclass
- pg_am
- pg_amproc
- pg_index
- pg_rewrite
- pg_attrdef
- pg_constraint
- pg_partitioned_table
- pg_type
- pg_namespace
- pg_authid

All active postgres connections send the same RPC to master on cache refresh. As long as YSQL sends RPC via local t-server proxy it is reasonable to cache the response on this RPC on local t-server and reuse data from cache instead of resending same RPC to a master over and over again (i.e. 1 request per each active connection).

`PgResponseCache` is the `LRUCache` which stored in the `PgClientService`.
Key in this cache is a text representation of RPC request. But special field in this request must be nullified (cleared out) first. Because the value of this field is unique for each request and it doesn't affect the response. This field is `PgsqlReadRequestPB::stmt_id`.

Also cacheable request must have additional field which will contains info about system catalog version. Because in case of catalog changes it is necessary to send new request to a master instead of using data from the local t-server cache as this data is outdated.

**Note:**
Only request which preloads the sys catalog is cacheable now. Requests which loads sys catalog records on-demand are not cacheable. The necessity of caching these requests will be estimated in future.

Test Plan:
Jenkins

```
./yb_build.sh --gtest_filter PgCatalogPerfTest.ResponseCacheEfficiency
```

Reviewers: mihnea, jason, myang, sergei

Reviewed By: myang, sergei

Subscribers: plee, smishra, yql, bogdan

Differential Revision: https://phabricator.dev.yugabyte.com/D17824
@d-uspenskiy d-uspenskiy moved this to Done in YQL-beta Nov 22, 2022
@sharkberto
Copy link

If there is still backport work pending for stable releases, can we leave this open and tag with 2.14 / 2.16 Backport Required @tverona1 @d-uspenskiy I understand this is not yet ported to stable for those asking for tserver catalog caching

@yugabyte-ci yugabyte-ci reopened this Dec 6, 2022
@yugabyte-ci yugabyte-ci assigned sharkberto and unassigned d-uspenskiy Dec 6, 2022
d-uspenskiy added a commit that referenced this issue Dec 6, 2022
… t-server side

Summary:
On cache refresh YSQL sends RPC to a master which reads multiple system tables.
Nowadays they are:
- pg_database
- pg_class
- pg_attribute
- pg_opclass
- pg_am
- pg_amproc
- pg_index
- pg_rewrite
- pg_attrdef
- pg_constraint
- pg_partitioned_table
- pg_type
- pg_namespace
- pg_authid

All active postgres connections send the same RPC to master on cache refresh. As long as YSQL sends RPC via local t-server proxy it is reasonable to cache the response on this RPC on local t-server and reuse data from cache instead of resending same RPC to a master over and over again (i.e. 1 request per each active connection).

`PgResponseCache` is the `LRUCache` which stored in the `PgClientService`.
Key in this cache is a text representation of RPC request. But special field in this request must be nullified (cleared out) first. Because the value of this field is unique for each request and it doesn't affect the response. This field is `PgsqlReadRequestPB::stmt_id`.

Also cacheable request must have additional field which will contains info about system catalog version. Because in case of catalog changes it is necessary to send new request to a master instead of using data from the local t-server cache as this data is outdated.

**Note:**
Only request which preloads the sys catalog is cacheable now. Requests which loads sys catalog records on-demand are not cacheable. The necessity of caching these requests will be estimated in future.

Original commit: 7672a48 / D17824

Test Plan:
Jenkins: rebase: 2.16

```
./yb_build.sh --gtest_filter PgCatalogPerfTest.ResponseCacheEfficiency
```

Reviewers: jason, sergei, mihnea, myang

Reviewed By: myang

Subscribers: smishra, plee, mihnea, yql, bogdan

Differential Revision: https://phabricator.dev.yugabyte.com/D21452
@sharkberto sharkberto removed their assignment Dec 6, 2022
jayant07-yb pushed a commit to jayant07-yb/yugabyte-db that referenced this issue Dec 7, 2022
…er side

Summary:
On cache refresh YSQL sends RPC to a master which reads multiple system tables.
Nowadays they are:
- pg_database
- pg_class
- pg_attribute
- pg_opclass
- pg_am
- pg_amproc
- pg_index
- pg_rewrite
- pg_attrdef
- pg_constraint
- pg_partitioned_table
- pg_type
- pg_namespace
- pg_authid

All active postgres connections send the same RPC to master on cache refresh. As long as YSQL sends RPC via local t-server proxy it is reasonable to cache the response on this RPC on local t-server and reuse data from cache instead of resending same RPC to a master over and over again (i.e. 1 request per each active connection).

`PgResponseCache` is the `LRUCache` which stored in the `PgClientService`.
Key in this cache is a text representation of RPC request. But special field in this request must be nullified (cleared out) first. Because the value of this field is unique for each request and it doesn't affect the response. This field is `PgsqlReadRequestPB::stmt_id`.

Also cacheable request must have additional field which will contains info about system catalog version. Because in case of catalog changes it is necessary to send new request to a master instead of using data from the local t-server cache as this data is outdated.

**Note:**
Only request which preloads the sys catalog is cacheable now. Requests which loads sys catalog records on-demand are not cacheable. The necessity of caching these requests will be estimated in future.

Test Plan:
Jenkins

```
./yb_build.sh --gtest_filter PgCatalogPerfTest.ResponseCacheEfficiency
```

Reviewers: mihnea, jason, myang, sergei

Reviewed By: myang, sergei

Subscribers: plee, smishra, yql, bogdan

Differential Revision: https://phabricator.dev.yugabyte.com/D17824
@jameshartig
Copy link
Contributor

@sharkberto is this still planning on being backported to 2.14?

@sharkberto
Copy link

@jameshartig Not planning to backport to 2.14 - Sorry for any confusion

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/ysql Yugabyte SQL (YSQL) kind/enhancement This is an enhancement of an existing feature priority/critical Critical issue
Projects
Status: Done
Development

No branches or pull requests

6 participants