Skip to content

Commit 643b62d

Browse files
authored
Merge pull request #4764 from sysown/v3.0_compression
Add MySQL compression level variable and change default to compression level 3 (v3.0)
2 parents 261b529 + ed30c5f commit 643b62d

23 files changed

+278
-94
lines changed

include/MySQL_Thread.h

+1
Original file line numberDiff line numberDiff line change
@@ -470,6 +470,7 @@ class MySQL_Threads_Handler
470470
bool parse_failure_logs_digest;
471471
bool default_reconnect;
472472
bool have_compress;
473+
int protocol_compression_level;
473474
bool have_ssl;
474475
bool multiplexing;
475476
// bool stmt_multiplexing;

include/proxysql_structs.h

+2
Original file line numberDiff line numberDiff line change
@@ -1168,6 +1168,7 @@ __thread int mysql_thread___poll_timeout;
11681168
__thread int mysql_thread___poll_timeout_on_failure;
11691169
__thread bool mysql_thread___connection_warming;
11701170
__thread bool mysql_thread___have_compress;
1171+
__thread int mysql_thread___protocol_compression_level;
11711172
__thread bool mysql_thread___have_ssl;
11721173
__thread bool mysql_thread___multiplexing;
11731174
__thread bool mysql_thread___log_unhealthy_connections;
@@ -1464,6 +1465,7 @@ extern __thread int mysql_thread___poll_timeout;
14641465
extern __thread int mysql_thread___poll_timeout_on_failure;
14651466
extern __thread bool mysql_thread___connection_warming;
14661467
extern __thread bool mysql_thread___have_compress;
1468+
extern __thread int mysql_thread___protocol_compression_level;
14671469
extern __thread bool mysql_thread___have_ssl;
14681470
extern __thread bool mysql_thread___multiplexing;
14691471
extern __thread bool mysql_thread___log_unhealthy_connections;

lib/MySQL_Thread.cpp

+6
Original file line numberDiff line numberDiff line change
@@ -504,6 +504,7 @@ static char * mysql_thread_variables_names[]= {
504504
(char *)"handle_warnings",
505505
(char *)"evaluate_replication_lag_on_servers_load",
506506
(char *)"proxy_protocol_networks",
507+
(char *)"protocol_compression_level",
507508
NULL
508509
};
509510

@@ -1137,6 +1138,7 @@ MySQL_Threads_Handler::MySQL_Threads_Handler() {
11371138
variables.enable_load_data_local_infile=false;
11381139
variables.log_mysql_warnings_enabled=false;
11391140
variables.data_packets_history_size=0;
1141+
variables.protocol_compression_level=3;
11401142
// status variables
11411143
status_variables.mirror_sessions_current=0;
11421144
__global_MySQL_Thread_Variables_version=1;
@@ -2268,6 +2270,7 @@ char ** MySQL_Threads_Handler::get_variables_list() {
22682270
VariablesPointers_int["client_host_error_counts"] = make_tuple(&variables.client_host_error_counts, 0, 1024*1024, false);
22692271
VariablesPointers_int["handle_warnings"] = make_tuple(&variables.handle_warnings, 0, 1, false);
22702272
VariablesPointers_int["evaluate_replication_lag_on_servers_load"] = make_tuple(&variables.evaluate_replication_lag_on_servers_load, 0, 1, false);
2273+
VariablesPointers_int["protocol_compression_level"] = make_tuple(&variables.protocol_compression_level, -1, 9, false);
22712274

22722275
// logs
22732276
VariablesPointers_int["auditlog_filesize"] = make_tuple(&variables.auditlog_filesize, 1024*1024, 1*1024*1024*1024, false);
@@ -4178,6 +4181,7 @@ void MySQL_Thread::refresh_variables() {
41784181
REFRESH_VARIABLE_INT(poll_timeout);
41794182
REFRESH_VARIABLE_INT(poll_timeout_on_failure);
41804183
REFRESH_VARIABLE_BOOL(have_compress);
4184+
REFRESH_VARIABLE_INT(protocol_compression_level);
41814185
REFRESH_VARIABLE_BOOL(have_ssl);
41824186
REFRESH_VARIABLE_BOOL(multiplexing);
41834187
REFRESH_VARIABLE_BOOL(log_unhealthy_connections);
@@ -4262,6 +4266,8 @@ MySQL_Thread::MySQL_Thread() {
42624266
mysql_thread___ssl_p2s_crl=NULL;
42634267
mysql_thread___ssl_p2s_crlpath=NULL;
42644268

4269+
mysql_thread___protocol_compression_level=3;
4270+
42654271
last_maintenance_time=0;
42664272
last_move_to_idle_thread_time=0;
42674273
maintenance_loop=true;

lib/mysql_data_stream.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -1234,7 +1234,7 @@ void MySQL_Data_Stream::generate_compressed_packet() {
12341234
total_size+=p2.size;
12351235
l_free(p2.size,p2.ptr);
12361236
}
1237-
int rc=compress(dest, &destLen, source, sourceLen);
1237+
int rc=compress2(dest, &destLen, source, sourceLen, mysql_thread___protocol_compression_level);
12381238
assert(rc==Z_OK);
12391239
l_free(total_size, source);
12401240
queueOUT.pkt.size=destLen+7;
@@ -1266,9 +1266,9 @@ void MySQL_Data_Stream::generate_compressed_packet() {
12661266
dest1=(Bytef *)malloc(destLen1+7);
12671267
destLen2=len2*120/100+12;
12681268
dest2=(Bytef *)malloc(destLen2+7);
1269-
rc=compress(dest1+7, &destLen1, (const unsigned char *)p2.ptr, len1);
1269+
rc=compress2(dest1+7, &destLen1, (const unsigned char *)p2.ptr, len1, mysql_thread___protocol_compression_level);
12701270
assert(rc==Z_OK);
1271-
rc=compress(dest2+7, &destLen2, (const unsigned char *)p2.ptr+len1, len2);
1271+
rc=compress2(dest2+7, &destLen2, (const unsigned char *)p2.ptr+len1, len2, mysql_thread___protocol_compression_level);
12721272
assert(rc==Z_OK);
12731273

12741274
hdr.pkt_length=destLen1;

microbench/PR1977_bench.cpp

-7
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,6 @@ inline int fastrand() {
99
return (g_seed>>16)&0x7FFF;
1010
}
1111

12-
inline unsigned long long monotonic_time() {
13-
struct timespec ts;
14-
clock_gettime(CLOCK_MONOTONIC, &ts);
15-
return (((unsigned long long) ts.tv_sec) * 1000000) + (ts.tv_nsec / 1000);
16-
}
17-
18-
1912
#define NSRV 24
2013
#define NLOOP 10000000
2114

test/tap/groups/groups.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -180,5 +180,6 @@
180180
"eof_fast_forward-t" : [ "default", "mysql-auto_increment_delay_multiplex=0", "mysql-multiplexing=false", "mysql-query_digests=0", "mysql-query_digests_keep_comment=1" ],
181181
"eof_mixed_flags_queries-t" : [ "default", "mysql-auto_increment_delay_multiplex=0", "mysql-multiplexing=false", "mysql-query_digests=0", "mysql-query_digests_keep_comment=1" ],
182182
"eof_packet_mixed_queries-t" : [ "default", "mysql-auto_increment_delay_multiplex=0", "mysql-multiplexing=false", "mysql-query_digests=0", "mysql-query_digests_keep_comment=1" ],
183-
"ok_packet_mixed_queries-t" : [ "default", "mysql-auto_increment_delay_multiplex=0", "mysql-multiplexing=false", "mysql-query_digests=0", "mysql-query_digests_keep_comment=1" ]
183+
"ok_packet_mixed_queries-t" : [ "default", "mysql-auto_increment_delay_multiplex=0", "mysql-multiplexing=false", "mysql-query_digests=0", "mysql-query_digests_keep_comment=1" ],
184+
"mysql-protocol_compression_level-t" : [ "default", "mysql-auto_increment_delay_multiplex=0", "mysql-multiplexing=false", "mysql-query_digests=0", "mysql-query_digests_keep_comment=1" ]
184185
}

test/tap/tap/utils.cpp

+6
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,12 @@ int create_table_test_sbtest1(int num_rows, MYSQL *mysql) {
399399
return add_more_rows_test_sbtest1(num_rows, mysql);
400400
}
401401

402+
unsigned long long monotonic_time() {
403+
struct timespec ts;
404+
clock_gettime(CLOCK_MONOTONIC, &ts);
405+
return (((unsigned long long) ts.tv_sec) * 1000000) + (ts.tv_nsec / 1000);
406+
}
407+
402408
int create_table_test_sqlite_sbtest1(int num_rows, MYSQL *mysql) {
403409
MYSQL_QUERY(mysql, "DROP TABLE IF EXISTS sbtest1");
404410
MYSQL_QUERY(mysql, "CREATE TABLE IF NOT EXISTS sbtest1 (id INTEGER PRIMARY KEY AUTOINCREMENT, `k` int(10) NOT NULL DEFAULT '0', `c` char(120) NOT NULL DEFAULT '', `pad` char(60) NOT NULL DEFAULT '')");

test/tap/tap/utils.h

+2
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,8 @@ int create_table_test_sbtest1(int num_rows, MYSQL *mysql);
144144
int create_table_test_sqlite_sbtest1(int num_rows, MYSQL *mysql); // as above, but for SQLite3 server
145145
int add_more_rows_test_sbtest1(int num_rows, MYSQL *mysql, bool sqlite=false);
146146

147+
unsigned long long monotonic_time();
148+
147149
using mysql_res_row = std::vector<std::string>;
148150

149151
/**

test/tap/tests/multiple_prepared_statements-t.cpp

-6
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,6 @@ inline int fastrand() {
3636
return (g_seed>>16)&0x7FFF;
3737
}
3838

39-
inline unsigned long long monotonic_time() {
40-
struct timespec ts;
41-
clock_gettime(CLOCK_MONOTONIC, &ts);
42-
return (((unsigned long long) ts.tv_sec) * 1000000) + (ts.tv_nsec / 1000);
43-
}
44-
4539
#define NTHREADS 5
4640
#define NCONNS 6
4741
#define NPREP 15000

test/tap/tests/mysql-init_connect-1-t.cpp

-6
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,6 @@ It uses 2 valid init_connect, and 2 invalid ones that trigger PMC-10003.
1717
It also sets a value that causes a syntax error
1818
*/
1919

20-
inline unsigned long long monotonic_time() {
21-
struct timespec ts;
22-
clock_gettime(CLOCK_MONOTONIC, &ts);
23-
return (((unsigned long long) ts.tv_sec) * 1000000) + (ts.tv_nsec / 1000);
24-
}
25-
2620
int main(int argc, char** argv) {
2721
CommandLine cl;
2822

test/tap/tests/mysql-init_connect-2-t.cpp

-6
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,6 @@ mysql-init_connect
2121
We configure both hostgroup 0 and 1
2222
*/
2323

24-
inline unsigned long long monotonic_time() {
25-
struct timespec ts;
26-
clock_gettime(CLOCK_MONOTONIC, &ts);
27-
return (((unsigned long long) ts.tv_sec) * 1000000) + (ts.tv_nsec / 1000);
28-
}
29-
3024
int main(int argc, char** argv) {
3125
CommandLine cl;
3226

test/tap/tests/mysql-last_insert_id-t.cpp

-6
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,6 @@
1111
#include "command_line.h"
1212
#include "utils.h"
1313

14-
inline unsigned long long monotonic_time() {
15-
struct timespec ts;
16-
clock_gettime(CLOCK_MONOTONIC, &ts);
17-
return (((unsigned long long) ts.tv_sec) * 1000000) + (ts.tv_nsec / 1000);
18-
}
19-
2014

2115
std::string queries[5] = {
2216
"SELECT LAST_INSERT_ID() LIMIT 1",

0 commit comments

Comments
 (0)