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

safekeeper: add eviction_min_resident to stop evictions thrashing #8335

Merged
merged 5 commits into from
Jul 10, 2024

Conversation

jcsp
Copy link
Contributor

@jcsp jcsp commented Jul 10, 2024

Problem

  • The condition for eviction is not time-based: it is possible for a timeline to be restored in response to a client, that client times out, and then as soon as the timeline is restored it is immediately evicted again.
  • There is no delay on eviction at startup of the safekeeper, so when it starts up and sees many idle timelines, it does many evictions which will likely be immediately restored when someone uses the timeline.

Summary of changes

  • Add eviction_min_resident parameter, and use it in ready_for_eviction to avoid evictions if the timeline has been resident for less than this period.
  • This also implicitly delays evictions at startup for eviction_min_resident
  • Set this to a very low number for the existing eviction test, which expects immediate eviction.

The default period is 10 minutes. The general reasoning for that is that in the worst case where we thrash ~10k timelines on one safekeeper, downloading 16MB for each one, we should set a period that would not overwhelm the node's bandwidth.

Checklist before requesting a review

  • I have performed a self-review of my code.
  • If it is a core feature, I have added thorough tests.
  • Do we need to implement analytics? if so did you add the relevant metrics to the dashboard?
  • If this PR requires public announcement, mark it with /release-notes label and add several sentences in this section.

Checklist before merging

  • Do not forget to reformat commit message to not include the above checklist

@jcsp jcsp added c/storage/safekeeper Component: storage: safekeeper t/bug Issue Type: Bug labels Jul 10, 2024
Copy link

github-actions bot commented Jul 10, 2024

3042 tests run: 2927 passed, 0 failed, 115 skipped (full report)


Flaky tests (1)

Postgres 14

  • test_isolation[None]: debug

Code coverage* (full report)

  • functions: 32.5% (6931 of 21297 functions)
  • lines: 49.9% (54511 of 109162 lines)

* collected from Rust tests only


The comment gets automatically updated with the latest test results
d261b08 at 2024-07-10T18:48:08.982Z :recycle:

@jcsp jcsp requested a review from arssher July 10, 2024 11:43
@jcsp jcsp marked this pull request as ready for review July 10, 2024 11:43
@jcsp jcsp requested a review from a team as a code owner July 10, 2024 11:43
Copy link
Contributor

@arssher arssher left a comment

Choose a reason for hiding this comment

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

I'd suggest to

  • Explain in comments to the option that it shouldn't be normally needed because partial_backup_timeout already prevents eviction its value seconds/minutes after the write. However, it guards against eviction-read only access-quick deeviction pattern. I haven't seen yet evidence we do it though.
  • Have the same default value for partial_backup_timeout and eviction_min_resident.

@jcsp
Copy link
Contributor Author

jcsp commented Jul 10, 2024

Explain in comments to the option that it shouldn't be normally needed because partial_backup_timeout already prevents eviction its value seconds/minutes after the write. However, it guards against eviction-read only access-quick deeviction pattern. I haven't seen yet evidence we do it though.

When we saw that happen today, I think it was because clients had triggered the un-eviction, but then timed out before writing anything, so they left the timeline in the state where it was eligible for eviction (nothing pending upload)

Have the same default value for partial_backup_timeout and eviction_min_resident.

Makes sense, changed.

@jcsp jcsp enabled auto-merge (squash) July 10, 2024 17:51
@arssher
Copy link
Contributor

arssher commented Jul 10, 2024

When we saw that happen today, I think it was because clients had triggered the un-eviction, but then timed out before writing anything, so they left the timeline in the state where it was eligible for eviction (nothing pending upload)

Probably, but I doubt it, see
https://neondb.slack.com/archives/C033RQ5SPDH/p1720626053871819?thread_ts=1720601531.744029&cid=C033RQ5SPDH
I think postgres has very little chance to start up without writing anything.

@jcsp jcsp merged commit 24f8133 into main Jul 10, 2024
61 checks passed
@jcsp jcsp deleted the jcsp/safekeeper-eviction-min-resident branch July 10, 2024 18:38
@jcsp jcsp mentioned this pull request Jul 10, 2024
5 tasks
jcsp added a commit that referenced this pull request Jul 11, 2024
## Problem

Follow up to #8335, to improve
observability of how many evict/restores we are doing.

## Summary of changes

- Add `safekeeper_eviction_events_started_total` and
`safekeeper_eviction_events_completed_total`, with a "kind" label of
evict or restore. This gives us rates, and also ability to calculate how
many are in progress.
- Generalize SafekeeperMetrics test type to use the same helpers as
pageserver, and enable querying any metric.
- Read the new metrics at the end of the eviction test.
skyzh pushed a commit that referenced this pull request Jul 15, 2024
)

## Problem

- The condition for eviction is not time-based: it is possible for a
timeline to be restored in response to a client, that client times out,
and then as soon as the timeline is restored it is immediately evicted
again.
- There is no delay on eviction at startup of the safekeeper, so when it
starts up and sees many idle timelines, it does many evictions which
will likely be immediately restored when someone uses the timeline.

## Summary of changes

- Add `eviction_min_resident` parameter, and use it in
`ready_for_eviction` to avoid evictions if the timeline has been
resident for less than this period.
- This also implicitly delays evictions at startup for
`eviction_min_resident`
- Set this to a very low number for the existing eviction test, which
expects immediate eviction.

The default period is 15 minutes. The general reasoning for that is that
in the worst case where we thrash ~10k timelines on one safekeeper,
downloading 16MB for each one, we should set a period that would not
overwhelm the node's bandwidth.
skyzh pushed a commit that referenced this pull request Jul 15, 2024
## Problem

Follow up to #8335, to improve
observability of how many evict/restores we are doing.

## Summary of changes

- Add `safekeeper_eviction_events_started_total` and
`safekeeper_eviction_events_completed_total`, with a "kind" label of
evict or restore. This gives us rates, and also ability to calculate how
many are in progress.
- Generalize SafekeeperMetrics test type to use the same helpers as
pageserver, and enable querying any metric.
- Read the new metrics at the end of the eviction test.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c/storage/safekeeper Component: storage: safekeeper t/bug Issue Type: Bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants