Changeset 718
- Timestamp:
- 04/23/07 19:15:45 (2 years ago)
- Files:
-
- cherokee/trunk/ChangeLog (modified) (1 diff)
- cherokee/trunk/cherokee/fdpoll.c (modified) (1 diff)
- cherokee/trunk/cherokee/macros.h (modified) (1 diff)
- cherokee/trunk/cherokee/server.c (modified) (8 diffs)
- cherokee/trunk/cherokee/source.c (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
cherokee/trunk/ChangeLog
r716 r718 1 2007-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 1 23 2007-04-22 Alvaro Lopez Ortega <alvaro@alobbs.com> 2 24 cherokee/trunk/cherokee/fdpoll.c
r702 r718 158 158 cherokee_fdpoll_is_full (cherokee_fdpoll_t *fdp) 159 159 { 160 return (fdp->npollfds >= (fdp->nfiles - 2));160 return (fdp->npollfds >= fdp->nfiles); 161 161 } 162 162 cherokee/trunk/cherokee/macros.h
r702 r718 100 100 #define DEFAULT_LOGGER_MAX_BUFSIZE 32768 101 101 #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 103 118 104 119 #define IOCACHE_MAX_FILE_SIZE 50000 cherokee/trunk/cherokee/server.c
r706 r718 91 91 #define ENTRIES "core,server" 92 92 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 93 98 ret_t 94 99 cherokee_server_new (cherokee_server_t **srv) … … 636 641 /* File descriptor limit 637 642 */ 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); 639 644 640 645 /* Threading stuff … … 644 649 } else { 645 650 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)); 647 652 648 653 switch (srv->thread_policy) { … … 733 738 { 734 739 ret_t ret; 735 int i, fds_per_thread , max_fds;740 int i, fds_per_thread; 736 741 #ifdef HAVE_PTHREAD 737 742 int thr_fds, spare_fds; 738 743 #endif 739 744 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) 744 748 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; 748 754 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; 761 759 #ifdef HAVE_PTHREAD 762 760 thr_fds = fds_per_thread * srv->thread_num; 763 spare_fds = max_fds - thr_fds;761 spare_fds = srv->max_fds - thr_fds; 764 762 #endif 765 763 … … 828 826 } 829 827 } 830 828 831 829 ret = cherokee_virtual_server_has_tls (srv->vserver_default); 832 830 if (ret == ret_ok) { … … 954 952 if (unlikely(ret < ret_ok)) 955 953 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); 958 972 return ret_error; 959 973 } … … 995 1009 srv->thread_num = srv->ncpus * 5; 996 1010 } 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; 999 1013 if (srv->thread_num < 1) 1000 1014 srv->thread_num = 1; … … 1009 1023 srv->max_conn_reuse = DEFAULT_CONN_REUSE; 1010 1024 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; 1016 1027 1017 1028 /* Get the passwd file entry before chroot cherokee/trunk/cherokee/source.c
r690 r718 74 74 */ 75 75 if (! cherokee_buffer_is_empty (&src->unix_socket)) { 76 ret = cherokee_socket_close (sock); 76 77 ret = cherokee_socket_set_client (sock, AF_UNIX); 77 78 if (ret != ret_ok) return ret; … … 85 86 /* INET socket 86 87 */ 88 ret = cherokee_socket_close (sock); 87 89 ret = cherokee_socket_set_client (sock, AF_INET); 88 90 if (ret != ret_ok) return ret; 89 91 90 92 ret = cherokee_resolv_cache_get_host (resolv, src->host.buf, sock); 91 93 if (ret != ret_ok) return ret;