You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@brpc.apache.org by "chenBright (via GitHub)" <gi...@apache.org> on 2023/01/26 10:40:52 UTC
[GitHub] [brpc] chenBright opened a new pull request, #2098: support TCP heartbeat of client
chenBright opened a new pull request, #2098:
URL: https://github.com/apache/brpc/pull/2098
### What problem does this PR solve?
Issue Number: #1895
Problem Summary:
### What is changed and the side effects?
Changed:
Side effects:
- Performance effects(性能影响):
- Breaking backward compatibility(向后兼容性):
---
### Check List:
- Please make sure your changes are compilable(请确保你的更改可以通过编译).
- When providing us with a new feature, it is best to add related tests(如果你向我们增加一个新的功能, 请添加相关测试).
- Please follow [Contributor Covenant Code of Conduct](../../master/CODE_OF_CONDUCT.md).(请遵循贡献者准则).
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org
For additional commands, e-mail: dev-help@brpc.apache.org
[GitHub] [brpc] wwbmmm commented on a diff in pull request #2098: support TCP heartbeat of client
Posted by "wwbmmm (via GitHub)" <gi...@apache.org>.
wwbmmm commented on code in PR #2098:
URL: https://github.com/apache/brpc/pull/2098#discussion_r1091347215
##########
src/brpc/socket.h:
##########
@@ -198,6 +212,31 @@ struct SocketOptions {
std::shared_ptr<AppConnect> app_connect;
// The created socket will set parsing_context with this value.
Destroyable* initial_parsing_context;
+
+ // Socket keepalive related options.
+ // Refer to `SocketKeepaliveOptions' for details
+ void enable_keepalive() {
+ if (!_keepalive_options) {
+ _keepalive_options.reset(new SocketKeepaliveOptions);
+ }
+ }
+ bool has_keepalive_options() { return _keepalive_options != NULL; }
+ const SocketKeepaliveOptions& keepalive_options() const {
+ return *_keepalive_options;
+ }
+ SocketKeepaliveOptions* mutable_keepalive_options() {
+ enable_keepalive();
+ return _keepalive_options.get();
+ }
+ std::shared_ptr<SocketKeepaliveOptions>
+ shared_keepalibe_options() const {
+ return _keepalive_options;
+ }
+
+private:
+ // SocketKeepaliveOptions is not often used, allocate it on heap to
+ // prevent SocketKeepaliveOptions from being bloated in most cases.
+ std::shared_ptr<SocketKeepaliveOptions> _keepalive_options;
Review Comment:
看socket option的其它成员都是public,比如
`std::shared_ptr<SocketSSLContext> initial_ssl_ctx;`
`std::shared_ptr<AppConnect> app_connect;`
这个是不是也直接public就好了?
##########
src/brpc/socket.h:
##########
@@ -198,6 +212,31 @@ struct SocketOptions {
std::shared_ptr<AppConnect> app_connect;
// The created socket will set parsing_context with this value.
Destroyable* initial_parsing_context;
+
+ // Socket keepalive related options.
+ // Refer to `SocketKeepaliveOptions' for details
+ void enable_keepalive() {
+ if (!_keepalive_options) {
+ _keepalive_options.reset(new SocketKeepaliveOptions);
+ }
+ }
+ bool has_keepalive_options() { return _keepalive_options != NULL; }
+ const SocketKeepaliveOptions& keepalive_options() const {
+ return *_keepalive_options;
+ }
+ SocketKeepaliveOptions* mutable_keepalive_options() {
+ enable_keepalive();
+ return _keepalive_options.get();
+ }
+ std::shared_ptr<SocketKeepaliveOptions>
+ shared_keepalibe_options() const {
Review Comment:
keepalibe -> keepalive
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org
For additional commands, e-mail: dev-help@brpc.apache.org
[GitHub] [brpc] cdjingit commented on a diff in pull request #2098: support TCP heartbeat of client
Posted by "cdjingit (via GitHub)" <gi...@apache.org>.
cdjingit commented on code in PR #2098:
URL: https://github.com/apache/brpc/pull/2098#discussion_r1091424180
##########
src/brpc/socket.cpp:
##########
@@ -590,6 +592,69 @@ int Socket::ResetFileDescriptor(int fd) {
return 0;
}
+void Socket::SetKeepalive(int fd) {
+ if (!_keepalive_options) {
+ return;
+ } else {
+ int keep_alive = 1;
+ socklen_t size = sizeof(keep_alive);
+ if (setsockopt(fd, SOL_SOCKET, SO_KEEPALIVE, &keep_alive, size)!=0) {
+ LOG(FATAL) << "Fail to set keepalive of fd=" << fd;
Review Comment:
打印出系统error
PLOG(FATAL) << "Fail to set keepalive of fd=" << fd;
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org
For additional commands, e-mail: dev-help@brpc.apache.org
[GitHub] [brpc] chenBright commented on a diff in pull request #2098: support TCP heartbeat of client
Posted by "chenBright (via GitHub)" <gi...@apache.org>.
chenBright commented on code in PR #2098:
URL: https://github.com/apache/brpc/pull/2098#discussion_r1090618329
##########
src/brpc/socket.cpp:
##########
@@ -579,6 +583,71 @@ int Socket::ResetFileDescriptor(int fd) {
}
}
+ do {
Review Comment:
done
##########
src/brpc/socket.h:
##########
@@ -198,6 +198,15 @@ struct SocketOptions {
std::shared_ptr<AppConnect> app_connect;
// The created socket will set parsing_context with this value.
Destroyable* initial_parsing_context;
+
+ // Enable TCP keepalive or not.
+ bool keepalive;
Review Comment:
done
##########
src/brpc/input_messenger.cpp:
##########
@@ -53,6 +53,18 @@ DEFINE_bool(log_connection_close, false,
"Print log when remote side closes the connection");
BRPC_VALIDATE_GFLAG(log_connection_close, PassValidate);
+DEFINE_bool(socket_keepalive, false,
+ "Enable keepalive of sockets if this value is true");
+
+DEFINE_int32(socket_keepidle_s, -1,
Review Comment:
done
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org
For additional commands, e-mail: dev-help@brpc.apache.org
[GitHub] [brpc] cdjingit commented on pull request #2098: support TCP heartbeat of client
Posted by "cdjingit (via GitHub)" <gi...@apache.org>.
cdjingit commented on PR #2098:
URL: https://github.com/apache/brpc/pull/2098#issuecomment-1413097090
LGTM
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org
For additional commands, e-mail: dev-help@brpc.apache.org
[GitHub] [brpc] chenBright commented on a diff in pull request #2098: support TCP heartbeat of client
Posted by "chenBright (via GitHub)" <gi...@apache.org>.
chenBright commented on code in PR #2098:
URL: https://github.com/apache/brpc/pull/2098#discussion_r1091834224
##########
src/brpc/socket.cpp:
##########
@@ -590,6 +592,69 @@ int Socket::ResetFileDescriptor(int fd) {
return 0;
}
+void Socket::SetKeepalive(int fd) {
Review Comment:
done
##########
src/brpc/socket.cpp:
##########
@@ -590,6 +592,69 @@ int Socket::ResetFileDescriptor(int fd) {
return 0;
}
+void Socket::SetKeepalive(int fd) {
+ if (!_keepalive_options) {
Review Comment:
done
##########
src/brpc/socket.cpp:
##########
@@ -590,6 +592,69 @@ int Socket::ResetFileDescriptor(int fd) {
return 0;
}
+void Socket::SetKeepalive(int fd) {
+ if (!_keepalive_options) {
+ return;
+ } else {
+ int keep_alive = 1;
+ socklen_t size = sizeof(keep_alive);
+ if (setsockopt(fd, SOL_SOCKET, SO_KEEPALIVE, &keep_alive, size)!=0) {
+ LOG(FATAL) << "Fail to set keepalive of fd=" << fd;
Review Comment:
done
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org
For additional commands, e-mail: dev-help@brpc.apache.org
[GitHub] [brpc] chenBright commented on pull request #2098: support TCP heartbeat of client
Posted by "chenBright (via GitHub)" <gi...@apache.org>.
chenBright commented on PR #2098:
URL: https://github.com/apache/brpc/pull/2098#issuecomment-1408621943
> 另外补充一下单测?
done
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org
For additional commands, e-mail: dev-help@brpc.apache.org
[GitHub] [brpc] chenBright commented on a diff in pull request #2098: support TCP heartbeat of client
Posted by "chenBright (via GitHub)" <gi...@apache.org>.
chenBright commented on code in PR #2098:
URL: https://github.com/apache/brpc/pull/2098#discussion_r1091833005
##########
src/brpc/socket.h:
##########
@@ -198,6 +212,31 @@ struct SocketOptions {
std::shared_ptr<AppConnect> app_connect;
// The created socket will set parsing_context with this value.
Destroyable* initial_parsing_context;
+
+ // Socket keepalive related options.
+ // Refer to `SocketKeepaliveOptions' for details
+ void enable_keepalive() {
+ if (!_keepalive_options) {
+ _keepalive_options.reset(new SocketKeepaliveOptions);
+ }
+ }
+ bool has_keepalive_options() { return _keepalive_options != NULL; }
+ const SocketKeepaliveOptions& keepalive_options() const {
+ return *_keepalive_options;
+ }
+ SocketKeepaliveOptions* mutable_keepalive_options() {
+ enable_keepalive();
+ return _keepalive_options.get();
+ }
+ std::shared_ptr<SocketKeepaliveOptions>
+ shared_keepalibe_options() const {
+ return _keepalive_options;
+ }
+
+private:
+ // SocketKeepaliveOptions is not often used, allocate it on heap to
+ // prevent SocketKeepaliveOptions from being bloated in most cases.
+ std::shared_ptr<SocketKeepaliveOptions> _keepalive_options;
Review Comment:
可以改成public,不过使用SocketOptions就麻烦一点,需要new SocketKeepaliveOptions或者make_shared。
##########
src/brpc/socket.h:
##########
@@ -198,6 +212,31 @@ struct SocketOptions {
std::shared_ptr<AppConnect> app_connect;
// The created socket will set parsing_context with this value.
Destroyable* initial_parsing_context;
+
+ // Socket keepalive related options.
+ // Refer to `SocketKeepaliveOptions' for details
+ void enable_keepalive() {
+ if (!_keepalive_options) {
+ _keepalive_options.reset(new SocketKeepaliveOptions);
+ }
+ }
+ bool has_keepalive_options() { return _keepalive_options != NULL; }
+ const SocketKeepaliveOptions& keepalive_options() const {
+ return *_keepalive_options;
+ }
+ SocketKeepaliveOptions* mutable_keepalive_options() {
+ enable_keepalive();
+ return _keepalive_options.get();
+ }
+ std::shared_ptr<SocketKeepaliveOptions>
+ shared_keepalibe_options() const {
+ return _keepalive_options;
+ }
+
+private:
+ // SocketKeepaliveOptions is not often used, allocate it on heap to
+ // prevent SocketKeepaliveOptions from being bloated in most cases.
+ std::shared_ptr<SocketKeepaliveOptions> _keepalive_options;
Review Comment:
done
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org
For additional commands, e-mail: dev-help@brpc.apache.org
[GitHub] [brpc] chenBright commented on a diff in pull request #2098: support TCP heartbeat of client
Posted by "chenBright (via GitHub)" <gi...@apache.org>.
chenBright commented on code in PR #2098:
URL: https://github.com/apache/brpc/pull/2098#discussion_r1091833256
##########
src/brpc/socket.h:
##########
@@ -198,6 +212,31 @@ struct SocketOptions {
std::shared_ptr<AppConnect> app_connect;
// The created socket will set parsing_context with this value.
Destroyable* initial_parsing_context;
+
+ // Socket keepalive related options.
+ // Refer to `SocketKeepaliveOptions' for details
+ void enable_keepalive() {
+ if (!_keepalive_options) {
+ _keepalive_options.reset(new SocketKeepaliveOptions);
+ }
+ }
+ bool has_keepalive_options() { return _keepalive_options != NULL; }
+ const SocketKeepaliveOptions& keepalive_options() const {
+ return *_keepalive_options;
+ }
+ SocketKeepaliveOptions* mutable_keepalive_options() {
+ enable_keepalive();
+ return _keepalive_options.get();
+ }
+ std::shared_ptr<SocketKeepaliveOptions>
+ shared_keepalibe_options() const {
Review Comment:
done
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org
For additional commands, e-mail: dev-help@brpc.apache.org
[GitHub] [brpc] wwbmmm commented on a diff in pull request #2098: support TCP heartbeat of client
Posted by "wwbmmm (via GitHub)" <gi...@apache.org>.
wwbmmm commented on code in PR #2098:
URL: https://github.com/apache/brpc/pull/2098#discussion_r1089663536
##########
src/brpc/socket.h:
##########
@@ -198,6 +198,15 @@ struct SocketOptions {
std::shared_ptr<AppConnect> app_connect;
// The created socket will set parsing_context with this value.
Destroyable* initial_parsing_context;
+
+ // Enable TCP keepalive or not.
+ bool keepalive;
Review Comment:
这4个参数多次一起出现,是不是可以定义一个结构体(比如SocketKeepaliveOption),简化一下代码
这里可以放结构体的shared_ptr,指针非空表示启用,减少常态下Socket对象占用的内存。
##########
src/brpc/socket.cpp:
##########
@@ -579,6 +583,71 @@ int Socket::ResetFileDescriptor(int fd) {
}
}
+ do {
Review Comment:
这一大段建议单独抽出一个函数
##########
src/brpc/input_messenger.cpp:
##########
@@ -53,6 +53,18 @@ DEFINE_bool(log_connection_close, false,
"Print log when remote side closes the connection");
BRPC_VALIDATE_GFLAG(log_connection_close, PassValidate);
+DEFINE_bool(socket_keepalive, false,
+ "Enable keepalive of sockets if this value is true");
+
+DEFINE_int32(socket_keepidle_s, -1,
Review Comment:
这几个缩写有点不好理解,可否改成
socket_keepalive_idle_s
socket_keepalive_interval_s
socket_keepalive_count
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: devnull-unsubscribe@infra.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [brpc] cdjingit commented on a diff in pull request #2098: support TCP heartbeat of client
Posted by "cdjingit (via GitHub)" <gi...@apache.org>.
cdjingit commented on code in PR #2098:
URL: https://github.com/apache/brpc/pull/2098#discussion_r1091423246
##########
src/brpc/socket.cpp:
##########
@@ -590,6 +592,69 @@ int Socket::ResetFileDescriptor(int fd) {
return 0;
}
+void Socket::SetKeepalive(int fd) {
Review Comment:
SetKeepalive -> EnableKeepalive ?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org
For additional commands, e-mail: dev-help@brpc.apache.org
[GitHub] [brpc] cdjingit commented on a diff in pull request #2098: support TCP heartbeat of client
Posted by "cdjingit (via GitHub)" <gi...@apache.org>.
cdjingit commented on code in PR #2098:
URL: https://github.com/apache/brpc/pull/2098#discussion_r1091425668
##########
src/brpc/socket.cpp:
##########
@@ -590,6 +592,69 @@ int Socket::ResetFileDescriptor(int fd) {
return 0;
}
+void Socket::SetKeepalive(int fd) {
+ if (!_keepalive_options) {
+ return;
+ } else {
+ int keep_alive = 1;
+ socklen_t size = sizeof(keep_alive);
+ if (setsockopt(fd, SOL_SOCKET, SO_KEEPALIVE, &keep_alive, size)!=0) {
+ LOG(FATAL) << "Fail to set keepalive of fd=" << fd;
+ return;
+ }
+ }
+
+#if defined(OS_LINUX)
+ if (_keepalive_options->keepalive_idle_s > 0) {
+ socklen_t size = sizeof(_keepalive_options->keepalive_idle_s);
+ if (setsockopt(fd, SOL_TCP, TCP_KEEPIDLE,
+ &_keepalive_options->keepalive_idle_s, size) < 0) {
+ LOG(FATAL) << "Fail to set keepidle of fd=" << fd;
Review Comment:
PLOG() 其他地方类似
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org
For additional commands, e-mail: dev-help@brpc.apache.org
[GitHub] [brpc] chenBright commented on a diff in pull request #2098: support TCP heartbeat of client
Posted by "chenBright (via GitHub)" <gi...@apache.org>.
chenBright commented on code in PR #2098:
URL: https://github.com/apache/brpc/pull/2098#discussion_r1093135496
##########
src/brpc/socket.cpp:
##########
@@ -590,6 +592,69 @@ int Socket::ResetFileDescriptor(int fd) {
return 0;
}
+void Socket::SetKeepalive(int fd) {
+ if (!_keepalive_options) {
+ return;
+ } else {
+ int keep_alive = 1;
+ socklen_t size = sizeof(keep_alive);
+ if (setsockopt(fd, SOL_SOCKET, SO_KEEPALIVE, &keep_alive, size)!=0) {
+ LOG(FATAL) << "Fail to set keepalive of fd=" << fd;
+ return;
+ }
+ }
+
+#if defined(OS_LINUX)
+ if (_keepalive_options->keepalive_idle_s > 0) {
+ socklen_t size = sizeof(_keepalive_options->keepalive_idle_s);
+ if (setsockopt(fd, SOL_TCP, TCP_KEEPIDLE,
+ &_keepalive_options->keepalive_idle_s, size) < 0) {
+ LOG(FATAL) << "Fail to set keepidle of fd=" << fd;
Review Comment:
嗯,改过来了
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org
For additional commands, e-mail: dev-help@brpc.apache.org
[GitHub] [brpc] cdjingit commented on a diff in pull request #2098: support TCP heartbeat of client
Posted by "cdjingit (via GitHub)" <gi...@apache.org>.
cdjingit commented on code in PR #2098:
URL: https://github.com/apache/brpc/pull/2098#discussion_r1091423644
##########
src/brpc/socket.cpp:
##########
@@ -590,6 +592,69 @@ int Socket::ResetFileDescriptor(int fd) {
return 0;
}
+void Socket::SetKeepalive(int fd) {
+ if (!_keepalive_options) {
Review Comment:
代码结构更清晰一点
```
if (! _keepalive_options) {
return;
}
......
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org
For additional commands, e-mail: dev-help@brpc.apache.org
[GitHub] [brpc] wwbmmm commented on a diff in pull request #2098: support TCP heartbeat of client
Posted by "wwbmmm (via GitHub)" <gi...@apache.org>.
wwbmmm commented on code in PR #2098:
URL: https://github.com/apache/brpc/pull/2098#discussion_r1092674319
##########
src/brpc/socket.cpp:
##########
@@ -590,6 +592,69 @@ int Socket::ResetFileDescriptor(int fd) {
return 0;
}
+void Socket::SetKeepalive(int fd) {
+ if (!_keepalive_options) {
+ return;
+ } else {
+ int keep_alive = 1;
+ socklen_t size = sizeof(keep_alive);
+ if (setsockopt(fd, SOL_SOCKET, SO_KEEPALIVE, &keep_alive, size)!=0) {
+ LOG(FATAL) << "Fail to set keepalive of fd=" << fd;
+ return;
+ }
+ }
+
+#if defined(OS_LINUX)
+ if (_keepalive_options->keepalive_idle_s > 0) {
+ socklen_t size = sizeof(_keepalive_options->keepalive_idle_s);
+ if (setsockopt(fd, SOL_TCP, TCP_KEEPIDLE,
+ &_keepalive_options->keepalive_idle_s, size) < 0) {
+ LOG(FATAL) << "Fail to set keepidle of fd=" << fd;
Review Comment:
这几个LOG(FATAL)好像还没改过来
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org
For additional commands, e-mail: dev-help@brpc.apache.org
[GitHub] [brpc] chenBright commented on a diff in pull request #2098: support TCP heartbeat of client
Posted by "chenBright (via GitHub)" <gi...@apache.org>.
chenBright commented on code in PR #2098:
URL: https://github.com/apache/brpc/pull/2098#discussion_r1091834733
##########
src/brpc/socket.cpp:
##########
@@ -590,6 +592,69 @@ int Socket::ResetFileDescriptor(int fd) {
return 0;
}
+void Socket::SetKeepalive(int fd) {
+ if (!_keepalive_options) {
+ return;
+ } else {
+ int keep_alive = 1;
+ socklen_t size = sizeof(keep_alive);
+ if (setsockopt(fd, SOL_SOCKET, SO_KEEPALIVE, &keep_alive, size)!=0) {
+ LOG(FATAL) << "Fail to set keepalive of fd=" << fd;
+ return;
+ }
+ }
+
+#if defined(OS_LINUX)
+ if (_keepalive_options->keepalive_idle_s > 0) {
+ socklen_t size = sizeof(_keepalive_options->keepalive_idle_s);
+ if (setsockopt(fd, SOL_TCP, TCP_KEEPIDLE,
+ &_keepalive_options->keepalive_idle_s, size) < 0) {
+ LOG(FATAL) << "Fail to set keepidle of fd=" << fd;
+ }
+ }
+
+ if (_keepalive_options->keepalive_interval_s > 0) {
+ socklen_t size = sizeof(_keepalive_options->keepalive_interval_s);
Review Comment:
done
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org
For additional commands, e-mail: dev-help@brpc.apache.org
Re: [PR] Support TCP heartbeat of client (brpc)
Posted by "wwbmmm (via GitHub)" <gi...@apache.org>.
wwbmmm merged PR #2098:
URL: https://github.com/apache/brpc/pull/2098
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org
For additional commands, e-mail: dev-help@brpc.apache.org
[GitHub] [brpc] wwbmmm commented on pull request #2098: support TCP heartbeat of client
Posted by "wwbmmm (via GitHub)" <gi...@apache.org>.
wwbmmm commented on PR #2098:
URL: https://github.com/apache/brpc/pull/2098#issuecomment-1413081382
LGTM
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org
For additional commands, e-mail: dev-help@brpc.apache.org
[GitHub] [brpc] wwbmmm commented on pull request #2098: support TCP heartbeat of client
Posted by "wwbmmm (via GitHub)" <gi...@apache.org>.
wwbmmm commented on PR #2098:
URL: https://github.com/apache/brpc/pull/2098#issuecomment-1407311836
另外补充一下单测?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: devnull-unsubscribe@infra.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [brpc] cdjingit commented on a diff in pull request #2098: support TCP heartbeat of client
Posted by "cdjingit (via GitHub)" <gi...@apache.org>.
cdjingit commented on code in PR #2098:
URL: https://github.com/apache/brpc/pull/2098#discussion_r1091429112
##########
src/brpc/socket.h:
##########
@@ -198,6 +212,31 @@ struct SocketOptions {
std::shared_ptr<AppConnect> app_connect;
// The created socket will set parsing_context with this value.
Destroyable* initial_parsing_context;
+
+ // Socket keepalive related options.
+ // Refer to `SocketKeepaliveOptions' for details
+ void enable_keepalive() {
+ if (!_keepalive_options) {
+ _keepalive_options.reset(new SocketKeepaliveOptions);
+ }
+ }
+ bool has_keepalive_options() { return _keepalive_options != NULL; }
Review Comment:
bool has_keepalive_options() const
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org
For additional commands, e-mail: dev-help@brpc.apache.org
[GitHub] [brpc] cdjingit commented on a diff in pull request #2098: support TCP heartbeat of client
Posted by "cdjingit (via GitHub)" <gi...@apache.org>.
cdjingit commented on code in PR #2098:
URL: https://github.com/apache/brpc/pull/2098#discussion_r1091431658
##########
src/brpc/socket.cpp:
##########
@@ -590,6 +592,69 @@ int Socket::ResetFileDescriptor(int fd) {
return 0;
}
+void Socket::SetKeepalive(int fd) {
+ if (!_keepalive_options) {
+ return;
+ } else {
+ int keep_alive = 1;
+ socklen_t size = sizeof(keep_alive);
+ if (setsockopt(fd, SOL_SOCKET, SO_KEEPALIVE, &keep_alive, size)!=0) {
+ LOG(FATAL) << "Fail to set keepalive of fd=" << fd;
Review Comment:
FATAL 级别似乎太严格了,改成ERROR?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org
For additional commands, e-mail: dev-help@brpc.apache.org
[GitHub] [brpc] cdjingit commented on a diff in pull request #2098: support TCP heartbeat of client
Posted by "cdjingit (via GitHub)" <gi...@apache.org>.
cdjingit commented on code in PR #2098:
URL: https://github.com/apache/brpc/pull/2098#discussion_r1091428037
##########
src/brpc/socket.cpp:
##########
@@ -590,6 +592,69 @@ int Socket::ResetFileDescriptor(int fd) {
return 0;
}
+void Socket::SetKeepalive(int fd) {
+ if (!_keepalive_options) {
+ return;
+ } else {
+ int keep_alive = 1;
+ socklen_t size = sizeof(keep_alive);
+ if (setsockopt(fd, SOL_SOCKET, SO_KEEPALIVE, &keep_alive, size)!=0) {
+ LOG(FATAL) << "Fail to set keepalive of fd=" << fd;
+ return;
+ }
+ }
+
+#if defined(OS_LINUX)
+ if (_keepalive_options->keepalive_idle_s > 0) {
+ socklen_t size = sizeof(_keepalive_options->keepalive_idle_s);
+ if (setsockopt(fd, SOL_TCP, TCP_KEEPIDLE,
+ &_keepalive_options->keepalive_idle_s, size) < 0) {
+ LOG(FATAL) << "Fail to set keepidle of fd=" << fd;
+ }
+ }
+
+ if (_keepalive_options->keepalive_interval_s > 0) {
+ socklen_t size = sizeof(_keepalive_options->keepalive_interval_s);
Review Comment:
size 变量可以不定义了,直接
```
::setsockopt(fd, SOL_TCP, TCP_KEEPINTVL,
&_keepalive_options->keepalive_interval_s,
sizeof(_keepalive_options->keepalive_interval_s)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org
For additional commands, e-mail: dev-help@brpc.apache.org
[GitHub] [brpc] cdjingit commented on a diff in pull request #2098: support TCP heartbeat of client
Posted by "cdjingit (via GitHub)" <gi...@apache.org>.
cdjingit commented on code in PR #2098:
URL: https://github.com/apache/brpc/pull/2098#discussion_r1091425668
##########
src/brpc/socket.cpp:
##########
@@ -590,6 +592,69 @@ int Socket::ResetFileDescriptor(int fd) {
return 0;
}
+void Socket::SetKeepalive(int fd) {
+ if (!_keepalive_options) {
+ return;
+ } else {
+ int keep_alive = 1;
+ socklen_t size = sizeof(keep_alive);
+ if (setsockopt(fd, SOL_SOCKET, SO_KEEPALIVE, &keep_alive, size)!=0) {
+ LOG(FATAL) << "Fail to set keepalive of fd=" << fd;
+ return;
+ }
+ }
+
+#if defined(OS_LINUX)
+ if (_keepalive_options->keepalive_idle_s > 0) {
+ socklen_t size = sizeof(_keepalive_options->keepalive_idle_s);
+ if (setsockopt(fd, SOL_TCP, TCP_KEEPIDLE,
+ &_keepalive_options->keepalive_idle_s, size) < 0) {
+ LOG(FATAL) << "Fail to set keepidle of fd=" << fd;
Review Comment:
PLOG()
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org
For additional commands, e-mail: dev-help@brpc.apache.org
[GitHub] [brpc] cdjingit commented on a diff in pull request #2098: support TCP heartbeat of client
Posted by "cdjingit (via GitHub)" <gi...@apache.org>.
cdjingit commented on code in PR #2098:
URL: https://github.com/apache/brpc/pull/2098#discussion_r1091424589
##########
src/brpc/socket.cpp:
##########
@@ -590,6 +592,69 @@ int Socket::ResetFileDescriptor(int fd) {
return 0;
}
+void Socket::SetKeepalive(int fd) {
+ if (!_keepalive_options) {
+ return;
+ } else {
+ int keep_alive = 1;
+ socklen_t size = sizeof(keep_alive);
+ if (setsockopt(fd, SOL_SOCKET, SO_KEEPALIVE, &keep_alive, size)!=0) {
Review Comment:
```
if (::setsockopt(fd, SOL_SOCKET, SO_KEEPALIVE, &keep_alive, sizeof(keep_alive)) != 0)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org
For additional commands, e-mail: dev-help@brpc.apache.org
[GitHub] [brpc] chenBright commented on a diff in pull request #2098: support TCP heartbeat of client
Posted by "chenBright (via GitHub)" <gi...@apache.org>.
chenBright commented on code in PR #2098:
URL: https://github.com/apache/brpc/pull/2098#discussion_r1091834500
##########
src/brpc/socket.cpp:
##########
@@ -590,6 +592,69 @@ int Socket::ResetFileDescriptor(int fd) {
return 0;
}
+void Socket::SetKeepalive(int fd) {
+ if (!_keepalive_options) {
+ return;
+ } else {
+ int keep_alive = 1;
+ socklen_t size = sizeof(keep_alive);
+ if (setsockopt(fd, SOL_SOCKET, SO_KEEPALIVE, &keep_alive, size)!=0) {
Review Comment:
done
##########
src/brpc/socket.cpp:
##########
@@ -590,6 +592,69 @@ int Socket::ResetFileDescriptor(int fd) {
return 0;
}
+void Socket::SetKeepalive(int fd) {
+ if (!_keepalive_options) {
+ return;
+ } else {
+ int keep_alive = 1;
+ socklen_t size = sizeof(keep_alive);
+ if (setsockopt(fd, SOL_SOCKET, SO_KEEPALIVE, &keep_alive, size)!=0) {
+ LOG(FATAL) << "Fail to set keepalive of fd=" << fd;
+ return;
+ }
+ }
+
+#if defined(OS_LINUX)
+ if (_keepalive_options->keepalive_idle_s > 0) {
+ socklen_t size = sizeof(_keepalive_options->keepalive_idle_s);
+ if (setsockopt(fd, SOL_TCP, TCP_KEEPIDLE,
+ &_keepalive_options->keepalive_idle_s, size) < 0) {
+ LOG(FATAL) << "Fail to set keepidle of fd=" << fd;
Review Comment:
done
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org
For additional commands, e-mail: dev-help@brpc.apache.org