hawq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From shiv...@apache.org
Subject [38/50] incubator-hawq git commit: HAWQ-557. Set connection pool connections always NODELAY and KEEPALIVE
Date Mon, 21 Mar 2016 22:02:07 GMT
HAWQ-557. Set connection pool connections always NODELAY and KEEPALIVE


Project: http://git-wip-us.apache.org/repos/asf/incubator-hawq/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-hawq/commit/e82ac3f1
Tree: http://git-wip-us.apache.org/repos/asf/incubator-hawq/tree/e82ac3f1
Diff: http://git-wip-us.apache.org/repos/asf/incubator-hawq/diff/e82ac3f1

Branch: refs/heads/HAWQ-459
Commit: e82ac3f17319dcc630b467868491089a189aeeec
Parents: f38ad11
Author: YI JIN <yjin@pivotal.io>
Authored: Fri Mar 18 13:58:18 2016 +1100
Committer: YI JIN <yjin@pivotal.io>
Committed: Fri Mar 18 13:58:18 2016 +1100

----------------------------------------------------------------------
 .../communication/rmcomm_AsyncComm.c            |  6 +++++
 .../communication/rmcomm_Connect.c              |  5 ++++
 .../communication/rmcomm_QD2RM.c                | 27 ++++++++++++++++++++
 .../include/utils/network_utils.h               |  1 +
 .../resourcemanager/utils/network_utils.c       | 20 +++++++++++++++
 5 files changed, 59 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/e82ac3f1/src/backend/resourcemanager/communication/rmcomm_AsyncComm.c
----------------------------------------------------------------------
diff --git a/src/backend/resourcemanager/communication/rmcomm_AsyncComm.c b/src/backend/resourcemanager/communication/rmcomm_AsyncComm.c
index 0084edc..181cc86 100644
--- a/src/backend/resourcemanager/communication/rmcomm_AsyncComm.c
+++ b/src/backend/resourcemanager/communication/rmcomm_AsyncComm.c
@@ -718,6 +718,12 @@ int registerAsyncConnectionFileDesc(const char				*address,
 	sockres = connect(fd, (struct sockaddr *)&server_addr, sizeof(server_addr));
 	if ( sockres == 0 )
 	{
+		if ( setConnectionLongTermNoDelay(fd) != FUNC_RETURN_OK )
+		{
+			close(fd);
+			res = UTIL_NETWORK_FAIL_CONNECT;
+			goto exit;
+		}
 		/*
 		 * New connection is created. Suppose domain socket and local socket
 		 * connection can be done now. Register a normal client FD in poll() to

http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/e82ac3f1/src/backend/resourcemanager/communication/rmcomm_Connect.c
----------------------------------------------------------------------
diff --git a/src/backend/resourcemanager/communication/rmcomm_Connect.c b/src/backend/resourcemanager/communication/rmcomm_Connect.c
index fd916da..6c58a5c 100644
--- a/src/backend/resourcemanager/communication/rmcomm_Connect.c
+++ b/src/backend/resourcemanager/communication/rmcomm_Connect.c
@@ -68,6 +68,11 @@ void WriteReadyHandler_Connect(AsyncCommBuffer buffer)
 		shouldclose = true;
 	}
 
+	if ( setConnectionLongTermNoDelay(buffer->FD) != FUNC_RETURN_OK )
+	{
+		shouldclose = true;
+	}
+
 	if ( shouldclose )
 	{
 		ErrorHandler_Connect(buffer);

http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/e82ac3f1/src/backend/resourcemanager/communication/rmcomm_QD2RM.c
----------------------------------------------------------------------
diff --git a/src/backend/resourcemanager/communication/rmcomm_QD2RM.c b/src/backend/resourcemanager/communication/rmcomm_QD2RM.c
index d601383..59494a0 100644
--- a/src/backend/resourcemanager/communication/rmcomm_QD2RM.c
+++ b/src/backend/resourcemanager/communication/rmcomm_QD2RM.c
@@ -1440,6 +1440,7 @@ void *generateResourceRefreshHeartBeat(void *arg)
 				int sockres = 0;
 				while(true)
 				{
+					int on;
 					sockres = connect(fd,
 									  (struct sockaddr *)&server_addr,
 									  sizeof(server_addr));
@@ -1455,8 +1456,34 @@ void *generateResourceRefreshHeartBeat(void *arg)
 									  "failed to connect to resource manager, "
 									  "fd %d (errno %d)", fd, errno);
 							close(fd);
+							fd = -1;
 						}
 					}
+#ifdef	TCP_NODELAY
+					on = 1;
+					if (sockres == 0 &&
+						setsockopt(fd,
+								   IPPROTO_TCP, TCP_NODELAY,
+								   (char *) &on, sizeof(on)) < 0)
+					{
+						write_log("ERROR setsockopt(TCP_NODELAY) failed: %m");
+						close(fd);
+						fd = -1;
+						sockres = -1;
+					}
+#endif
+					on = 1;
+					if (sockres == 0 &&
+						setsockopt(fd,
+								   SOL_SOCKET, SO_KEEPALIVE,
+								   (char *) &on, sizeof(on)) < 0)
+					{
+						write_log("ERROR setsockopt(SO_KEEPALIVE) failed: %m");
+						close(fd);
+						fd = -1;
+						sockres = -1;
+					}
+
 					break;
 				}
 

http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/e82ac3f1/src/backend/resourcemanager/include/utils/network_utils.h
----------------------------------------------------------------------
diff --git a/src/backend/resourcemanager/include/utils/network_utils.h b/src/backend/resourcemanager/include/utils/network_utils.h
index 4aa2cf0..a048131 100644
--- a/src/backend/resourcemanager/include/utils/network_utils.h
+++ b/src/backend/resourcemanager/include/utils/network_utils.h
@@ -109,6 +109,7 @@ int setConnectionNonBlocked(int fd);
 
 #define DRM_SOCKET_CONN_RETRY 5
 int  connectToServerRemote(const char *address,uint16_t port,int *clientfd);
+int setConnectionLongTermNoDelay(int fd);
 void closeConnectionRemote(int *clientfd);
 void returnAliveConnectionRemote(int 			*clientfd,
 								 const char 	*hostname,

http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/e82ac3f1/src/backend/resourcemanager/utils/network_utils.c
----------------------------------------------------------------------
diff --git a/src/backend/resourcemanager/utils/network_utils.c b/src/backend/resourcemanager/utils/network_utils.c
index b8bbab9..fbfe0a9 100644
--- a/src/backend/resourcemanager/utils/network_utils.c
+++ b/src/backend/resourcemanager/utils/network_utils.c
@@ -715,3 +715,23 @@ static void cleanupSocketConnectionPool(int code, Datum arg)
 	freePAIRRefList(&ResolvedHostnames, &addrlist);
 	cleanHASHTABLE(&ResolvedHostnames);
 }
+
+int setConnectionLongTermNoDelay(int fd)
+{
+	int on;
+#ifdef	TCP_NODELAY
+	on = 1;
+	if (setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, (char *) &on, sizeof(on)) < 0)
+	{
+		elog(WARNING, "setsockopt(TCP_NODELAY) failed: %m");
+		return SYSTEM_CALL_ERROR;
+	}
+#endif
+	on = 1;
+	if (setsockopt(fd, SOL_SOCKET, SO_KEEPALIVE, (char *) &on, sizeof(on)) < 0)
+	{
+		elog(WARNING, "setsockopt(SO_KEEPALIVE) failed: %m");
+		return SYSTEM_CALL_ERROR;
+	}
+	return FUNC_RETURN_OK;
+}


Mime
View raw message