-
Notifications
You must be signed in to change notification settings - Fork 84
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
fix: enhance connection rate limit #196
fix: enhance connection rate limit #196
Conversation
e0fe870
to
d3e15b9
Compare
2de8851
to
1a86898
Compare
Prior to this change, if connection rate is limited, the acceptors will enter suspending state and stop accepting the sockets leaving the sockets in the system backlog. If the acceptor backlog (default=1024) is filled up, for long enough time to cause the majority of the clients to have closed socket from their end and try to reconnect aggressively, the acceptor may never be able to get a normal socket again. The fix is: in suspending state, accept the sockets and immediately cose them to free up the backlog. The close triggers TCP-RST to cut the TCP graceful close overheads.
85445bd
to
4f1a472
Compare
910c448
to
0031552
Compare
case eval_tune_socket_fun(TuneFun, Sock) of | ||
{ok, Sock} -> | ||
case esockd_connection_sup:start_connection(ConnSup, Sock, UpgradeFuns) of | ||
{ok, NewSock} -> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why the socket is changed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the socket does not change most of the time, but the API is designed to allow it to change.
{ok, _Pid} -> | ||
%% Inc accepted stats. | ||
inc_stats(State, accepted), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why move to here? I think the old code looks fine. the socket is indeed accepted isn't it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there was previously no clear definition what accepted
means.
and there was no counters for error cases.
now it means: accepted from the listener backlog, and successfully started an owner process.
and this counter is disjoint from error cases.
a2d6096
to
73f9fab
Compare
esslaccept error reason has been deleted since OTP 16
when system limit is reached, it does not make sense to continue accepting new connections aggressively
73f9fab
to
10475ca
Compare
Fixes: emqx/emqx#14145
Prior to this change, if connection rate is limited, the acceptors will enter suspending state and stop accepting the sockets leaving the sockets in the system backlog.
If the acceptor backlog (default=1024) is filled up, for long enough time to cause the majority of the clients to have closed socket from their end and try to reconnect aggressively, the acceptor may never be able to get a normal socket again.
The fix is: in suspending state, accept the sockets and immediately close them to free up the backlog.
The close triggers TCP-RST to cut the TCP graceful close overheads.