Browse Source

Listen with the maximum backlog when we first start for more seamless restarts and then drop to the minimum afterwards to effectively ratelimit new connections

master
Con Kolivas 10 years ago
parent
commit
c8627c0d1b
  1. 12
      src/connector.c

12
src/connector.c

@ -294,8 +294,8 @@ void *receiver(void *arg)
conn_instance_t *ci = (conn_instance_t *)arg; conn_instance_t *ci = (conn_instance_t *)arg;
client_instance_t *client, *tmp; client_instance_t *client, *tmp;
int ret, nfds, i, maxfds = 1; int ret, nfds, i, maxfds = 1;
bool update, maxconn = true;
struct pollfd *fds; struct pollfd *fds;
bool update;
rename_proc("creceiver"); rename_proc("creceiver");
@ -379,6 +379,14 @@ repoll:
if (update) if (update)
goto rebuild_fds; goto rebuild_fds;
else if (unlikely(maxconn)) {
/* When we first start we listen to as many connections as
* possible. Once we stop receiving connections we drop the
* listen to the minimum to effectively ratelimit how fast we
* can receive connections. */
maxconn = false;
listen(ci->serverfd, 0);
}
goto repoll; goto repoll;
out: out:
free(fds); free(fds);
@ -748,7 +756,7 @@ int connector(proc_instance_t *pi)
if (tries) if (tries)
LOGWARNING("Connector successfully bound to socket"); LOGWARNING("Connector successfully bound to socket");
ret = listen(sockd, 10); ret = listen(sockd, SOMAXCONN);
if (ret < 0) { if (ret < 0) {
LOGERR("Connector failed to listen on socket"); LOGERR("Connector failed to listen on socket");
Close(sockd); Close(sockd);

Loading…
Cancel
Save