-
Notifications
You must be signed in to change notification settings - Fork 96
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
Make master outlive confdata out of shared memory errors #946
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DrDet
added
enhancement
New feature or request
runtime
Feature related to runtime
labels
Dec 3, 2023
tolk-vm
reviewed
Dec 4, 2023
DrDet
force-pushed
the
dvaksman/make-master-outlive-confdata-overflow
branch
4 times, most recently
from
December 9, 2023 13:41
22120c5
to
a263915
Compare
tolk-vm
reviewed
Dec 9, 2023
DrDet
force-pushed
the
dvaksman/make-master-outlive-confdata-overflow
branch
from
December 9, 2023 18:38
3db0400
to
7d80e52
Compare
tolk-vm
reviewed
Dec 9, 2023
DrDet
force-pushed
the
dvaksman/make-master-outlive-confdata-overflow
branch
from
December 9, 2023 18:43
7d80e52
to
b55eb00
Compare
tolk-vm
previously approved these changes
Dec 9, 2023
tolk-vm
approved these changes
Dec 9, 2023
DrDet
force-pushed
the
dvaksman/make-master-outlive-confdata-overflow
branch
from
December 9, 2023 19:25
d4b4515
to
8e97de6
Compare
troy4eg
approved these changes
Dec 9, 2023
DedAzaMarks
pushed a commit
to DedAzaMarks/kphp
that referenced
this pull request
Dec 13, 2023
- events throttling approach with soft/hard OOM mode - external allocation heuristic checks to prevent OOM - timeout for reading binlog on updates to prevent master freezing - new emergency option for blacklisting confdata events - extend confdata monitoring in StatsHouse and Graphana Co-authored-by: Aleksandr Kirsanov <unserialize.alias@gmail.com>
mt-omarov
pushed a commit
to mt-omarov/kphp
that referenced
this pull request
Feb 26, 2024
- events throttling approach with soft/hard OOM mode - external allocation heuristic checks to prevent OOM - timeout for reading binlog on updates to prevent master freezing - new emergency option for blacklisting confdata events - extend confdata monitoring in StatsHouse and Graphana Co-authored-by: Aleksandr Kirsanov <unserialize.alias@gmail.com>
mt-omarov
pushed a commit
to mt-omarov/kphp
that referenced
this pull request
Feb 26, 2024
- events throttling approach with soft/hard OOM mode - external allocation heuristic checks to prevent OOM - timeout for reading binlog on updates to prevent master freezing - new emergency option for blacklisting confdata events - extend confdata monitoring in StatsHouse and Graphana Co-authored-by: Aleksandr Kirsanov <unserialize.alias@gmail.com>
mt-omarov
pushed a commit
to mt-omarov/kphp
that referenced
this pull request
Feb 26, 2024
- events throttling approach with soft/hard OOM mode - external allocation heuristic checks to prevent OOM - timeout for reading binlog on updates to prevent master freezing - new emergency option for blacklisting confdata events - extend confdata monitoring in StatsHouse and Graphana Co-authored-by: Aleksandr Kirsanov <unserialize.alias@gmail.com>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Here're two new approaches:
Events throttling
To prevent OOM errors on confdata overflows we start to throttle events, when too little shared memory left. There're two modes:
If server enters any OOM modes, it can't go back out of it. Manual server restart is needed for that.
External preventive allocation heuristic checks
Before any action, that internally invokes allocations, we explicitly check that allocator has enough memory for that.
To achieve this we need to somehow calculate upper-bound for memory that will be required by the action in each particular case.
There're two 'kinds' of allocations:
array<mixed>::mutate_if_shared()
, etc..). It's not too complicated, because it's our own code and we can calculate it easily.std::map<>
which uses our shared memory allocator. To handle this we will use common sense, some knowledge about search trees internal structure and compile time upper-bound for tree node size from our allocator:kphp/runtime/memory_resource/resource_allocator.h
Line 48 in d685b6c
New stats for confdata
This PR also includes writing confdata metrics to statshouse:
kphp_confdata_memory
kphp_confdata_events
kphp_confdata_sections_by_count
kphp_confdata_update_fails
New option for blacklisting confdata events
--confdata-force-ignore-keys-prefix
— an emergency option, e.g. 'highload.vid*', to forcibly drop keys from snapshot/binlog; may be used multiple times.Timeouts for reading binlog
To prevent master hanging in
master_cron()
, a timeout for reading a next binlog chunk is added, controlled by--confdata-update-timeout
. Every second (every cron iteration) we allow binlog reader to consume next event no more than timeout seconds. That allows master to perform other work.Note, that an option for reading binlog in a separate thread can't be implemented, since the master process is also fundamentally single-threaded (lots of globals, global allocator, global allocator switches between heap/shared memory, etc.).