MXS-2073: Add missing TCP_NODELAY for client sockets

The client connections had the Nagle algorithm enabled which could cause
bad performance with smaller workloads. The common network configuration
code in utils.cc, currently used by the backend connections, sets it
properly.
This commit is contained in:
Markus Mäkelä 2018-09-27 18:56:15 +03:00
parent ee45900648
commit 93d866c6a7
No known key found for this signature in database
GPG Key ID: 72D48FCE664F7B19
4 changed files with 27 additions and 40 deletions

View File

@ -24,32 +24,18 @@ MXS_BEGIN_DECLS
/**
* MXS_BACKEND_SO_RCVBUF
* MXS_SO_RCVBUF
*
* The value used when setting SO_RCVBUF of backend sockets.
* The size of the network input buffer.
*/
#define MXS_BACKEND_SO_RCVBUF (128 * 1024)
#define MXS_SO_RCVBUF_SIZE (128 * 1024)
/**
* MXS_BACKEND_SO_SNDBUF
* MXS_SO_SNDBUF
*
* The value used when setting SO_SNDBUF of backend sockets.
* The size of the network output buffer.
*/
#define MXS_BACKEND_SO_SNDBUF (128 * 1024)
/**
* MXS_CLIENT_SO_RCVBUF
*
* The value used when setting SO_RCVBUF of client sockets.
*/
#define MXS_CLIENT_SO_RCVBUF (128 * 1024)
/**
* MXS_CLIENT_SO_SNDBUF
*
* The value used when setting SO_SNDBUF of client sockets.
*/
#define MXS_CLIENT_SO_SNDBUF (128 * 1024)
#define MXS_SO_SNDBUF_SIZE (128 * 1024)
/**
* MXS_MAX_NW_READ_BUFFER_SIZE

View File

@ -46,6 +46,20 @@ enum mxs_socket_type
bool utils_init(); /*< Call this first before using any other function */
void utils_end();
/**
* Configure network socket options
*
* This is a helper function for setting various socket options that are always wanted for all types
* of connections. It sets the socket into nonblocking mode, configures sndbuf and rcvbuf sizes
* and sets TCP_NODELAY (no Nagle algorithm).
*
* @param so Socket to configure
* @param type Socket type
*
* @return True if configuration was successful
*/
bool configure_network_socket(int so, int type);
/**
* @brief Create a network socket and a socket configuration
*

View File

@ -2369,21 +2369,7 @@ dcb_accept(DCB *dcb)
{
dcb->stats.n_accepts++;
/* set nonblocking */
sendbuf = MXS_CLIENT_SO_SNDBUF;
if (setsockopt(c_sock, SOL_SOCKET, SO_SNDBUF, &sendbuf, optlen) != 0)
{
MXS_ERROR("Failed to set socket options: %d, %s", errno, mxs_strerror(errno));
}
sendbuf = MXS_CLIENT_SO_RCVBUF;
if (setsockopt(c_sock, SOL_SOCKET, SO_RCVBUF, &sendbuf, optlen) != 0)
{
MXS_ERROR("Failed to set socket options: %d, %s", errno, mxs_strerror(errno));
}
setnonblocking(c_sock);
configure_network_socket(c_sock, client_conn.ss_family);
client_dcb = dcb_alloc(DCB_ROLE_CLIENT_HANDLER, dcb->listener);

View File

@ -942,17 +942,18 @@ void utils_end()
SPINLOCK tmplock = SPINLOCK_INIT;
static bool configure_network_socket(int so)
bool configure_network_socket(int so, int type)
{
int sndbufsize = MXS_BACKEND_SO_SNDBUF;
int rcvbufsize = MXS_BACKEND_SO_RCVBUF;
int sndbufsize = MXS_SO_SNDBUF_SIZE;
int rcvbufsize = MXS_SO_RCVBUF_SIZE;
int one = 1;
if (setsockopt(so, SOL_SOCKET, SO_SNDBUF, &sndbufsize, sizeof(sndbufsize)) != 0 ||
setsockopt(so, SOL_SOCKET, SO_RCVBUF, &rcvbufsize, sizeof(rcvbufsize)) != 0 ||
setsockopt(so, IPPROTO_TCP, TCP_NODELAY, &one, sizeof(one)) != 0)
(type != AF_UNIX && setsockopt(so, IPPROTO_TCP, TCP_NODELAY, &one, sizeof(one)) != 0))
{
MXS_ERROR("Failed to set socket option: %d, %s.", errno, mxs_strerror(errno));
ss_dassert(!true);
return false;
}
@ -1022,7 +1023,7 @@ int open_network_socket(enum mxs_socket_type type, struct sockaddr_storage *addr
freeaddrinfo(ai);
if ((type == MXS_SOCKET_NETWORK && !configure_network_socket(so)) ||
if ((type == MXS_SOCKET_NETWORK && !configure_network_socket(so, addr->ss_family)) ||
(type == MXS_SOCKET_LISTENER && !configure_listener_socket(so)))
{
close(so);