Skip to content

Commit 4c75588

Browse files
authored
Merge pull request #4814 from sysown/v3.0_compression_test_fix
Move setting of compression level to correct place in the tap test
2 parents f27aa6f + e7159ad commit 4c75588

File tree

1 file changed

+36
-30
lines changed

1 file changed

+36
-30
lines changed

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

+36-30
Original file line numberDiff line numberDiff line change
@@ -46,18 +46,18 @@ MYSQL* initilize_mysql_connection(char* host, char* username, char* password, in
4646
return nullptr;
4747

4848
fprintf(stderr, "MySQL connection details: %s %s %d\n", username, password, port);
49-
if (!mysql_real_connect(mysql, host, username, password, NULL, port, NULL, 0)) {
50-
fprintf(stderr, "Failed to connect to database: Error: %s\n",
51-
mysql_error(mysql));
52-
return nullptr;
53-
}
5449
if (compression) {
5550
if (mysql_options(mysql, MYSQL_OPT_COMPRESS, nullptr) != 0) {
5651
fprintf(stderr, "Failed to set mysql compression option: Error: %s\n",
5752
mysql_error(mysql));
5853
return nullptr;
5954
}
6055
}
56+
if (!mysql_real_connect(mysql, host, username, password, NULL, port, NULL, 0)) {
57+
fprintf(stderr, "Failed to connect to database: Error: %s\n",
58+
mysql_error(mysql));
59+
return nullptr;
60+
}
6161
return mysql;
6262
}
6363

@@ -66,8 +66,9 @@ int main(int argc, char** argv) {
6666
CommandLine cl;
6767
std::string query = "SELECT t1.id id1, t1.k k1, t1.c c1, t1.pad pad1, t2.id id2, t2.k k2, t2.c c2, t2.pad pad2 FROM test.sbtest1 t1 JOIN test.sbtest1 t2 LIMIT 90000000";
6868
unsigned long time_proxy = 0;
69-
unsigned long time_proxy_compressed = 0;
70-
unsigned long diff = 0;
69+
unsigned long time_proxy_compression_level_default = 0;
70+
unsigned long time_proxy_compression_level_8 = 0;
71+
long diff = 0;
7172
unsigned long time_mysql_compressed = 0;
7273
unsigned long time_mysql_without_compressed = 0;
7374
std::string compression_level = {""};
@@ -82,7 +83,7 @@ int main(int argc, char** argv) {
8283
if(cl.getEnv())
8384
return exit_status();
8485

85-
plan(8);
86+
plan(9);
8687

8788
// ProxySQL connection without compression
8889
proxysql = initilize_mysql_connection(cl.host, cl.username, cl.password, cl.port, false);
@@ -96,18 +97,18 @@ int main(int argc, char** argv) {
9697
goto cleanup;
9798
}
9899

99-
// MySQL connection with compression
100-
mysql_compression = initilize_mysql_connection(cl.host, cl.username, cl.password, cl.mysql_port, true);
101-
if (!mysql_compression) {
102-
goto cleanup;
103-
}
104-
105100
// MySQL connection without compression
106101
mysql = initilize_mysql_connection(cl.host, cl.username, cl.password, cl.mysql_port, false);
107102
if (!mysql) {
108103
goto cleanup;
109104
}
110105

106+
// MySQL connection with compression
107+
mysql_compression = initilize_mysql_connection(cl.host, cl.username, cl.password, cl.mysql_port, true);
108+
if (!mysql_compression) {
109+
goto cleanup;
110+
}
111+
111112
// ProxySQL admin connection
112113
proxysql_admin = initilize_mysql_connection(cl.host, cl.admin_username, cl.admin_password, cl.admin_port, false);
113114
if (!proxysql_admin) {
@@ -135,33 +136,33 @@ int main(int argc, char** argv) {
135136
goto cleanup;
136137
}
137138

138-
time_proxy_compressed = calculate_query_execution_time(proxysql_compression, query);
139-
diag("Time taken for query with proxysql with compression: %ld", time_proxy_compressed);
140-
if (time_proxy_compressed == -1) {
139+
time_proxy_compression_level_default = calculate_query_execution_time(proxysql_compression, query);
140+
diag("Time taken for query with proxysql with default compression (3): %ld", time_proxy_compression_level_default);
141+
if (time_proxy_compression_level_default == -1) {
141142
goto cleanup;
142143
}
143144

144-
diff = abs(time_proxy - time_proxy_compressed);
145+
diff = time_proxy_compression_level_default - time_proxy;
145146
performance_diff = (float)(diff * 100) / time_proxy;
146147

147-
ok((performance_diff < 10), "proxysql with compression performed well compared to without compression. Performance difference: %f percentage", performance_diff);
148-
149-
time_mysql_compressed = calculate_query_execution_time(mysql_compression, query);
150-
diag("Time taken for query with mysql with compression: %ld", time_mysql_compressed);
151-
if (time_mysql_compressed == -1) {
152-
goto cleanup;
153-
}
148+
ok((performance_diff > 0), "proxysql without compression performed well compared to default compression level (3). Performance difference: %f percentage", performance_diff);
154149

155150
time_mysql_without_compressed = calculate_query_execution_time(mysql, query);
156151
diag("Time taken for query with mysql without compression: %ld", time_mysql_without_compressed);
157152
if (time_mysql_without_compressed == -1) {
158153
goto cleanup;
159154
}
160155

161-
diff = abs(time_mysql_without_compressed - time_mysql_compressed);
156+
time_mysql_compressed = calculate_query_execution_time(mysql_compression, query);
157+
diag("Time taken for query with mysql with compression: %ld", time_mysql_compressed);
158+
if (time_mysql_compressed == -1) {
159+
goto cleanup;
160+
}
161+
162+
diff = time_mysql_compressed - time_mysql_without_compressed;
162163
performance_diff = (float)(diff * 100) / time_mysql_without_compressed;
163164

164-
ok((performance_diff < 10), "MySQL with compression performed well compared to without compression. Performance difference: %f percentage", performance_diff);
165+
ok((performance_diff > 0), "MySQL without compression performed well compared to mysql with compression. Performance difference: %f percentage", performance_diff);
165166

166167
ret = get_variable_value(proxysql_admin, "mysql-protocol_compression_level", compression_level, true);
167168
if (ret == EXIT_SUCCESS) {
@@ -204,12 +205,17 @@ int main(int argc, char** argv) {
204205
goto cleanup;
205206
}
206207

207-
time_proxy_compressed = calculate_query_execution_time(proxysql_compression, query);
208-
diag("Time taken for query with proxysql with compression level 8: %ld", time_proxy_compressed);
209-
if (time_proxy_compressed == -1) {
208+
time_proxy_compression_level_8 = calculate_query_execution_time(proxysql_compression, query);
209+
diag("Time taken for query with proxysql with compression level 8: %ld", time_proxy_compression_level_8);
210+
if (time_proxy_compression_level_8 == -1) {
210211
goto cleanup;
211212
}
212213

214+
diff = time_proxy_compression_level_8 - time_proxy_compression_level_default;
215+
performance_diff = (float)(diff * 100) / time_proxy_compression_level_default;
216+
217+
ok((performance_diff > 0), "proxysql with default compression level (3) performed well compared to compression level (8). Performance difference: %f percentage", performance_diff);
218+
213219
set_admin_global_variable(proxysql_admin, "mysql-protocol_compression_level", "3");
214220
if (mysql_query(proxysql_admin, "load mysql variables to runtime")) {
215221
diag("Failed to load mysql variables to runtime.");

0 commit comments

Comments
 (0)