Commit fdf4a5b7 authored by Vladislav Vaintroub's avatar Vladislav Vaintroub

MDEV-16277 tcp_nodelay session variable to enable / disable Nagle algorithm

parent 7a022d70
...@@ -89,6 +89,7 @@ size_t vio_write(Vio *vio, const uchar * buf, size_t size); ...@@ -89,6 +89,7 @@ size_t vio_write(Vio *vio, const uchar * buf, size_t size);
int vio_blocking(Vio *vio, my_bool onoff, my_bool *old_mode); int vio_blocking(Vio *vio, my_bool onoff, my_bool *old_mode);
my_bool vio_is_blocking(Vio *vio); my_bool vio_is_blocking(Vio *vio);
/* setsockopt TCP_NODELAY at IPPROTO_TCP level, when possible */ /* setsockopt TCP_NODELAY at IPPROTO_TCP level, when possible */
int vio_nodelay(Vio *vio, my_bool on);
int vio_fastsend(Vio *vio); int vio_fastsend(Vio *vio);
/* setsockopt SO_KEEPALIVE at SOL_SOCKET level, when possible */ /* setsockopt SO_KEEPALIVE at SOL_SOCKET level, when possible */
int vio_keepalive(Vio *vio, my_bool onoff); int vio_keepalive(Vio *vio, my_bool onoff);
......
...@@ -717,6 +717,7 @@ typedef struct system_variables ...@@ -717,6 +717,7 @@ typedef struct system_variables
ulong session_track_transaction_info; ulong session_track_transaction_info;
my_bool session_track_schema; my_bool session_track_schema;
my_bool session_track_state_change; my_bool session_track_state_change;
my_bool tcp_nodelay;
ulong threadpool_priority; ulong threadpool_priority;
......
...@@ -4039,6 +4039,16 @@ static bool fix_sql_log_bin_after_update(sys_var *self, THD *thd, ...@@ -4039,6 +4039,16 @@ static bool fix_sql_log_bin_after_update(sys_var *self, THD *thd,
return FALSE; return FALSE;
} }
static bool check_session_only_variable(sys_var *self, THD *,set_var *var)
{
if (unlikely(var->type == OPT_GLOBAL))
{
my_error(ER_INCORRECT_GLOBAL_LOCAL_VAR, MYF(0), self->name.str, "SESSION");
return true;
}
return false;
}
/** /**
This function checks if the sql_log_bin can be changed, This function checks if the sql_log_bin can be changed,
what is possible if: what is possible if:
...@@ -4054,20 +4064,17 @@ static bool fix_sql_log_bin_after_update(sys_var *self, THD *thd, ...@@ -4054,20 +4064,17 @@ static bool fix_sql_log_bin_after_update(sys_var *self, THD *thd,
static bool check_sql_log_bin(sys_var *self, THD *thd, set_var *var) static bool check_sql_log_bin(sys_var *self, THD *thd, set_var *var)
{ {
if (check_has_super(self, thd, var)) if (check_has_super(self, thd, var))
return TRUE; return true;
if (unlikely(var->type == OPT_GLOBAL)) if (check_session_only_variable(self, thd, var))
{ return true;
my_error(ER_INCORRECT_GLOBAL_LOCAL_VAR, MYF(0), self->name.str, "SESSION");
return TRUE;
}
if (unlikely(error_if_in_trans_or_substatement(thd, if (unlikely(error_if_in_trans_or_substatement(thd,
ER_STORED_FUNCTION_PREVENTS_SWITCH_SQL_LOG_BIN, ER_STORED_FUNCTION_PREVENTS_SWITCH_SQL_LOG_BIN,
ER_INSIDE_TRANSACTION_PREVENTS_SWITCH_SQL_LOG_BIN))) ER_INSIDE_TRANSACTION_PREVENTS_SWITCH_SQL_LOG_BIN)))
return TRUE; return true;
return FALSE; return false;
} }
static Sys_var_mybool Sys_log_binlog( static Sys_var_mybool Sys_log_binlog(
...@@ -5579,6 +5586,27 @@ static Sys_var_int Sys_keepalive_probes( ...@@ -5579,6 +5586,27 @@ static Sys_var_int Sys_keepalive_probes(
BLOCK_SIZE(1), BLOCK_SIZE(1),
NO_MUTEX_GUARD, NOT_IN_BINLOG, ON_CHECK(NULL)); NO_MUTEX_GUARD, NOT_IN_BINLOG, ON_CHECK(NULL));
static bool update_tcp_nodelay(sys_var *self, THD *thd,
enum_var_type type)
{
DBUG_ASSERT(thd);
Vio *vio = thd->net.vio;
if (vio)
return (MY_TEST(vio_nodelay(vio, thd->variables.tcp_nodelay)));
return false;
}
static Sys_var_mybool Sys_tcp_nodelay(
"tcp_nodelay",
"Set option TCP_NODELAY (disable Nagle's algorithm) on socket",
SESSION_VAR(tcp_nodelay), CMD_LINE(OPT_ARG),
DEFAULT(TRUE),NO_MUTEX_GUARD, NOT_IN_BINLOG,
ON_CHECK(check_session_only_variable),
ON_UPDATE(update_tcp_nodelay));
static Sys_var_charptr Sys_ignore_db_dirs( static Sys_var_charptr Sys_ignore_db_dirs(
"ignore_db_dirs", "ignore_db_dirs",
"Specifies a directory to add to the ignore list when collecting " "Specifies a directory to add to the ignore list when collecting "
......
...@@ -435,8 +435,34 @@ int vio_socket_timeout(Vio *vio, ...@@ -435,8 +435,34 @@ int vio_socket_timeout(Vio *vio,
DBUG_RETURN(ret); DBUG_RETURN(ret);
} }
/* Set TCP_NODELAY (disable Nagle's algorithm */
int vio_nodelay(Vio *vio, my_bool on)
{
int r;
int no_delay= MY_TEST(on);
DBUG_ENTER("vio_nodelay");
if (vio->type == VIO_TYPE_NAMEDPIPE || vio->type == VIO_TYPE_SHARED_MEMORY)
{
DBUG_RETURN(0);
}
r = mysql_socket_setsockopt(vio->mysql_socket, IPPROTO_TCP, TCP_NODELAY,
IF_WIN((const char*), (void*)) &no_delay,
sizeof(no_delay));
if (r)
{
DBUG_PRINT("warning",
("Couldn't set socket option for fast send, error %d",
socket_errno));
r = -1;
}
DBUG_PRINT("exit", ("%d", r));
DBUG_RETURN(r);
}
int vio_fastsend(Vio * vio __attribute__((unused))) int vio_fastsend(Vio * vio)
{ {
int r=0; int r=0;
DBUG_ENTER("vio_fastsend"); DBUG_ENTER("vio_fastsend");
...@@ -454,18 +480,7 @@ int vio_fastsend(Vio * vio __attribute__((unused))) ...@@ -454,18 +480,7 @@ int vio_fastsend(Vio * vio __attribute__((unused)))
} }
#endif /* IPTOS_THROUGHPUT */ #endif /* IPTOS_THROUGHPUT */
if (!r) if (!r)
{ r = vio_nodelay(vio, TRUE);
#ifdef __WIN__
BOOL nodelay= 1;
#else
int nodelay = 1;
#endif
r= mysql_socket_setsockopt(vio->mysql_socket, IPPROTO_TCP, TCP_NODELAY,
IF_WIN((const char*), (void*)) &nodelay,
sizeof(nodelay));
}
if (r) if (r)
{ {
DBUG_PRINT("warning", DBUG_PRINT("warning",
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment