mirror of
https://github.com/zeromq/libzmq.git
synced 2025-02-21 06:37:44 +01:00
Tuning of TCP sockets is done at a single place
Instead of being spread throughout the codebase, the tuning is done in tune_tcp_socket() function. Signed-off-by: Martin Sustrik <sustrik@250bpm.com>
This commit is contained in:
parent
46b053b8d6
commit
b45fec337a
24
src/ip.cpp
24
src/ip.cpp
@ -344,3 +344,27 @@ int zmq::resolve_local_path (sockaddr_storage *addr_, socklen_t *addr_len_,
|
||||
#endif
|
||||
}
|
||||
|
||||
void zmq::tune_tcp_socket (fd_t s_)
|
||||
{
|
||||
// Disable Nagle's algorithm. We are doing data batching on 0MQ level,
|
||||
// so using Nagle wouldn't improve throughput in anyway, but it would
|
||||
// hurt latency.
|
||||
int nodelay = 1;
|
||||
int rc = setsockopt (s_, IPPROTO_TCP, TCP_NODELAY, (char*) &nodelay,
|
||||
sizeof (int));
|
||||
#ifdef ZMQ_HAVE_WINDOWS
|
||||
wsa_assert (rc != SOCKET_ERROR);
|
||||
#else
|
||||
errno_assert (rc == 0);
|
||||
#endif
|
||||
|
||||
#ifdef ZMQ_HAVE_OPENVMS
|
||||
// Disable delayed acknowledgements as they hurt latency is serious manner.
|
||||
int nodelack = 1;
|
||||
rc = setsockopt (s_, IPPROTO_TCP, TCP_NODELACK, (char*) &nodelack,
|
||||
sizeof (int));
|
||||
errno_assert (rc != SOCKET_ERROR);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
|
@ -22,6 +22,7 @@
|
||||
#define __ZMQ_IP_HPP_INCLUDED__
|
||||
|
||||
#include "platform.hpp"
|
||||
#include "fd.hpp"
|
||||
|
||||
#ifdef ZMQ_HAVE_WINDOWS
|
||||
#include "windows.hpp"
|
||||
@ -30,6 +31,7 @@
|
||||
#include <sys/socket.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <netinet/in.h>
|
||||
#include <netinet/tcp.h>
|
||||
#include <netdb.h>
|
||||
#endif
|
||||
|
||||
@ -60,9 +62,12 @@ namespace zmq
|
||||
int resolve_ip_hostname (sockaddr_storage *addr_, socklen_t *addr_len_,
|
||||
const char *hostname_);
|
||||
|
||||
// This function sets up address for UNIX domain transport.
|
||||
// This function sets up address for UNIX domain transport.
|
||||
int resolve_local_path (sockaddr_storage *addr_, socklen_t *addr_len_,
|
||||
const char* pathname_);
|
||||
|
||||
// Tunes the supplied TCP socket for the best latency.
|
||||
void tune_tcp_socket (fd_t s_);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -26,8 +26,8 @@
|
||||
#include "io_thread.hpp"
|
||||
#include "platform.hpp"
|
||||
#include "random.hpp"
|
||||
#include "ip.hpp"
|
||||
#include "err.hpp"
|
||||
#include "ip.hpp"
|
||||
|
||||
#if defined ZMQ_HAVE_WINDOWS
|
||||
#include "windows.hpp"
|
||||
@ -106,25 +106,7 @@ void zmq::tcp_connecter_t::out_event ()
|
||||
return;
|
||||
}
|
||||
|
||||
// Disable Nagle's algorithm. We are doing data batching on 0MQ level,
|
||||
// so using Nagle wouldn't improve throughput in anyway, but it would
|
||||
// hurt latency.
|
||||
int nodelay = 1;
|
||||
int rc = setsockopt (fd, IPPROTO_TCP, TCP_NODELAY, (char*) &nodelay,
|
||||
sizeof (int));
|
||||
#ifdef ZMQ_HAVE_WINDOWS
|
||||
wsa_assert (rc != SOCKET_ERROR);
|
||||
#else
|
||||
errno_assert (rc == 0);
|
||||
#endif
|
||||
|
||||
#ifdef ZMQ_HAVE_OPENVMS
|
||||
// Disable delayed acknowledgements as they hurt latency is serious manner.
|
||||
int nodelack = 1;
|
||||
rc = setsockopt (fd, IPPROTO_TCP, TCP_NODELACK, (char*) &nodelack,
|
||||
sizeof (int));
|
||||
errno_assert (rc != SOCKET_ERROR);
|
||||
#endif
|
||||
tune_tcp_socket (fd);
|
||||
|
||||
// Create the engine object for this connection.
|
||||
tcp_engine_t *engine = new (std::nothrow) tcp_engine_t (fd, options);
|
||||
|
@ -29,6 +29,7 @@
|
||||
#include "session.hpp"
|
||||
#include "config.hpp"
|
||||
#include "err.hpp"
|
||||
#include "ip.hpp"
|
||||
|
||||
#ifdef ZMQ_HAVE_WINDOWS
|
||||
#include "windows.hpp"
|
||||
@ -86,25 +87,7 @@ void zmq::tcp_listener_t::in_event ()
|
||||
if (fd == retired_fd)
|
||||
return;
|
||||
|
||||
// Disable Nagle's algorithm. We are doing data batching on 0MQ level,
|
||||
// so using Nagle wouldn't improve throughput in anyway, but it would
|
||||
// hurt latency.
|
||||
int nodelay = 1;
|
||||
int rc = setsockopt (fd, IPPROTO_TCP, TCP_NODELAY, (char*) &nodelay,
|
||||
sizeof (int));
|
||||
#ifdef ZMQ_HAVE_WINDOWS
|
||||
wsa_assert (rc != SOCKET_ERROR);
|
||||
#else
|
||||
errno_assert (rc == 0);
|
||||
#endif
|
||||
|
||||
#ifdef ZMQ_HAVE_OPENVMS
|
||||
// Disable delayed acknowledgements as they hurt latency is serious manner.
|
||||
int nodelack = 1;
|
||||
rc = setsockopt (fd, IPPROTO_TCP, TCP_NODELACK, (char*) &nodelack,
|
||||
sizeof (int));
|
||||
errno_assert (rc != SOCKET_ERROR);
|
||||
#endif
|
||||
tune_tcp_socket (fd);
|
||||
|
||||
// Create the engine object for this connection.
|
||||
tcp_engine_t *engine = new (std::nothrow) tcp_engine_t (fd, options);
|
||||
|
@ -30,8 +30,8 @@
|
||||
#include "platform.hpp"
|
||||
#include "random.hpp"
|
||||
#include "likely.hpp"
|
||||
#include "ip.hpp"
|
||||
#include "err.hpp"
|
||||
#include "ip.hpp"
|
||||
|
||||
#if defined ZMQ_HAVE_WINDOWS
|
||||
#include "windows.hpp"
|
||||
@ -220,6 +220,8 @@ zmq::fd_t zmq::vtcp_connecter_t::connect ()
|
||||
return retired_fd;
|
||||
}
|
||||
|
||||
tune_tcp_socket (s);
|
||||
|
||||
fd_t result = s;
|
||||
s = retired_fd;
|
||||
return result;
|
||||
|
@ -30,6 +30,7 @@
|
||||
#include "session.hpp"
|
||||
#include "stdint.hpp"
|
||||
#include "err.hpp"
|
||||
#include "ip.hpp"
|
||||
|
||||
zmq::vtcp_listener_t::vtcp_listener_t (io_thread_t *io_thread_,
|
||||
socket_base_t *socket_, options_t &options_) :
|
||||
@ -95,6 +96,8 @@ void zmq::vtcp_listener_t::in_event ()
|
||||
if (fd == retired_fd)
|
||||
return;
|
||||
|
||||
tune_tcp_socket (fd);
|
||||
|
||||
// Create the engine object for this connection.
|
||||
tcp_engine_t *engine = new (std::nothrow) tcp_engine_t (fd, options);
|
||||
alloc_assert (engine);
|
||||
|
Loading…
x
Reference in New Issue
Block a user