Changeset 718

Show
Ignore:
Timestamp:
04/23/07 19:15:45 (2 years ago)
Author:
alo
Message:

--

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • cherokee/trunk/ChangeLog

    r716 r718  
     12007-04-22  A.D.F  <adefacc@tin.it> 
     2 
     3        * cherokee/macros.h: 
     4        - new macros to handler minimum number of system fds, 
     5          spare fds (used by standard I/O streams, i.e. stdin, etc.) 
     6          and minimum number of file descriptors really available 
     7          to Cherokee. 
     8 
     9        * cherokee/source.c: 
     10        - fixed a socket fd leak in cherokee_source_connect(), 
     11          that function does both the open and the connect, 
     12          if it fails, caller may retry it, but of course 
     13          if socket is open then it must be closed before the retry. 
     14 
     15        * cherokee/server.c: 
     16        - fix the max number of threads againts max. number of 
     17          max_fds. 
     18 
     19        * cherokee/fdpoll.c: 
     20        - now that we leave half of fds free to be used to open files, etc. 
     21          we can raise the max_fds limit to its real value 
     22 
    1232007-04-22  Alvaro Lopez Ortega  <alvaro@alobbs.com> 
    224 
  • cherokee/trunk/cherokee/fdpoll.c

    r702 r718  
    158158cherokee_fdpoll_is_full (cherokee_fdpoll_t *fdp) 
    159159{ 
    160         return (fdp->npollfds >= (fdp->nfiles - 2)); 
     160        return (fdp->npollfds >= fdp->nfiles); 
    161161} 
    162162 
  • cherokee/trunk/cherokee/macros.h

    r702 r718  
    100100#define DEFAULT_LOGGER_MAX_BUFSIZE    32768 
    101101#define LOGGER_MAX_BUFSIZE            (4 * 1024 * 1024) 
    102 #define MIN_SYSTEM_FD_NUM             10 
     102#define MIN_SYSTEM_FD_NUM             20        /* range: 16 - 64 */ 
     103#define MIN_SPARE_FDS                 10        /* range:  8 - 20 */ 
     104#define MIN_MAX_FDS                    4        /* range:  4 ... 32000 */ 
     105 
     106#if (MIN_SYSTEM_FD_NUM < 16)  
     107#error MIN_SYSTEM_FD_NUM too low, < 16 ! 
     108#endif 
     109#if (MIN_SPARE_FDS < 8) 
     110#error MIN_SPARE_FDS too low, < 8 ! 
     111#endif 
     112#if (MIN_MAX_FDS < 4) 
     113#error MIN_MAX_FDS too low, < 4 ! 
     114#endif 
     115#if (((MIN_SYSTEM_FD_NUM - MIN_SPARE_FDS) / 2) < MIN_MAX_FDS) 
     116#error MIN_SYSTEM_FD_NUM too low or MIN_SPARE FDS too high ! 
     117#endif 
    103118 
    104119#define IOCACHE_MAX_FILE_SIZE            50000 
  • cherokee/trunk/cherokee/server.c

    r706 r718  
    9191#define ENTRIES "core,server" 
    9292 
     93/* Number of spare fds, used for stdin, stdout, stderr, etc. 
     94 * Set it between 5 and 20. 
     95 */ 
     96#define MIN_SPARE_FDS   10 
     97 
    9398ret_t 
    9499cherokee_server_new  (cherokee_server_t **srv) 
     
    636641        /* File descriptor limit 
    637642         */ 
    638         cherokee_buffer_add_va (&n, ", %d fds limit", srv->system_fd_limit); 
     643        cherokee_buffer_add_va (&n, ", %d fds system limit, max. %d connections ", srv->system_fd_limit, srv->max_fds); 
    639644 
    640645        /* Threading stuff 
     
    644649        } else { 
    645650                cherokee_buffer_add_va (&n, ", %d threads", srv->thread_num); 
    646                 cherokee_buffer_add_va (&n, ", %d fds in each", srv->system_fd_limit / (srv->thread_num));     
     651                cherokee_buffer_add_va (&n, ", %d fds per thread", (srv->max_fds / srv->thread_num));  
    647652 
    648653                switch (srv->thread_policy) { 
     
    733738{        
    734739        ret_t ret; 
    735         int   i, fds_per_thread, max_fds
     740        int   i, fds_per_thread
    736741#ifdef HAVE_PTHREAD 
    737742        int   thr_fds, spare_fds; 
    738743#endif 
    739744 
    740         /* Leave some spare fds. 
    741          */ 
    742         if (srv->system_fd_limit < MIN_SYSTEM_FD_NUM) { 
    743                 PRINT_ERROR("srv->system_fd_limit %d < %d !\n", srv->system_fd_limit, MIN_SYSTEM_FD_NUM); 
     745        /* Verify max_fds value 
     746         */ 
     747        if (srv->max_fds < MIN_MAX_FDS) 
    744748                return ret_error; 
    745         } 
    746         if (srv->system_fd_limit > 1024) 
    747                 max_fds = srv->system_fd_limit - 20; 
     749 
     750        /* Set fd upper limit for threads. 
     751         */ 
     752        if (srv->thread_num > srv->max_fds) 
     753                srv->thread_num = srv->max_fds; 
    748754        else 
    749         if (srv->system_fd_limit > 100) 
    750                 max_fds = srv->system_fd_limit - 10; 
    751         else 
    752                 max_fds = srv->system_fd_limit - 5; 
    753  
    754         /* Set fd upper limit for threads. 
    755          * FIXME: when using a very high number of threads 
    756          *        some fds may be left unused (not a big problem). 
    757          */ 
    758         if (srv->thread_num > max_fds) 
    759                 srv->thread_num = max_fds; 
    760         fds_per_thread = max_fds / srv->thread_num; 
     755        if (srv->thread_num < 1) 
     756                srv->thread_num = 1; 
     757 
     758        fds_per_thread = srv->max_fds / srv->thread_num; 
    761759#ifdef HAVE_PTHREAD 
    762760        thr_fds = fds_per_thread * srv->thread_num; 
    763         spare_fds = max_fds - thr_fds; 
     761        spare_fds = srv->max_fds - thr_fds; 
    764762#endif 
    765763 
     
    828826                } 
    829827        } 
    830          
     828 
    831829        ret = cherokee_virtual_server_has_tls (srv->vserver_default); 
    832830        if (ret == ret_ok) { 
     
    954952        if (unlikely(ret < ret_ok)) 
    955953                return ret; 
    956         if (srv->system_fd_limit < 10) { 
    957                 PRINT_ERROR("Number of system files too low (%d < 10) !\n", srv->system_fd_limit); 
     954 
     955        /* Verify if there are enough fds. 
     956         */ 
     957        if (srv->system_fd_limit < MIN_SYSTEM_FD_NUM) { 
     958                PRINT_ERROR("Number of system files too low (%d < %d) !\n", srv->system_fd_limit, MIN_SYSTEM_FD_NUM); 
     959                return ret_error; 
     960        } 
     961 
     962        /* Set max_fds used for max. number of accepted connections. 
     963         * NOTE: max_fds is roughly half of max. system limit because 
     964         *       for each accepted connection we reserve 1 spare fd 
     965         *       that can be used for opening a file or for making 
     966         *       a new connection to a backend server 
     967         *       (i.e. FastCGI, SCGI, mirror, etc.). 
     968         */ 
     969        srv->max_fds = (srv->system_fd_limit - MIN_SPARE_FDS) / 2; 
     970        if (srv->max_fds < MIN_MAX_FDS) { 
     971                PRINT_ERROR("Number of max. connection too low %d < %d !\n", srv->max_fds, MIN_MAX_FDS); 
    958972                return ret_error; 
    959973        } 
     
    9951009                srv->thread_num = srv->ncpus * 5; 
    9961010        } 
    997         if (srv->thread_num + 5 >= srv->system_fd_limit) { 
    998                 srv->thread_num = srv->system_fd_limit - 5
     1011        if (srv->thread_num > srv->max_fds) { 
     1012                srv->thread_num = srv->max_fds
    9991013                if (srv->thread_num < 1) 
    10001014                        srv->thread_num = 1; 
     
    10091023                srv->max_conn_reuse = DEFAULT_CONN_REUSE; 
    10101024 
    1011         if (srv->max_conn_reuse > srv->system_fd_limit - 10) 
    1012                 srv->max_conn_reuse = srv->system_fd_limit - 10; 
    1013  
    1014         if (srv->max_conn_reuse < 0) 
    1015                 srv->max_conn_reuse = 0; 
     1025        if (srv->max_conn_reuse > srv->max_fds) 
     1026                srv->max_conn_reuse = srv->max_fds; 
    10161027 
    10171028        /* Get the passwd file entry before chroot 
  • cherokee/trunk/cherokee/source.c

    r690 r718  
    7474         */ 
    7575        if (! cherokee_buffer_is_empty (&src->unix_socket)) { 
     76                ret = cherokee_socket_close (sock); 
    7677                ret = cherokee_socket_set_client (sock, AF_UNIX); 
    7778                if (ret != ret_ok) return ret; 
     
    8586        /* INET socket 
    8687         */ 
     88        ret = cherokee_socket_close (sock); 
    8789        ret = cherokee_socket_set_client (sock, AF_INET); 
    8890        if (ret != ret_ok) return ret; 
    89          
     91 
    9092        ret = cherokee_resolv_cache_get_host (resolv, src->host.buf, sock); 
    9193        if (ret != ret_ok) return ret;