perf: 性能优化

* io_uring使用buffer pool避免内存分配与释放
    * packet io thread与worker thread无锁访问cmsg
    * 为解密流量的fd设置默认的TTL
This commit is contained in:
luwenpeng
2023-07-14 19:38:18 +08:00
parent 2b00650d3e
commit c3b887f1c5
19 changed files with 935 additions and 939 deletions

View File

@@ -1603,7 +1603,7 @@ static void get_tcp_option_from_cmsg(struct tfe_cmsg *cmsg, struct tfe_tcp_optio
}
}
void __stream_fd_option_setup(struct tfe_stream_private * _stream, evutil_socket_t fd, tfe_conn_dir dir)
void __stream_fd_option_setup(struct tfe_stream_private * _stream, evutil_socket_t fd, tfe_conn_dir dir, int overwrite_ttl)
{
struct tfe_stream * stream = &_stream->head;
struct tfe_proxy_tcp_options * tcp_options = &_stream->proxy_ref->tcp_options;
@@ -1720,21 +1720,31 @@ void __stream_fd_option_setup(struct tfe_stream_private * _stream, evutil_socket
errno = 0;
}
if (options.tcp_ttl > 0)
if (overwrite_ttl > 0)
{
if (__fd_ttl_option_setup(_stream, fd, options.tcp_ttl) < 0)
if (__fd_ttl_option_setup(_stream, fd, overwrite_ttl) < 0)
{
TFE_LOG_ERROR(g_default_logger, "%s: Failed at setup FD's ttl option, ttl = %d, fd = %d",
stream->str_stream_info, options.tcp_ttl, fd);
stream->str_stream_info, overwrite_ttl, fd);
}
}
else
{
if (options.tcp_ttl > 0)
{
if (__fd_ttl_option_setup(_stream, fd, options.tcp_ttl) < 0)
{
TFE_LOG_ERROR(g_default_logger, "%s: Failed at setup FD's ttl option, ttl = %d, fd = %d",
stream->str_stream_info, options.tcp_ttl, fd);
}
}
}
TFE_LOG_DEBUG(g_default_logger,
"%p %s %s: fetch tcp options, nodelay: %d ttl: %d keepalive: %d keepcnt: %d keepidle: %d keepintvl: %d user_timeout: %d",
stream, stream->str_stream_info, (dir == CONN_DIR_DOWNSTREAM ? "downstream" : "upstream"),
options.tcp_nodelay, options.tcp_ttl, options.tcp_keepalive,
options.tcp_keepcnt, options.tcp_keepidle, options.tcp_keepintvl, options.tcp_user_timeout);
"%p %s %s: fetch tcp options, nodelay: %d ttl: %d keepalive: %d keepcnt: %d keepidle: %d keepintvl: %d user_timeout: %d",
stream, stream->str_stream_info, (dir == CONN_DIR_DOWNSTREAM ? "downstream" : "upstream"),
options.tcp_nodelay, overwrite_ttl > 0 ? overwrite_ttl : options.tcp_ttl, options.tcp_keepalive,
options.tcp_keepcnt, options.tcp_keepidle, options.tcp_keepintvl, options.tcp_user_timeout);
}
int tfe_stream_init_by_fds(struct tfe_stream * stream, evutil_socket_t fd_downstream, evutil_socket_t fd_upstream, evutil_socket_t fd_fake_c, evutil_socket_t fd_fake_s)
@@ -1763,13 +1773,13 @@ int tfe_stream_init_by_fds(struct tfe_stream * stream, evutil_socket_t fd_downst
_stream->str_stream_addr = tfe_stream_addr_to_str(_stream->head.addr);
stream->str_stream_info = _stream->str_stream_addr;
__stream_fd_option_setup(_stream, fd_downstream, CONN_DIR_DOWNSTREAM);
__stream_fd_option_setup(_stream, fd_upstream, CONN_DIR_UPSTREAM);
__stream_fd_option_setup(_stream, fd_downstream, CONN_DIR_DOWNSTREAM, 0);
__stream_fd_option_setup(_stream, fd_upstream, CONN_DIR_UPSTREAM, 0);
if (_stream->is_decrypted_traffic_steering)
{
__stream_fd_option_setup(_stream, fd_fake_s, CONN_DIR_UPSTREAM);
__stream_fd_option_setup(_stream, fd_fake_c, CONN_DIR_DOWNSTREAM);
__stream_fd_option_setup(_stream, fd_fake_s, CONN_DIR_UPSTREAM, TFE_FAKE_S_DEFAULT_TTL);
__stream_fd_option_setup(_stream, fd_fake_c, CONN_DIR_DOWNSTREAM, TFE_FAKE_C_DEFAULT_TTL);
_stream->conn_fake_s = __conn_private_create_by_fake_fd(_stream, fd_fake_s);
if (_stream->conn_fake_s == NULL)