forked from tikv/tikv
-
Notifications
You must be signed in to change notification settings - Fork 9
Limit proxy's memory from TiFlash's side (#408) #425
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
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
cd6ecf5
Limit proxy's memory from TiFlash's side (#408)
CalvinNeo a0a5234
locked
CalvinNeo 1ea6a81
fix
CalvinNeo db1ab72
a
CalvinNeo 4d67ee4
a
CalvinNeo 30463cc
a
CalvinNeo 4f12224
a
CalvinNeo ecb6114
fix
CalvinNeo f57bd87
change ratio
CalvinNeo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,6 +8,7 @@ use proxy_server::{ | |
| proxy::{gen_proxy_config, gen_tikv_config}, | ||
| setup::overwrite_config_with_cmd_args, | ||
| }; | ||
| use tikv::config::MEMORY_USAGE_LIMIT_RATE; | ||
| use tikv_util::sys::SysQuota; | ||
|
|
||
| use crate::proxy::*; | ||
|
|
@@ -122,6 +123,11 @@ fn test_config_proxy_default_no_config_item() { | |
| std::cmp::min(256, (cpu_num * 8.0) as usize) | ||
| ); | ||
| assert_eq!(config.server.status_thread_pool_size, 2); | ||
|
|
||
| assert_eq!(config.raft_store.evict_cache_on_memory_ratio, 0.1); | ||
| assert_eq!(config.memory_usage_high_water, 0.9); | ||
| // Seems #244 doesn't goes into this branch. | ||
| assert_eq!(config.server.reject_messages_on_memory_ratio, 0.2); | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Differ from master |
||
| } | ||
|
|
||
| /// We test if the engine-label is set properly. | ||
|
|
@@ -200,3 +206,149 @@ apply-low-priority-pool-size = 41 | |
| config.raft_store.apply_batch_system.low_priority_pool_size | ||
| ); | ||
| } | ||
|
|
||
| #[test] | ||
| fn test_memory_limit_overwrite() { | ||
| let app = App::new("RaftStore Proxy") | ||
| .arg( | ||
| Arg::with_name("memory-limit-size") | ||
| .long("memory-limit-size") | ||
| .help("Used as the maximum memory we can consume, in bytes") | ||
| .takes_value(true), | ||
| ) | ||
| .arg( | ||
| Arg::with_name("memory-limit-ratio") | ||
| .long("memory-limit-ratio") | ||
| .help("Used as the maximum memory we can consume, in percentage") | ||
| .takes_value(true), | ||
| ); | ||
|
|
||
| let bootstrap = |args: Vec<&str>| { | ||
| let mut v: Vec<String> = vec![]; | ||
| let matches = app.clone().get_matches_from(args); | ||
| let mut config = gen_tikv_config(&None, false, &mut v); | ||
| let mut proxy_config = gen_proxy_config(&None, false, &mut v); | ||
| proxy_config.raftdb.defaultcf.block_cache_size = ReadableSize(0); | ||
| proxy_config.rocksdb.defaultcf.block_cache_size = ReadableSize(0); | ||
| proxy_config.rocksdb.lockcf.block_cache_size = ReadableSize(0); | ||
| proxy_config.rocksdb.writecf.block_cache_size = ReadableSize(0); | ||
| overwrite_config_with_cmd_args(&mut config, &mut proxy_config, &matches); | ||
| address_proxy_config(&mut config, &proxy_config); | ||
| config.compatible_adjust(); | ||
| config | ||
| }; | ||
|
|
||
| { | ||
| let args = vec![ | ||
| "test_memory_limit_overwrite1", | ||
| "--memory-limit-size", | ||
| "12345", | ||
| ]; | ||
| let mut config = bootstrap(args); | ||
| assert!(config.validate().is_ok()); | ||
| assert_eq!(config.memory_usage_limit, Some(ReadableSize(12345))); | ||
| } | ||
|
|
||
| { | ||
| let args = vec![ | ||
| "test_memory_limit_overwrite2", | ||
| "--memory-limit-size", | ||
| "12345", | ||
| "--memory-limit-ratio", | ||
| "0.9", | ||
| ]; | ||
| let mut config = bootstrap(args); | ||
| assert!(config.validate().is_ok()); | ||
| assert_eq!(config.memory_usage_limit, Some(ReadableSize(12345))); | ||
| } | ||
|
|
||
| let total = SysQuota::memory_limit_in_bytes(); | ||
| { | ||
| let args = vec![ | ||
| "test_memory_limit_overwrite3", | ||
| "--memory-limit-ratio", | ||
| "0.800000", | ||
| ]; | ||
| let mut config = bootstrap(args); | ||
| assert!(config.validate().is_ok()); | ||
| let limit = (total as f64 * 0.8) as u64; | ||
| assert_eq!(config.memory_usage_limit, Some(ReadableSize(limit))); | ||
| } | ||
|
|
||
| let default_limit = (total as f64 * MEMORY_USAGE_LIMIT_RATE) as u64; | ||
| { | ||
| let args = vec![ | ||
| "test_memory_limit_overwrite4", | ||
| "--memory-limit-ratio", | ||
| "7.9", | ||
| ]; | ||
| let mut config = bootstrap(args); | ||
| assert!(config.validate().is_ok()); | ||
| assert_eq!(config.memory_usage_limit, Some(ReadableSize(default_limit))); | ||
| } | ||
|
|
||
| { | ||
| let args = vec![ | ||
| "test_memory_limit_overwrite5", | ||
| "--memory-limit-ratio", | ||
| "'-0.9'", | ||
| ]; | ||
| let mut config = bootstrap(args); | ||
| assert!(config.validate().is_ok()); | ||
| assert_eq!(config.memory_usage_limit, Some(ReadableSize(default_limit))); | ||
| } | ||
|
|
||
| { | ||
| let args = vec!["test_memory_limit_overwrite6"]; | ||
| let mut config = bootstrap(args); | ||
| assert!(config.validate().is_ok()); | ||
| assert_eq!(config.memory_usage_limit, Some(ReadableSize(default_limit))); | ||
| } | ||
|
|
||
| let bootstrap2 = |args: Vec<&str>| { | ||
| let mut v: Vec<String> = vec![]; | ||
| let matches = app.clone().get_matches_from(args); | ||
| let mut file = tempfile::NamedTempFile::new().unwrap(); | ||
| write!( | ||
| file, | ||
| " | ||
| memory-usage-limit = 42 | ||
| " | ||
| ) | ||
| .unwrap(); | ||
| let path = file.path(); | ||
| let cpath = Some(path.as_os_str()); | ||
| let mut config = gen_tikv_config(&cpath, false, &mut v); | ||
| let mut proxy_config = gen_proxy_config(&cpath, false, &mut v); | ||
| proxy_config.raftdb.defaultcf.block_cache_size = ReadableSize(0); | ||
| proxy_config.rocksdb.defaultcf.block_cache_size = ReadableSize(0); | ||
| proxy_config.rocksdb.lockcf.block_cache_size = ReadableSize(0); | ||
| proxy_config.rocksdb.writecf.block_cache_size = ReadableSize(0); | ||
| overwrite_config_with_cmd_args(&mut config, &mut proxy_config, &matches); | ||
| address_proxy_config(&mut config, &proxy_config); | ||
| config.compatible_adjust(); | ||
| config | ||
| }; | ||
|
|
||
| { | ||
| let args = vec![ | ||
| "test_memory_limit_nooverwrite3", | ||
| "--memory-limit-ratio", | ||
| "0.800000", | ||
| ]; | ||
| let mut config = bootstrap2(args); | ||
| assert!(config.validate().is_ok()); | ||
| assert_eq!(config.memory_usage_limit, Some(ReadableSize(42))); | ||
| } | ||
|
|
||
| { | ||
| let args = vec![ | ||
| "test_memory_limit_nooverwrite1", | ||
| "--memory-limit-size", | ||
| "12345", | ||
| ]; | ||
| let mut config = bootstrap2(args); | ||
| assert!(config.validate().is_ok()); | ||
| assert_eq!(config.memory_usage_limit, Some(ReadableSize(42))); | ||
| } | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is currently in 0.1 in tikv release-6.5. We just modify here, so even if we merged upstream later, there is no difference.