2012-02-28 20 views
1

我已經創建了簡單的基於evhttp的服務器。使用libevent的evhttp服務器打開的文件太多

#include <stdlib.h> 
#include <stdio.h> 
#include <string.h> 
#include <event.h> 
#include <evhttp.h> 

void 
handler(struct evhttp_request *req, void *arg) { 
    struct evbuffer *buf; 
    buf = evbuffer_new(); 

    if(buf == NULL) { 
    fprintf(stderr, "ERROR: Failed to create response buffer\n"); 
    exit(EXIT_FAILURE); 
    } 

    evbuffer_add_printf(buf, "Server called"); 
    evhttp_send_reply(req, HTTP_OK, "OK", buf); 
} 

int 
main(int argc, char **argv) { 
    struct evhttp *http; 

    event_init(); 
    http = evhttp_start("0.0.0.0", 8081); 

    evhttp_set_gencb(http, handler, NULL); 

    event_dispatch(); 
    evhttp_free(http); 

    exit(EXIT_SUCCESS); 
} 

當我開始使用

ab -r -n 1000 -c 50 http://0.0.0.0:8081/ 

標杆它我得到這些警告在一些數量的嘗試:

[warn] Error from accept() call: Too many open files 

它還挺我沒有關閉套接字...併發級別50旨在只有50個套接字將被使用一次,對吧?

我應該關閉處理函數中的套接字嗎?

+0

我想如果它是「evbuffer_free(but)」 – 2012-02-28 01:38:47

回答

0

我開始使用event2/* libs並在處理函數結束時添加了evbuffer_free(buf)並完成了這項工作。

1

設置爲打開文件描述符的ulimit是什麼?例如。嘗試執行'ulimit -n'命令(不含引號)。這些是允許在應用程序中打開的文件描述符的數量。增加你可以使用ulimit命令。例如 ulimit -n 10240

+0

我有無限數量的描述符設置,所以這不是問題。 – 2012-03-25 20:32:40