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

Add MySQL compression level variable and change default to compression level 3 (v3.0) #4764

Open
wants to merge 12 commits into
base: v3.0
Choose a base branch
from
Open
1 change: 1 addition & 0 deletions include/MySQL_Thread.h
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,7 @@ class MySQL_Threads_Handler
bool parse_failure_logs_digest;
bool default_reconnect;
bool have_compress;
int protocol_compression_level;
bool have_ssl;
bool multiplexing;
// bool stmt_multiplexing;
Expand Down
2 changes: 2 additions & 0 deletions include/proxysql_structs.h
Original file line number Diff line number Diff line change
Expand Up @@ -1168,6 +1168,7 @@ __thread int mysql_thread___poll_timeout;
__thread int mysql_thread___poll_timeout_on_failure;
__thread bool mysql_thread___connection_warming;
__thread bool mysql_thread___have_compress;
__thread int mysql_thread___protocol_compression_level;
__thread bool mysql_thread___have_ssl;
__thread bool mysql_thread___multiplexing;
__thread bool mysql_thread___log_unhealthy_connections;
Expand Down Expand Up @@ -1464,6 +1465,7 @@ extern __thread int mysql_thread___poll_timeout;
extern __thread int mysql_thread___poll_timeout_on_failure;
extern __thread bool mysql_thread___connection_warming;
extern __thread bool mysql_thread___have_compress;
extern __thread int mysql_thread___protocol_compression_level;
extern __thread bool mysql_thread___have_ssl;
extern __thread bool mysql_thread___multiplexing;
extern __thread bool mysql_thread___log_unhealthy_connections;
Expand Down
6 changes: 6 additions & 0 deletions lib/MySQL_Thread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -504,6 +504,7 @@ static char * mysql_thread_variables_names[]= {
(char *)"handle_warnings",
(char *)"evaluate_replication_lag_on_servers_load",
(char *)"proxy_protocol_networks",
(char *)"protocol_compression_level",
NULL
};

Expand Down Expand Up @@ -1137,6 +1138,7 @@ MySQL_Threads_Handler::MySQL_Threads_Handler() {
variables.enable_load_data_local_infile=false;
variables.log_mysql_warnings_enabled=false;
variables.data_packets_history_size=0;
variables.protocol_compression_level=3;
// status variables
status_variables.mirror_sessions_current=0;
__global_MySQL_Thread_Variables_version=1;
Expand Down Expand Up @@ -2268,6 +2270,7 @@ char ** MySQL_Threads_Handler::get_variables_list() {
VariablesPointers_int["client_host_error_counts"] = make_tuple(&variables.client_host_error_counts, 0, 1024*1024, false);
VariablesPointers_int["handle_warnings"] = make_tuple(&variables.handle_warnings, 0, 1, false);
VariablesPointers_int["evaluate_replication_lag_on_servers_load"] = make_tuple(&variables.evaluate_replication_lag_on_servers_load, 0, 1, false);
VariablesPointers_int["protocol_compression_level"] = make_tuple(&variables.protocol_compression_level, 0, 9, false);
yashwantsahu20 marked this conversation as resolved.
Show resolved Hide resolved

// logs
VariablesPointers_int["auditlog_filesize"] = make_tuple(&variables.auditlog_filesize, 1024*1024, 1*1024*1024*1024, false);
Expand Down Expand Up @@ -4178,6 +4181,7 @@ void MySQL_Thread::refresh_variables() {
REFRESH_VARIABLE_INT(poll_timeout);
REFRESH_VARIABLE_INT(poll_timeout_on_failure);
REFRESH_VARIABLE_BOOL(have_compress);
REFRESH_VARIABLE_INT(protocol_compression_level);
REFRESH_VARIABLE_BOOL(have_ssl);
REFRESH_VARIABLE_BOOL(multiplexing);
REFRESH_VARIABLE_BOOL(log_unhealthy_connections);
Expand Down Expand Up @@ -4262,6 +4266,8 @@ MySQL_Thread::MySQL_Thread() {
mysql_thread___ssl_p2s_crl=NULL;
mysql_thread___ssl_p2s_crlpath=NULL;

mysql_thread___protocol_compression_level=3;

last_maintenance_time=0;
last_move_to_idle_thread_time=0;
maintenance_loop=true;
Expand Down
6 changes: 3 additions & 3 deletions lib/mysql_data_stream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1234,7 +1234,7 @@ void MySQL_Data_Stream::generate_compressed_packet() {
total_size+=p2.size;
l_free(p2.size,p2.ptr);
}
int rc=compress(dest, &destLen, source, sourceLen);
int rc=compress2(dest, &destLen, source, sourceLen, mysql_thread___protocol_compression_level);
assert(rc==Z_OK);
l_free(total_size, source);
queueOUT.pkt.size=destLen+7;
Expand Down Expand Up @@ -1266,9 +1266,9 @@ void MySQL_Data_Stream::generate_compressed_packet() {
dest1=(Bytef *)malloc(destLen1+7);
destLen2=len2*120/100+12;
dest2=(Bytef *)malloc(destLen2+7);
rc=compress(dest1+7, &destLen1, (const unsigned char *)p2.ptr, len1);
rc=compress2(dest1+7, &destLen1, (const unsigned char *)p2.ptr, len1, mysql_thread___protocol_compression_level);
assert(rc==Z_OK);
rc=compress(dest2+7, &destLen2, (const unsigned char *)p2.ptr+len1, len2);
rc=compress2(dest2+7, &destLen2, (const unsigned char *)p2.ptr+len1, len2, mysql_thread___protocol_compression_level);
assert(rc==Z_OK);

hdr.pkt_length=destLen1;
Expand Down
7 changes: 0 additions & 7 deletions microbench/PR1977_bench.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,6 @@ inline int fastrand() {
return (g_seed>>16)&0x7FFF;
}

inline unsigned long long monotonic_time() {
struct timespec ts;
clock_gettime(CLOCK_MONOTONIC, &ts);
return (((unsigned long long) ts.tv_sec) * 1000000) + (ts.tv_nsec / 1000);
}


#define NSRV 24
#define NLOOP 10000000

Expand Down
3 changes: 2 additions & 1 deletion test/tap/groups/groups.json
Original file line number Diff line number Diff line change
Expand Up @@ -180,5 +180,6 @@
"eof_fast_forward-t" : [ "default", "mysql-auto_increment_delay_multiplex=0", "mysql-multiplexing=false", "mysql-query_digests=0", "mysql-query_digests_keep_comment=1" ],
"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" ],
"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" ],
"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" ]
"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" ],
"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" ]
}
6 changes: 6 additions & 0 deletions test/tap/tap/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,12 @@ int create_table_test_sbtest1(int num_rows, MYSQL *mysql) {
return add_more_rows_test_sbtest1(num_rows, mysql);
}

unsigned long long monotonic_time() {
struct timespec ts;
clock_gettime(CLOCK_MONOTONIC, &ts);
return (((unsigned long long) ts.tv_sec) * 1000000) + (ts.tv_nsec / 1000);
}

int create_table_test_sqlite_sbtest1(int num_rows, MYSQL *mysql) {
MYSQL_QUERY(mysql, "DROP TABLE IF EXISTS sbtest1");
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 '')");
Expand Down
2 changes: 2 additions & 0 deletions test/tap/tap/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,8 @@ int create_table_test_sbtest1(int num_rows, MYSQL *mysql);
int create_table_test_sqlite_sbtest1(int num_rows, MYSQL *mysql); // as above, but for SQLite3 server
int add_more_rows_test_sbtest1(int num_rows, MYSQL *mysql, bool sqlite=false);

unsigned long long monotonic_time();

using mysql_res_row = std::vector<std::string>;

/**
Expand Down
6 changes: 0 additions & 6 deletions test/tap/tests/multiple_prepared_statements-t.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,6 @@ inline int fastrand() {
return (g_seed>>16)&0x7FFF;
}

inline unsigned long long monotonic_time() {
struct timespec ts;
clock_gettime(CLOCK_MONOTONIC, &ts);
return (((unsigned long long) ts.tv_sec) * 1000000) + (ts.tv_nsec / 1000);
}

#define NTHREADS 5
#define NCONNS 6
#define NPREP 15000
Expand Down
6 changes: 0 additions & 6 deletions test/tap/tests/mysql-init_connect-1-t.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,6 @@ It uses 2 valid init_connect, and 2 invalid ones that trigger PMC-10003.
It also sets a value that causes a syntax error
*/

inline unsigned long long monotonic_time() {
struct timespec ts;
clock_gettime(CLOCK_MONOTONIC, &ts);
return (((unsigned long long) ts.tv_sec) * 1000000) + (ts.tv_nsec / 1000);
}

int main(int argc, char** argv) {
CommandLine cl;

Expand Down
6 changes: 0 additions & 6 deletions test/tap/tests/mysql-init_connect-2-t.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,6 @@ mysql-init_connect
We configure both hostgroup 0 and 1
*/

inline unsigned long long monotonic_time() {
struct timespec ts;
clock_gettime(CLOCK_MONOTONIC, &ts);
return (((unsigned long long) ts.tv_sec) * 1000000) + (ts.tv_nsec / 1000);
}

int main(int argc, char** argv) {
CommandLine cl;

Expand Down
6 changes: 0 additions & 6 deletions test/tap/tests/mysql-last_insert_id-t.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,6 @@
#include "command_line.h"
#include "utils.h"

inline unsigned long long monotonic_time() {
struct timespec ts;
clock_gettime(CLOCK_MONOTONIC, &ts);
return (((unsigned long long) ts.tv_sec) * 1000000) + (ts.tv_nsec / 1000);
}


std::string queries[5] = {
"SELECT LAST_INSERT_ID() LIMIT 1",
Expand Down
Loading