Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[coro_io] fix client pool slow connect bug #657

Merged
merged 4 commits into from
Apr 10, 2024

Conversation

poor-circle
Copy link
Collaborator

Why

There has some bug in old version client_pool.

  1. the socket cost 100ms+ in connection may timeout util 60s.
  2. the timer wont canceled if connection success in some case, which cost process blocking and wait for timeout.

What is changing

  1. fix client pool algorithm for slow connection and reduce latency.
  2. fix the bug.

Example

Copy link

Code Coverage Report
for detail, goto summary download Artifacts

Filename                                       Functions  Missed Functions  Executed       Lines      Missed Lines     Cover    Branches   Missed Branches     Cover
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
coro_io/channel.hpp                                   14                 0   100.00%         105                 3    97.14%          30                 2    93.33%
coro_io/client_pool.hpp                               29                 1    96.55%         358                57    84.08%         140                41    70.71%
coro_io/coro_file.hpp                                 22                 2    90.91%         213                46    78.40%          56                21    62.50%
coro_io/coro_io.hpp                                   48                 1    97.92%         304                 9    97.04%           4                 0   100.00%
coro_io/detail/client_queue.hpp                       10                 1    90.00%          47                 5    89.36%          10                 2    80.00%
coro_io/io_context_pool.hpp                           34                 3    91.18%         206                19    90.78%          26                 6    76.92%
coro_io/rate_limiter.hpp                              13                 1    92.31%          85                 9    89.41%           8                 3    62.50%
coro_rpc/impl/common_service.hpp                       1                 0   100.00%           8                 0   100.00%           4                 0   100.00%
coro_rpc/impl/coro_connection.hpp                     32                 9    71.88%         335               152    54.63%          84                48    42.86%
coro_rpc/impl/coro_rpc_client.hpp                     21                 5    76.19%         164                18    89.02%          44                11    75.00%
coro_rpc/impl/coro_rpc_server.hpp                     13                 0   100.00%         213                26    87.79%          80                35    56.25%
coro_rpc/impl/errno.h                                  9                 4    55.56%          13                 8    38.46%           0                 0         -
coro_rpc/impl/protocol/coro_rpc_protocol.hpp           6                 0   100.00%          84                23    72.62%          24                 9    62.50%
coro_rpc/impl/router.hpp                               5                 0   100.00%          61                 7    88.52%          10                 1    90.00%
easylog.hpp                                            8                 0   100.00%          41                 3    92.68%          12                 4    66.67%
easylog/appender.hpp                                  22                 0   100.00%         266                18    93.23%          88                26    70.45%
easylog/record.hpp                                    17                 0   100.00%         111                 4    96.40%          16                 2    87.50%
struct_pack.hpp                                        3                 2    33.33%          29                 7    75.86%           0                 0         -
struct_pack/calculate_size.hpp                         7                 0   100.00%         215                17    92.09%           6                 5    16.67%
struct_pack/derived_helper.hpp                         2                 2     0.00%           6                 6     0.00%           0                 0         -
struct_pack/endian_wrapper.hpp                         6                 3    50.00%          86                28    67.44%           2                 1    50.00%
struct_pack/error_code.hpp                             6                 6     0.00%          30                30     0.00%           0                 0         -
struct_pack/foreach_macro.h                            1                 1     0.00%           1                 1     0.00%           0                 0         -
struct_pack/md5_constexpr.hpp                          7                 7     0.00%          31                31     0.00%           0                 0         -
struct_pack/packer.hpp                                 9                 2    77.78%         385                27    92.99%          18                13    27.78%
struct_pack/reflection.hpp                             9                 6    33.33%         628                81    87.10%           0                 0         -
struct_pack/size_info.hpp                              2                 0   100.00%          10                 0   100.00%           0                 0         -
struct_pack/tuple.hpp                                  1                 1     0.00%           1                 1     0.00%           0                 0         -
struct_pack/type_calculate.hpp                        21                21     0.00%         479               479     0.00%           0                 0         -
struct_pack/type_id.hpp                                2                 2     0.00%         198               198     0.00%           0                 0         -
struct_pack/util.h                                     5                 3    40.00%          43                14    67.44%           2                 0   100.00%
struct_pack/varint.hpp                                 1                 1     0.00%           3                 3     0.00%           0                 0         -
util/concurrentqueue.h                                79                19    75.95%        1249               552    55.80%         292               155    46.92%
util/dragonbox.h                                      90                50    44.44%         735               388    47.21%          38                34    10.53%
util/dragonbox_to_chars.h                              6                 2    66.67%         440               381    13.41%          54                46    14.81%
util/expected.hpp                                     17                 3    82.35%          21                 3    85.71%           2                 0   100.00%
util/function_name.h                                   1                 1     0.00%           7                 7     0.00%           0                 0         -
util/meta_string.hpp                                  10                 3    70.00%          46                23    50.00%           8                 0   100.00%
util/time_util.h                                      13                13     0.00%         156               156     0.00%           0                 0         -

Files which contain no functions:
struct_pack/marco.h                                    0                 0         -           0                 0         -           0                 0         -
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
TOTAL                                                602               175    70.93%        7413              2840    61.69%        1058               465    56.05%

Copy link

Code Coverage Report
for detail, goto summary download Artifacts

Filename                                       Functions  Missed Functions  Executed       Lines      Missed Lines     Cover    Branches   Missed Branches     Cover
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
coro_io/channel.hpp                                   14                 0   100.00%         105                 3    97.14%          30                 2    93.33%
coro_io/client_pool.hpp                               29                 1    96.55%         358                64    82.12%         140                46    67.14%
coro_io/coro_file.hpp                                 22                 2    90.91%         213                46    78.40%          56                21    62.50%
coro_io/coro_io.hpp                                   48                 1    97.92%         304                 9    97.04%           4                 0   100.00%
coro_io/detail/client_queue.hpp                       10                 1    90.00%          47                 1    97.87%          10                 1    90.00%
coro_io/io_context_pool.hpp                           34                 3    91.18%         206                19    90.78%          26                 6    76.92%
coro_io/rate_limiter.hpp                              13                 1    92.31%          85                 9    89.41%           8                 3    62.50%
coro_rpc/impl/common_service.hpp                       1                 0   100.00%           8                 0   100.00%           4                 0   100.00%
coro_rpc/impl/coro_connection.hpp                     32                 9    71.88%         335               152    54.63%          84                46    45.24%
coro_rpc/impl/coro_rpc_client.hpp                     21                 5    76.19%         164                18    89.02%          44                12    72.73%
coro_rpc/impl/coro_rpc_server.hpp                     13                 0   100.00%         213                26    87.79%          80                37    53.75%
coro_rpc/impl/errno.h                                  9                 4    55.56%          13                 8    38.46%           0                 0         -
coro_rpc/impl/protocol/coro_rpc_protocol.hpp           6                 0   100.00%          84                23    72.62%          24                 9    62.50%
coro_rpc/impl/router.hpp                               5                 0   100.00%          61                 7    88.52%          10                 1    90.00%
easylog.hpp                                            8                 0   100.00%          41                 3    92.68%          12                 4    66.67%
easylog/appender.hpp                                  22                 0   100.00%         266                18    93.23%          88                26    70.45%
easylog/record.hpp                                    17                 0   100.00%         111                 4    96.40%          16                 2    87.50%
struct_pack.hpp                                        3                 2    33.33%          29                 7    75.86%           0                 0         -
struct_pack/calculate_size.hpp                         7                 0   100.00%         215                17    92.09%           6                 5    16.67%
struct_pack/derived_helper.hpp                         2                 2     0.00%           6                 6     0.00%           0                 0         -
struct_pack/endian_wrapper.hpp                         6                 3    50.00%          86                28    67.44%           2                 1    50.00%
struct_pack/error_code.hpp                             6                 6     0.00%          30                30     0.00%           0                 0         -
struct_pack/foreach_macro.h                            1                 1     0.00%           1                 1     0.00%           0                 0         -
struct_pack/md5_constexpr.hpp                          7                 7     0.00%          31                31     0.00%           0                 0         -
struct_pack/packer.hpp                                 9                 2    77.78%         385                27    92.99%          18                13    27.78%
struct_pack/reflection.hpp                             9                 6    33.33%         628                81    87.10%           0                 0         -
struct_pack/size_info.hpp                              2                 0   100.00%          10                 0   100.00%           0                 0         -
struct_pack/tuple.hpp                                  1                 1     0.00%           1                 1     0.00%           0                 0         -
struct_pack/type_calculate.hpp                        21                21     0.00%         479               479     0.00%           0                 0         -
struct_pack/type_id.hpp                                2                 2     0.00%         198               198     0.00%           0                 0         -
struct_pack/util.h                                     5                 3    40.00%          43                14    67.44%           2                 0   100.00%
struct_pack/varint.hpp                                 1                 1     0.00%           3                 3     0.00%           0                 0         -
util/concurrentqueue.h                                79                19    75.95%        1249               546    56.29%         292               146    50.00%
util/dragonbox.h                                      90                50    44.44%         735               388    47.21%          38                34    10.53%
util/dragonbox_to_chars.h                              6                 2    66.67%         440               381    13.41%          54                46    14.81%
util/expected.hpp                                     17                 3    82.35%          21                 3    85.71%           2                 0   100.00%
util/function_name.h                                   1                 1     0.00%           7                 7     0.00%           0                 0         -
util/meta_string.hpp                                  10                 3    70.00%          46                23    50.00%           8                 0   100.00%
util/time_util.h                                      13                13     0.00%         156               156     0.00%           0                 0         -

Files which contain no functions:
struct_pack/marco.h                                    0                 0         -           0                 0         -           0                 0         -
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
TOTAL                                                602               175    70.93%        7413              2837    61.73%        1058               461    56.43%

include/ylt/coro_io/client_pool.hpp Outdated Show resolved Hide resolved
include/ylt/coro_io/client_pool.hpp Outdated Show resolved Hide resolved
include/ylt/coro_io/client_pool.hpp Outdated Show resolved Hide resolved
include/ylt/coro_io/client_pool.hpp Outdated Show resolved Hide resolved
include/ylt/coro_io/client_pool.hpp Outdated Show resolved Hide resolved
include/ylt/coro_io/client_pool.hpp Outdated Show resolved Hide resolved
include/ylt/coro_io/client_pool.hpp Outdated Show resolved Hide resolved
include/ylt/coro_io/client_pool.hpp Outdated Show resolved Hide resolved
Copy link

Code Coverage Report
for detail, goto summary download Artifacts

Filename                                       Functions  Missed Functions  Executed       Lines      Missed Lines     Cover    Branches   Missed Branches     Cover
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
coro_io/channel.hpp                                   14                 0   100.00%         105                 3    97.14%          30                 2    93.33%
coro_io/client_pool.hpp                               29                 1    96.55%         358                63    82.40%         140                47    66.43%
coro_io/coro_file.hpp                                 22                 2    90.91%         213                46    78.40%          56                21    62.50%
coro_io/coro_io.hpp                                   48                 1    97.92%         304                 9    97.04%           4                 0   100.00%
coro_io/detail/client_queue.hpp                       10                 1    90.00%          47                 1    97.87%          10                 0   100.00%
coro_io/io_context_pool.hpp                           34                 3    91.18%         206                19    90.78%          26                 6    76.92%
coro_io/rate_limiter.hpp                              13                 1    92.31%          85                 9    89.41%           8                 3    62.50%
coro_rpc/impl/common_service.hpp                       1                 0   100.00%           8                 0   100.00%           4                 0   100.00%
coro_rpc/impl/coro_connection.hpp                     32                 9    71.88%         335               152    54.63%          84                48    42.86%
coro_rpc/impl/coro_rpc_client.hpp                     21                 5    76.19%         164                18    89.02%          44                12    72.73%
coro_rpc/impl/coro_rpc_server.hpp                     13                 0   100.00%         213                26    87.79%          80                35    56.25%
coro_rpc/impl/errno.h                                  9                 4    55.56%          13                 8    38.46%           0                 0         -
coro_rpc/impl/protocol/coro_rpc_protocol.hpp           6                 0   100.00%          84                23    72.62%          24                 9    62.50%
coro_rpc/impl/router.hpp                               5                 0   100.00%          61                 7    88.52%          10                 1    90.00%
easylog.hpp                                            8                 0   100.00%          41                 3    92.68%          12                 4    66.67%
easylog/appender.hpp                                  22                 0   100.00%         266                18    93.23%          88                26    70.45%
easylog/record.hpp                                    17                 0   100.00%         111                 4    96.40%          16                 2    87.50%
struct_pack.hpp                                        3                 2    33.33%          29                 7    75.86%           0                 0         -
struct_pack/calculate_size.hpp                         7                 0   100.00%         215                17    92.09%           6                 5    16.67%
struct_pack/derived_helper.hpp                         2                 2     0.00%           6                 6     0.00%           0                 0         -
struct_pack/endian_wrapper.hpp                         6                 3    50.00%          86                28    67.44%           2                 1    50.00%
struct_pack/error_code.hpp                             6                 6     0.00%          30                30     0.00%           0                 0         -
struct_pack/foreach_macro.h                            1                 1     0.00%           1                 1     0.00%           0                 0         -
struct_pack/md5_constexpr.hpp                          7                 7     0.00%          31                31     0.00%           0                 0         -
struct_pack/packer.hpp                                 9                 2    77.78%         385                27    92.99%          18                13    27.78%
struct_pack/reflection.hpp                             9                 6    33.33%         628                81    87.10%           0                 0         -
struct_pack/size_info.hpp                              2                 0   100.00%          10                 0   100.00%           0                 0         -
struct_pack/tuple.hpp                                  1                 1     0.00%           1                 1     0.00%           0                 0         -
struct_pack/type_calculate.hpp                        21                21     0.00%         479               479     0.00%           0                 0         -
struct_pack/type_id.hpp                                2                 2     0.00%         198               198     0.00%           0                 0         -
struct_pack/util.h                                     5                 3    40.00%          43                14    67.44%           2                 0   100.00%
struct_pack/varint.hpp                                 1                 1     0.00%           3                 3     0.00%           0                 0         -
util/concurrentqueue.h                                79                19    75.95%        1249               565    54.76%         292               156    46.58%
util/dragonbox.h                                      90                50    44.44%         735               388    47.21%          38                34    10.53%
util/dragonbox_to_chars.h                              6                 2    66.67%         440               381    13.41%          54                46    14.81%
util/expected.hpp                                     17                 3    82.35%          21                 3    85.71%           2                 0   100.00%
util/function_name.h                                   1                 1     0.00%           7                 7     0.00%           0                 0         -
util/meta_string.hpp                                  10                 3    70.00%          46                23    50.00%           8                 0   100.00%
util/time_util.h                                      13                13     0.00%         156               156     0.00%           0                 0         -

Files which contain no functions:
struct_pack/marco.h                                    0                 0         -           0                 0         -           0                 0         -
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
TOTAL                                                602               175    70.93%        7413              2855    61.49%        1058               471    55.48%

Copy link

Code Coverage Report
for detail, goto summary download Artifacts

Filename                                       Functions  Missed Functions  Executed       Lines      Missed Lines     Cover    Branches   Missed Branches     Cover
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
coro_io/channel.hpp                                   14                 0   100.00%         105                 3    97.14%          30                 2    93.33%
coro_io/client_pool.hpp                               29                 1    96.55%         358                57    84.08%         140                43    69.29%
coro_io/coro_file.hpp                                 22                 2    90.91%         213                46    78.40%          56                21    62.50%
coro_io/coro_io.hpp                                   48                 1    97.92%         304                 9    97.04%           4                 0   100.00%
coro_io/detail/client_queue.hpp                       10                 1    90.00%          47                 1    97.87%          10                 1    90.00%
coro_io/io_context_pool.hpp                           34                 3    91.18%         206                19    90.78%          26                 6    76.92%
coro_io/rate_limiter.hpp                              13                 1    92.31%          85                 9    89.41%           8                 3    62.50%
coro_rpc/impl/common_service.hpp                       1                 0   100.00%           8                 0   100.00%           4                 0   100.00%
coro_rpc/impl/coro_connection.hpp                     32                 9    71.88%         335               152    54.63%          84                47    44.05%
coro_rpc/impl/coro_rpc_client.hpp                     21                 5    76.19%         164                18    89.02%          44                11    75.00%
coro_rpc/impl/coro_rpc_server.hpp                     13                 0   100.00%         213                26    87.79%          80                35    56.25%
coro_rpc/impl/errno.h                                  9                 4    55.56%          13                 8    38.46%           0                 0         -
coro_rpc/impl/protocol/coro_rpc_protocol.hpp           6                 0   100.00%          84                23    72.62%          24                 9    62.50%
coro_rpc/impl/router.hpp                               5                 0   100.00%          61                 7    88.52%          10                 1    90.00%
easylog.hpp                                            8                 0   100.00%          41                 3    92.68%          12                 4    66.67%
easylog/appender.hpp                                  22                 0   100.00%         266                18    93.23%          88                26    70.45%
easylog/record.hpp                                    17                 0   100.00%         111                 4    96.40%          16                 2    87.50%
struct_pack.hpp                                        3                 2    33.33%          29                 7    75.86%           0                 0         -
struct_pack/calculate_size.hpp                         7                 0   100.00%         215                17    92.09%           6                 5    16.67%
struct_pack/derived_helper.hpp                         2                 2     0.00%           6                 6     0.00%           0                 0         -
struct_pack/endian_wrapper.hpp                         6                 3    50.00%          86                28    67.44%           2                 1    50.00%
struct_pack/error_code.hpp                             6                 6     0.00%          30                30     0.00%           0                 0         -
struct_pack/foreach_macro.h                            1                 1     0.00%           1                 1     0.00%           0                 0         -
struct_pack/md5_constexpr.hpp                          7                 7     0.00%          31                31     0.00%           0                 0         -
struct_pack/packer.hpp                                 9                 2    77.78%         385                27    92.99%          18                13    27.78%
struct_pack/reflection.hpp                             9                 6    33.33%         628                81    87.10%           0                 0         -
struct_pack/size_info.hpp                              2                 0   100.00%          10                 0   100.00%           0                 0         -
struct_pack/tuple.hpp                                  1                 1     0.00%           1                 1     0.00%           0                 0         -
struct_pack/type_calculate.hpp                        21                21     0.00%         479               479     0.00%           0                 0         -
struct_pack/type_id.hpp                                2                 2     0.00%         198               198     0.00%           0                 0         -
struct_pack/util.h                                     5                 3    40.00%          43                14    67.44%           2                 0   100.00%
struct_pack/varint.hpp                                 1                 1     0.00%           3                 3     0.00%           0                 0         -
util/concurrentqueue.h                                79                19    75.95%        1249               554    55.64%         292               153    47.60%
util/dragonbox.h                                      90                50    44.44%         735               388    47.21%          38                34    10.53%
util/dragonbox_to_chars.h                              6                 2    66.67%         440               381    13.41%          54                46    14.81%
util/expected.hpp                                     17                 3    82.35%          21                 3    85.71%           2                 0   100.00%
util/function_name.h                                   1                 1     0.00%           7                 7     0.00%           0                 0         -
util/meta_string.hpp                                  10                 3    70.00%          46                23    50.00%           8                 0   100.00%
util/time_util.h                                      13                13     0.00%         156               156     0.00%           0                 0         -

Files which contain no functions:
struct_pack/marco.h                                    0                 0         -           0                 0         -           0                 0         -
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
TOTAL                                                602               175    70.93%        7413              2838    61.72%        1058               463    56.24%

@poor-circle poor-circle merged commit ab0fb6b into alibaba:main Apr 10, 2024
33 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants