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

WriteBufferManager: allow slowing down writes based on total memory usage #114

Closed
isaac-io opened this issue Aug 4, 2022 · 5 comments · Fixed by #423
Closed

WriteBufferManager: allow slowing down writes based on total memory usage #114

isaac-io opened this issue Aug 4, 2022 · 5 comments · Fixed by #423
Assignees
Labels
enhancement New feature or request stabilization
Milestone

Comments

@isaac-io
Copy link
Contributor

isaac-io commented Aug 4, 2022

Currently the WriteBufferManager (WBM) does not allow slowing down writes in response to memory usage getting close to the prescribed limit. The only mechanism for letting flushes catch up is stopping writes completely by passing true for the allow_stall parameter of the WBM constructor. This can lead to oscillation between full write rate and complete stop, which is undesirable as it affects the latency of user writes.

Allow slowing down writes based on memory consumption by having the WBM signal the WriteController (WC) (there can be more than one) of the delay requirement. The delay requirement is stored in the WC as part of the Global Delay feature (#346). The same way a CF signals the WC that it has a delay requirement.

To enable this feature:

  1. allow_delays_and_stalls = true . in the ctor of WriteBufferManager (previously this flag was named allow_stalls)
  2. use_dynamic_delay = true .

The way the delay requirements are calculated is as follows:

The WBM reports a delay once its memory consumption passes a certain threshold from the quota. That threshold can be controlled by passing start_delay_percent to the ctor of the WBM. The default value is 70. Which means that the WBM will start issuing delay requests once the memory consumption of the WBM reaches 70% of its quota.
The delay is linear throughout the range from threshold to the max quota. The range from start of delay to the quota is divided into 99 steps of delay. (kMaxDelayedWriteFactor - 1). E.g. in the 1st step, the delay requirement will be 99/100 * max_delayed_write_rate() and the last step (when the memory almost reached the quota) will result in a delay requirement of 1/100 * max_delayed_write_rate(). max_delayed_write_rate() is the rate the user passed to delayed_write_rate (DBOptions) which can also be dynamically changed.

note:

The stall logic in the WBM is redundant since the WC already includes logic for stopping writes which can be reused.
For the first phase, #423 , keep using the stall logic in the WBM (ShouldStall() and WBMStallWrites()) and only add the mechanism for slowing down writes.

@udi-speedb
Copy link
Contributor

@isaac-io isaac-io linked a pull request Sep 21, 2022 that will close this issue
@isaac-io isaac-io added this to the v2.1.0 milestone Sep 21, 2022
@isaac-io isaac-io modified the milestones: v2.1.0, v2.2.0 Oct 26, 2022
@bosmatt bosmatt moved this to 🏗️ Working on it in Speedb Roadmap Nov 3, 2022
@udi-speedb
Copy link
Contributor

@Guyme The ticket as was actually completed but abandoned.
So, I suggest creating a new ticket once we actually know what we want to do here, and how it fits with other delayed write activities we work on.

@udi-speedb udi-speedb moved this from 🏗️ Working on it to 🔮 Future in Speedb Roadmap Dec 25, 2022
@Guyme Guyme modified the milestones: v2.2.0, V2.3.0 Dec 25, 2022
@Yuval-Ariel Yuval-Ariel moved this from 🔮 Future to 🏗️ Working on it in Speedb Roadmap Jan 8, 2023
@Guyme Guyme added enhancement New feature or request Working on it A feature request that is being actively worked on labels Jan 18, 2023
@Yuval-Ariel
Copy link
Contributor

@erez-speedb , plz make sure theres no degradation with branch - dirty-mem-connect-wbm-to-global-delay.
i'll run the performance scenario which shows benefit.

@erez-speedb
Copy link

Perf test passed, same performance and memory consumption as 2.4.1
All test were done with WF disabled.

@erez-speedb erez-speedb removed their assignment May 19, 2023
@Yuval-Ariel
Copy link
Contributor

Yuval-Ariel commented May 23, 2023

comparing main branch (e7e2de7) vs this branch (ba6a3de)
cmd:
./db_bench --compression_type=None -db=/data/ -num=200000000 -value_size=1000 -key_size=16 --delayed_write_rate=536870912 -report_interval_seconds=1 -max_write_buffer_number=4 -num_column_families=6 -histogram -max_background_compactions=8 -cache_size=8388608 -max_background_flushes=1 -bloom_bits=10 -benchmark_read_rate_limit=0 -benchmark_write_rate_limit=0 -report_file=fillrandom.csv --disable_wal=true --benchmarks=fillrandom,levelstats --db_write_buffer_size=1073741824 --allow_wbm_stalls=true --use_spdb_writes=false --initiate_wbm_flushes=false -write_buffer_size=134217728

results:
main and Dirty PR

quantitative - almost 50% improvement in stability:
ops/sec (std)
main - 89981
this branch - 49333

same Ops/sec (mean)
main - 255700
this branch - 245854

platform
azure standard_L16s_V3 instance
"cpu": "Intel(R) Xeon(R) Platinum 8370C CPU @ 2.80GHz",
"num_cpu": 16,
"memory": "128G"
"disk": single 1.8T NVME

@github-project-automation github-project-automation bot moved this from 🏗️ Working on it to 📖 Need your Opinion! in Speedb Roadmap May 26, 2023
@Yuval-Ariel Yuval-Ariel moved this from 📖 Need your Opinion! to ✅ Shipped in Speedb Roadmap May 28, 2023
@bosmatt bosmatt removed the Working on it A feature request that is being actively worked on label Oct 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request stabilization
Projects
Status: ✅ Shipped
7 participants