4

I want to control limit of possible libevent-http connections per process.

How can i do that ?

I didn't found any info in documentation, please help!

I think that if i didn't limit number of connections - system can crash. Project is very high load.

ev_base = event_init();
ev_http = evhttp_new(ev_base);
// limit http connections here... how can i do that?
artyomboyko
  • 2,781
  • 5
  • 40
  • 54
  • Is setrlimit(RLIMIT_NOFILE... What i'm looking for ? – artyomboyko Jul 02 '11 at 14:30
  • If the system can crash from resource exhaustion, you probably need to disable overcommit. On Linux, `echo "2" > /proc/sys/vm/overcommit_memory`. You probably want to limit connections too, but disabling overcommit should be the first step in setting up any production Linux server. – R.. GitHub STOP HELPING ICE Jul 02 '11 at 16:22

1 Answers1

3
struct evconnlistener *
evconnlistener_new(struct event_base *base,
    evconnlistener_cb cb, void *ptr, unsigned flags, int backlog,
    evutil_socket_t fd)

The backlog is what you want to modify. Internally they call:

listen(fd, backlog)

However in their http library they fix the backlog to 128:

evhttp_bind_socket_with_handle(struct evhttp *http, const char *address, ev_uint16_t port)
{
    [...]
        if (listen(fd, 128) == -1) {
                event_sock_warn(fd, "%s: listen", __func__);
                evutil_closesocket(fd);
                return (NULL);
        }
    [...]
}
whoplisp
  • 2,508
  • 16
  • 19