Skip to content

Commit 1838119

Browse files
Chun Nifacebook-github-bot
authored andcommitted
Add different compression choice
Summary: when using clone to copy data in innodb instance and turn compression on. The speed is about 10 times slower than with compression off. The default compression algorithm used is zlib. Try to use other compression algorithm to tune the performance. Differential Revision: D46406587 fbshipit-source-id: 55f748c
1 parent 2f11e1f commit 1838119

File tree

7 files changed

+110
-0
lines changed

7 files changed

+110
-0
lines changed

include/mysql/components/services/clone_protocol_service.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ struct mysql_clone_ssl_context {
6161

6262
/** Enable network compression. */
6363
bool m_enable_compression;
64+
const char *m_compression_algorithm;
65+
uint m_compression_level;
6466
NET_SERVER *m_server_extn;
6567
};
6668

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
INSTALL PLUGIN clone SONAME 'CLONE_PLUGIN';
2+
SET GLOBAL clone_enable_compression = ON;
3+
SET GLOBAL clone_compression_algorithm = ZSTD;
4+
SET GLOBAL clone_zstd_compression_level = 8;
5+
SET GLOBAL clone_autotune_concurrency = OFF;
6+
SET GLOBAL clone_max_concurrency = 8;
7+
SET GLOBAL clone_valid_donor_list = 'HOST:PORT';
8+
CLONE INSTANCE FROM USER@HOST:PORT IDENTIFIED BY '' DATA DIRECTORY = 'CLONE_DATADIR';
9+
select ID, STATE, ERROR_NO from performance_schema.clone_status;
10+
ID STATE ERROR_NO
11+
1 Completed 0
12+
select ID, STAGE, STATE from performance_schema.clone_progress;
13+
ID STAGE STATE
14+
1 DROP DATA Completed
15+
1 FILE COPY Completed
16+
1 PAGE COPY Completed
17+
1 SST COPY Completed
18+
1 REDO COPY Completed
19+
1 FILE SYNC Completed
20+
1 RESTART Not Started
21+
1 RECOVERY Not Started
22+
# restart
23+
UNINSTALL PLUGIN clone;
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
--source include/have_rocksdb.inc
2+
3+
--let $HOST = 127.0.0.1
4+
--let $PORT =`select @@port`
5+
--let $USER = root
6+
--let remote_clone = 1
7+
8+
--source ../../clone/include/clone_connection_begin.inc
9+
--let $CLONE_DATADIR = $MYSQL_TMP_DIR/data_new
10+
11+
# Install Clone Plugin
12+
--replace_result $CLONE_PLUGIN CLONE_PLUGIN
13+
--eval INSTALL PLUGIN clone SONAME '$CLONE_PLUGIN'
14+
15+
--connection clone_conn_1
16+
SET GLOBAL clone_enable_compression = ON;
17+
SET GLOBAL clone_compression_algorithm = ZSTD;
18+
SET GLOBAL clone_zstd_compression_level = 8;
19+
--source ../../clone/include/clone_command.inc
20+
21+
--force-rmdir $CLONE_DATADIR
22+
23+
--let restart_parameters=
24+
--source include/restart_mysqld.inc
25+
26+
# Clean up
27+
UNINSTALL PLUGIN clone;
28+
--source ../../clone/include/clone_connection_end.inc

plugin/clone/include/clone.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,10 @@ extern uint clone_max_io_bandwidth;
9090
/** Clone system variable: If network compression is enabled */
9191
extern bool clone_enable_compression;
9292

93+
extern ulong clone_compression_algorithm;
94+
95+
extern uint clone_zstd_compression_level;
96+
9397
/** Clone system variable: SSL private key */
9498
extern char *clone_client_ssl_private_key;
9599

@@ -111,6 +115,11 @@ const uint CLONE_MIN_BLOCK = 1024 * 1024;
111115
/** Minimum network packet. Safe margin for meta information */
112116
const uint CLONE_MIN_NET_BLOCK = 2 * CLONE_MIN_BLOCK;
113117

118+
/** Clone supported compression libs */
119+
#define CLONE_COMPRESSION_ALGORITHM_COUNT_MAX 3
120+
extern const char
121+
*clone_compression_lib_names[CLONE_COMPRESSION_ALGORITHM_COUNT_MAX];
122+
114123
/* Namespace for all clone data types */
115124
namespace myclone {
116125

plugin/clone/src/clone_client.cc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -896,6 +896,13 @@ int Client::connect_remote(bool is_restart, bool use_aux) {
896896
mysql_clone_ssl_context ssl_context;
897897

898898
ssl_context.m_enable_compression = clone_enable_compression;
899+
900+
if (ssl_context.m_enable_compression) {
901+
ssl_context.m_compression_algorithm =
902+
clone_compression_lib_names[clone_compression_algorithm];
903+
ssl_context.m_compression_level = clone_zstd_compression_level;
904+
}
905+
899906
ssl_context.m_server_extn =
900907
ssl_context.m_enable_compression ? &m_conn_server_extn : nullptr;
901908
ssl_context.m_ssl_mode = m_share->m_ssl_mode;

plugin/clone/src/clone_plugin.cc

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,10 @@ uint clone_max_io_bandwidth;
7070
/** Clone system variable: If network compression is enabled */
7171
bool clone_enable_compression;
7272

73+
ulong clone_compression_algorithm;
74+
75+
uint clone_zstd_compression_level;
76+
7377
/** Clone system variable: valid list of donor addresses. */
7478
static char *clone_valid_donor_list;
7579

@@ -636,6 +640,28 @@ static MYSQL_SYSVAR_BOOL(enable_compression, clone_enable_compression,
636640
"If compression is done at network", nullptr, nullptr,
637641
false); /* Disable compression by default */
638642

643+
enum enum_clone_compression_algorithm { ZLIB = 0, ZSTD };
644+
const char *clone_compression_lib_names[] = {COMPRESSION_ALGORITHM_ZLIB,
645+
COMPRESSION_ALGORITHM_ZSTD, NullS};
646+
647+
static TYPELIB clone_compression_algorithms_typelib = {
648+
array_elements(clone_compression_lib_names) - 1,
649+
"clone_compression_algorithms_typelib", clone_compression_lib_names,
650+
nullptr};
651+
652+
static MYSQL_SYSVAR_ENUM(compression_algorithm, clone_compression_algorithm,
653+
PLUGIN_VAR_OPCMDARG | PLUGIN_VAR_MEMALLOC,
654+
"compression algorithm used in clone", nullptr,
655+
nullptr, enum_clone_compression_algorithm::ZSTD,
656+
&clone_compression_algorithms_typelib);
657+
658+
static MYSQL_SYSVAR_UINT(zstd_compression_level, clone_zstd_compression_level,
659+
PLUGIN_VAR_NOCMDARG, "zstd compression level", nullptr,
660+
nullptr, 3, /* Default */
661+
1, /* Minimum */
662+
10, /* Maximum */
663+
1);
664+
639665
/** List of valid donor addresses allowed to clone from. */
640666
static MYSQL_SYSVAR_STR(valid_donor_list, clone_valid_donor_list,
641667
PLUGIN_VAR_OPCMDARG | PLUGIN_VAR_MEMALLOC,
@@ -705,6 +731,8 @@ static SYS_VAR *clone_system_variables[] = {
705731
MYSQL_SYSVAR(ssl_cert),
706732
MYSQL_SYSVAR(ssl_ca),
707733
MYSQL_SYSVAR(donor_timeout_after_network_failure),
734+
MYSQL_SYSVAR(compression_algorithm),
735+
MYSQL_SYSVAR(zstd_compression_level),
708736
nullptr};
709737

710738
/** Declare clone plugin */

sql/server_component/clone_protocol_service.cc

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,12 @@ DEFINE_METHOD(MYSQL *, mysql_clone_connect,
394394
/* Enable compression. */
395395
if (ssl_ctx->m_enable_compression) {
396396
mysql_options(mysql, MYSQL_OPT_COMPRESS, nullptr);
397+
if (ssl_ctx->m_compression_algorithm) {
398+
mysql_options(mysql, MYSQL_OPT_COMPRESSION_ALGORITHMS,
399+
ssl_ctx->m_compression_algorithm);
400+
mysql_options(mysql, MYSQL_OPT_ZSTD_COMPRESSION_LEVEL,
401+
&ssl_ctx->m_compression_level);
402+
}
397403
mysql_extension_set_server_extn(mysql, ssl_ctx->m_server_extn);
398404
}
399405

@@ -539,6 +545,13 @@ DEFINE_METHOD(int, mysql_clone_get_response,
539545
*net_length = 0;
540546
*length = my_net_read(net);
541547

548+
/* The ZSTD object has been updated to include the newly created decompressor
549+
context. Include the change in the net extension so that the resource can
550+
be released when de-init compress context. */
551+
if (net->compress) {
552+
static_cast<NET_SERVER *>(saved_extn)->compress_ctx =
553+
server_extn.compress_ctx;
554+
}
542555
net->extension = saved_extn;
543556
server_extn.compress_ctx.algorithm = MYSQL_UNCOMPRESSED;
544557

0 commit comments

Comments
 (0)