Skip to content
Snippets Groups Projects
Commit 2c4a6a93 authored by Christophe Geuzaine's avatar Christophe Geuzaine
Browse files

previous commits (disabling Nagle's buffering algorithm) seem to fix the...

previous commits (disabling Nagle's buffering algorithm) seem to fix the performance problem for TCP/IP connections on Linux
parent 387e08d4
No related branches found
No related tags found
No related merge requests found
...@@ -280,6 +280,7 @@ class GmshClient : public GmshSocket { ...@@ -280,6 +280,7 @@ class GmshClient : public GmshSocket {
_sock = socket(AF_INET, SOCK_STREAM, 0); _sock = socket(AF_INET, SOCK_STREAM, 0);
if(_sock < 0) return -1; if(_sock < 0) return -1;
char one = 1; char one = 1;
// disable Nagle's algorithm (very slow for many small messages)
setsockopt(_sock, IPPROTO_TCP, TCP_NODELAY, &one, sizeof(one)); setsockopt(_sock, IPPROTO_TCP, TCP_NODELAY, &one, sizeof(one));
// try to connect socket to host:port // try to connect socket to host:port
const char *port = strstr(sockname, ":"); const char *port = strstr(sockname, ":");
......
...@@ -45,6 +45,7 @@ ...@@ -45,6 +45,7 @@
#include <sys/un.h> #include <sys/un.h>
#include <sys/time.h> #include <sys/time.h>
#include <netinet/in.h> #include <netinet/in.h>
#include <netinet/tcp.h>
#include <netdb.h> #include <netdb.h>
#if defined(HAVE_NO_SOCKLEN_T) #if defined(HAVE_NO_SOCKLEN_T)
typedef int socklen_t; typedef int socklen_t;
...@@ -276,6 +277,9 @@ class GmshClient : public GmshSocket { ...@@ -276,6 +277,9 @@ class GmshClient : public GmshSocket {
// TCP/IP socket // TCP/IP socket
_sock = socket(AF_INET, SOCK_STREAM, 0); _sock = socket(AF_INET, SOCK_STREAM, 0);
if(_sock < 0) return -1; if(_sock < 0) return -1;
char one = 1;
// disable Nagle's algorithm (very slow for many small messages)
setsockopt(_sock, IPPROTO_TCP, TCP_NODELAY, &one, sizeof(one));
// try to connect socket to host:port // try to connect socket to host:port
const char *port = strstr(sockname, ":"); const char *port = strstr(sockname, ":");
int portno = atoi(port + 1); int portno = atoi(port + 1);
...@@ -324,13 +328,13 @@ class GmshServer : public GmshSocket{ ...@@ -324,13 +328,13 @@ class GmshServer : public GmshSocket{
public: public:
GmshServer() : GmshSocket(), _portno(-1) {} GmshServer() : GmshSocket(), _portno(-1) {}
virtual ~GmshServer(){} virtual ~GmshServer(){}
virtual int NonBlockingSystemCall(const char *exe, const char *args) = 0; virtual int NonBlockingSystemCall(const std::string &exe, const std::string &args) = 0;
virtual int NonBlockingWait(double waitint, double timeout, int socket=-1) = 0; virtual int NonBlockingWait(double waitint, double timeout, int socket=-1) = 0;
// start the client by launching "exe args" (args is supposed to contain // start the client by launching "exe args" (args is supposed to contain
// '%s' where the socket name should appear) // '%s' where the socket name should appear)
int Start(const char *exe, const char *args, const char *sockname, double timeout) int Start(const std::string &exe, const std::string &args, const std::string &sockname,
double timeout)
{ {
if(!sockname) throw "Invalid (null) socket name";
_sockname = sockname; _sockname = sockname;
int tmpsock; int tmpsock;
if(strstr(_sockname.c_str(), "/") || strstr(_sockname.c_str(), "\\") || if(strstr(_sockname.c_str(), "/") || strstr(_sockname.c_str(), "\\") ||
...@@ -366,6 +370,9 @@ class GmshServer : public GmshSocket{ ...@@ -366,6 +370,9 @@ class GmshServer : public GmshSocket{
_portno = atoi(port + 1); _portno = atoi(port + 1);
// create a socket // create a socket
tmpsock = socket(AF_INET, SOCK_STREAM, 0); tmpsock = socket(AF_INET, SOCK_STREAM, 0);
char one = 1;
setsockopt(tmpsock, IPPROTO_TCP, TCP_NODELAY, &one, sizeof(one));
#if !defined(WIN32) || defined(__CYGWIN__) #if !defined(WIN32) || defined(__CYGWIN__)
if(tmpsock < 0) if(tmpsock < 0)
#else #else
...@@ -393,9 +400,9 @@ class GmshServer : public GmshSocket{ ...@@ -393,9 +400,9 @@ class GmshServer : public GmshSocket{
} }
} }
if((exe && strlen(exe)) || (args && strlen(args))){ if(exe.size() || args.size()){
char s[1024]; char s[1024];
sprintf(s, args, _sockname.c_str()); sprintf(s, args.c_str(), _sockname.c_str());
NonBlockingSystemCall(exe, s); // starts the solver NonBlockingSystemCall(exe, s); // starts the solver
} }
else{ else{
...@@ -433,9 +440,10 @@ class GmshServer : public GmshSocket{ ...@@ -433,9 +440,10 @@ class GmshServer : public GmshSocket{
struct sockaddr_in from_in; struct sockaddr_in from_in;
socklen_t len = sizeof(from_in); socklen_t len = sizeof(from_in);
_sock = accept(tmpsock, (struct sockaddr *)&from_in, &len); _sock = accept(tmpsock, (struct sockaddr *)&from_in, &len);
char one = 1;
setsockopt(_sock, IPPROTO_TCP, TCP_NODELAY, &one, sizeof(one));
} }
CloseSocket(tmpsock); CloseSocket(tmpsock);
if(_sock < 0) if(_sock < 0)
throw "Socket accept failed"; throw "Socket accept failed";
return _sock; return _sock;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment