Skip to content

Commit

Permalink
gRPC: use gzip level-2 compression by default (tikv#12791)
Browse files Browse the repository at this point in the history
ref tikv#12929

add initial arguments for gzip compression:
gzip_compression_level: represent gzip compression level, the origin gzip compression level is 6 and hardcoding;
compression_lower_bound: this represent gzip will compress the data only larger than this

Signed-off-by: zkkxu <goodbodyguard@163.com>
Signed-off-by: xufei <xufei02@pingcap.com>
  • Loading branch information
zkkxu authored Jun 29, 2022
1 parent 6bd1d45 commit d356be1
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 6 deletions.
8 changes: 4 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ futures-executor = "0.3.1"
futures-timer = "3.0"
futures-util = { version = "0.3.1", default-features = false, features = ["io", "async-await"] }
getset = "0.1"
grpcio = { version = "0.10", default-features = false, features = ["openssl-vendored", "protobuf-codec"] }
grpcio = { version = "0.10.3", default-features = false, features = ["openssl-vendored", "protobuf-codec", "nightly"] }
grpcio-health = { version = "0.10", default-features = false, features = ["protobuf-codec"] }
hex = "0.4"
http = "0"
Expand Down
8 changes: 8 additions & 0 deletions src/server/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ const DEFAULT_GRPC_CONCURRENT_STREAM: i32 = 1024;
const DEFAULT_GRPC_RAFT_CONN_NUM: usize = 1;
const DEFAULT_GRPC_MEMORY_POOL_QUOTA: u64 = isize::MAX as u64;
const DEFAULT_GRPC_STREAM_INITIAL_WINDOW_SIZE: u64 = 2 * 1024 * 1024;
const DEFAULT_GRPC_GZIP_COMPRESSION_LEVEL: usize = 2;
const DEFAULT_GRPC_MIN_MESSAGE_SIZE_TO_COMPRESS: usize = 4096;

// Number of rows in each chunk.
const DEFAULT_ENDPOINT_BATCH_ROW_LIMIT: usize = 64;
Expand Down Expand Up @@ -98,6 +100,10 @@ pub struct Config {
#[online_config(skip)]
pub grpc_compression_type: GrpcCompressionType,
#[online_config(skip)]
pub grpc_gzip_compression_level: usize,
#[online_config(skip)]
pub grpc_min_message_size_to_compress: usize,
#[online_config(skip)]
pub grpc_concurrency: usize,
#[online_config(skip)]
pub grpc_concurrent_stream: i32,
Expand Down Expand Up @@ -213,6 +219,8 @@ impl Default for Config {
raft_client_queue_size: 8192,
raft_msg_max_batch_size: 128,
grpc_compression_type: GrpcCompressionType::None,
grpc_gzip_compression_level: DEFAULT_GRPC_GZIP_COMPRESSION_LEVEL,
grpc_min_message_size_to_compress: DEFAULT_GRPC_MIN_MESSAGE_SIZE_TO_COMPRESS,
grpc_concurrency: DEFAULT_GRPC_CONCURRENCY,
grpc_concurrent_stream: DEFAULT_GRPC_CONCURRENT_STREAM,
grpc_raft_conn_num: DEFAULT_GRPC_RAFT_CONN_NUM,
Expand Down
2 changes: 2 additions & 0 deletions src/server/raft_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -692,6 +692,8 @@ where
.keepalive_time(cfg.grpc_keepalive_time.0)
.keepalive_timeout(cfg.grpc_keepalive_timeout.0)
.default_compression_algorithm(cfg.grpc_compression_algorithm())
.default_gzip_compression_level(cfg.grpc_gzip_compression_level)
.default_grpc_min_message_size_to_compress(cfg.grpc_min_message_size_to_compress)
// hack: so it's different args, grpc will always create a new connection.
.raw_cfg_int(
CString::new("random id").unwrap(),
Expand Down
4 changes: 3 additions & 1 deletion src/server/snap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,9 @@ pub fn send_snap(
.stream_initial_window_size(cfg.grpc_stream_initial_window_size.0 as i32)
.keepalive_time(cfg.grpc_keepalive_time.0)
.keepalive_timeout(cfg.grpc_keepalive_timeout.0)
.default_compression_algorithm(cfg.grpc_compression_algorithm());
.default_compression_algorithm(cfg.grpc_compression_algorithm())
.default_gzip_compression_level(cfg.grpc_gzip_compression_level)
.default_grpc_min_message_size_to_compress(cfg.grpc_min_message_size_to_compress);

let channel = security_mgr.connect(cb, addr);
let client = TikvClient::new(channel);
Expand Down
2 changes: 2 additions & 0 deletions tests/integrations/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ fn test_serde_custom_tikv_config() {
labels: HashMap::from_iter([("a".to_owned(), "b".to_owned())]),
advertise_addr: "example.com:443".to_owned(),
status_addr: "example.com:443".to_owned(),
grpc_gzip_compression_level: 2,
grpc_min_message_size_to_compress: 4096,
advertise_status_addr: "example.com:443".to_owned(),
status_thread_pool_size: 1,
max_grpc_send_msg_len: 6 * (1 << 20),
Expand Down

0 comments on commit d356be1

Please sign in to comment.