Skip to content

Improve ui settings performance#84513

Merged
mshustov merged 9 commits intoelastic:masterfrom
mshustov:improve-ui-settings-perf
Dec 2, 2020
Merged

Improve ui settings performance#84513
mshustov merged 9 commits intoelastic:masterfrom
mshustov:improve-ui-settings-perf

Conversation

@mshustov
Copy link
Copy Markdown
Contributor

@mshustov mshustov commented Nov 30, 2020

Summary

Closes #82218
Adds caching layer with TTL to uiSettings client.
Every SOC used in UiSettings is scoped to a KibanaRequest, thus the uiSettings cache cannot be shared between users.

Response time 95th ptc on 7.10 branch

scenario before after
Global Information 4636 1510
login 2060 1268
discover 4299 1258
Discover query 2 4385 1778
Discover query 3 4308 1419
query indexPattern 2075 637
query da...ard list 1914 599
query panels list 1842 780
query vi...izations 1927 737
query search & map 1633 690
query ti...ies data 6532 2681
query gauge data 4661 1419
canvas workpads 2074 695
interpreter demo 1558 433
load workpad 5824 1818
query ca...timelion 4262 1338
query canvas aggs 1 2072 1039
query canvas aggs 2 1815 435

50th ptc

scenario before after
Global Information 1281 526
login 1212 792
discover 2215 764
Discover query 2 2441 846
Discover query 3 2077 832
query indexPattern 890 344
query da...ard list 997 337
query panels list 1018 363
query vi...izations 1108 380
query search & map 1036 385
query ti...ies data 4695 1461
query gauge data 2848 743
canvas workpads 1018 316
interpreter demo 697 217
load workpad 2990 1087
query ca...timelion 2183 752
query canvas aggs 1 984 496
query canvas aggs 2 458 199

75th ptc

scenario before after
Global Information 2349 862
login 1462 991
discover 3294 1108
Discover query 2 3404 921
Discover query 3 3503 1004
query indexPattern 1425 427
query da...ard list 1374 413
query panels list 1285 434
query vi...izations 1488 514
query search & map 1306 502
query ti...ies data 5800 1864
query gauge data 3833 998
canvas workpads 1331 417
interpreter demo 958 314
load workpad 4240 1410
query ca...timelion 3104 895
query canvas aggs 1 1417 629
query canvas aggs 2 847 270

Checklist

@mshustov mshustov added Team:Core Platform Core services: plugins, logging, config, saved objects, http, ES client, i18n, etc t// performance release_note:skip Skip the PR/issue when compiling release notes v7.11.0 v7.10.1 labels Nov 30, 2020
@mshustov mshustov marked this pull request as ready for review November 30, 2020 18:01
@mshustov mshustov requested a review from a team as a code owner November 30, 2020 18:01
@elasticmachine
Copy link
Copy Markdown
Contributor

Pinging @elastic/kibana-core (Team:Core)

@mshustov mshustov marked this pull request as draft November 30, 2020 18:03
@mshustov mshustov marked this pull request as ready for review November 30, 2020 18:42
@mshustov mshustov requested a review from legrego November 30, 2020 18:44
Copy link
Copy Markdown
Contributor

@pgayvallet pgayvallet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. The perf improvement for 95pct looks amazing. Do you have the numbers for 50 and 75pct just FMI?

Comment thread src/core/server/ui_settings/cache.test.ts Outdated
Comment thread src/core/server/ui_settings/ui_settings_client.ts
Copy link
Copy Markdown
Member

@legrego legrego left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks!

* under the License.
*/
const oneSec = 1000;
const defMaxAge = 5 * oneSec;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A side question for my info: How was a default of 5 seconds decided? I couldn't find a reference to how the decision was made in #82218

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I chose a value that is slightly longer than Global Information: 4636ms before the fix.

Comment thread src/core/server/ui_settings/ui_settings_client.ts Outdated
@mshustov
Copy link
Copy Markdown
Contributor Author

mshustov commented Dec 1, 2020

@pgayvallet added numbers for 50th & 75th percentiles

@kobelb
Copy link
Copy Markdown
Contributor

kobelb commented Dec 1, 2020

Do we have other options to address the UI settings performance besides caching? For HA deployments of Kibana, we'll potentially have a stale cache entry for five seconds. Almost none of our automated tests run against a HA deployment of Kibana, so our automated tests won't catch the side-effects this introduces. At a minimum, we shouldn't be backporting this to be released in a patch version because this change is inherently "unsafe" with our current level of testing.

@mshustov mshustov removed the v7.10.1 label Dec 2, 2020
@mshustov
Copy link
Copy Markdown
Contributor Author

mshustov commented Dec 2, 2020

Do we have other options to address the UI settings performance besides caching?

Yeah, it’s listed as a tradeoff in the parent issue
IMO the current solution is the most practical one. Other ideas that I have (like migrate all the usage places from single read operation to readAllUiSettingForMyPlugins) won’t scale for the already existing number of plugins or have the same race-conditions problems (like batching requests). I’m open to other ideas, though.

We can reduce cache TTL from 5s to 1s to minimize race condition probability for the current implementation. WDYT? @kobelb

At a minimum, we shouldn't be backporting this to be released in a patch version because this change is inherently "unsafe" with our current level of testing.

Got it, removed the 7.10.1 label

@kibanamachine
Copy link
Copy Markdown
Contributor

💚 Build Succeeded

Metrics [docs]

Distributable file count

id before after diff
default 43201 43202 +1
oss 22584 22585 +1

History

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

@kobelb
Copy link
Copy Markdown
Contributor

kobelb commented Dec 2, 2020

😳 I think I previously skipped over a very important part of the issue description:

Every SOC used in UiSettings is scoped to a KibanaRequest, thus the uiSettings cache cannot be shared between users.

Is my understanding correct that this cache is only per-request with a max TTL of 5 seconds? If so, that seems much safer to me, and would be equivalent to loading all of the UI Settings when a HTTP request is initiated and using them throughout the HTTP request. If that's correct, this all LGTM, and apologies for raising the initial concern.

@mshustov
Copy link
Copy Markdown
Contributor Author

mshustov commented Dec 2, 2020

Is my understanding correct that this cache is only per-request with a max TTL of 5 seconds?

Yes. That's how it works.

@mshustov mshustov merged commit 88359b7 into elastic:master Dec 2, 2020
@mshustov mshustov deleted the improve-ui-settings-perf branch December 2, 2020 19:15
mshustov added a commit to mshustov/kibana that referenced this pull request Dec 2, 2020
* remove unused parameter in "read" function

* add cache for uiSettings client

* add tests for ui_settings client caching

* address comments

* do not mutate ui_settings_client cache
mshustov added a commit that referenced this pull request Dec 2, 2020
* remove unused parameter in "read" function

* add cache for uiSettings client

* add tests for ui_settings client caching

* address comments

* do not mutate ui_settings_client cache
stratoula added a commit that referenced this pull request Apr 22, 2026
## Summary

This is a performance enhancement to the UI Settings service. It
introduces a space-aware, process-wide cache layer for the settings
saved object. It applies to `.get('setting-name')` lookups on all UI
settings clients.

### Justification

When a dashboard loads, search-related settings need to be consulted
before each search request. That can mean 20+ saved object lookups (see
#84923) which are each happening
in different requests, so the [per-request
cache](#84513) doesn't cover it.

### Caching approach

`NamespacedCache` is the class that handles caching. It stores both
resolved settings objects and in-flight requests to deduplicate read
operations (`getUserDefined`).

The server-side cache is freshened in three scenarios
- A setting is changed (`setMany`)
- A browser requests `index.html`
- A settings lookup occurs after the TTL has expired

The browser UI settings client is guaranteed to get fresh settings page
loads (this preserves the existing UX for changing settings).

In a multi-node scenario, the node performing a setting change gets fast
consistency. Other nodes get eventual consistency.

### Checklist

- [x] [Unit or functional
tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)
were updated or added to match the most common scenarios

---------

Co-authored-by: Stratou <efstratia.kalafateli@elastic.co>
SoniaSanzV pushed a commit to SoniaSanzV/kibana that referenced this pull request Apr 27, 2026
…c#262618)

## Summary

This is a performance enhancement to the UI Settings service. It
introduces a space-aware, process-wide cache layer for the settings
saved object. It applies to `.get('setting-name')` lookups on all UI
settings clients.

### Justification

When a dashboard loads, search-related settings need to be consulted
before each search request. That can mean 20+ saved object lookups (see
elastic#84923) which are each happening
in different requests, so the [per-request
cache](elastic#84513) doesn't cover it.

### Caching approach

`NamespacedCache` is the class that handles caching. It stores both
resolved settings objects and in-flight requests to deduplicate read
operations (`getUserDefined`).

The server-side cache is freshened in three scenarios
- A setting is changed (`setMany`)
- A browser requests `index.html`
- A settings lookup occurs after the TTL has expired

The browser UI settings client is guaranteed to get fresh settings page
loads (this preserves the existing UX for changing settings).

In a multi-node scenario, the node performing a setting change gets fast
consistency. Other nodes get eventual consistency.

### Checklist

- [x] [Unit or functional
tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)
were updated or added to match the most common scenarios

---------

Co-authored-by: Stratou <efstratia.kalafateli@elastic.co>
patrykkopycinski pushed a commit to patrykkopycinski/kibana that referenced this pull request May 6, 2026
* remove unused parameter in "read" function

* add cache for uiSettings client

* add tests for ui_settings client caching

* address comments

* do not mutate ui_settings_client cache
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

performance release_note:skip Skip the PR/issue when compiling release notes Team:Core Platform Core services: plugins, logging, config, saved objects, http, ES client, i18n, etc t// v7.11.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Do not overwhelm Elasticsearch with UiSettings requests

7 participants