From: Josh G. <ja...@us...> - 2003-10-25 09:35:05
|
Update of /cvsroot/gift/OpenFT/src In directory sc8-pr-cvs1:/tmp/cvs-serv4134/src Modified Files: ft_conn.c Log Message: fun with getrlimit Index: ft_conn.c =================================================================== RCS file: /cvsroot/gift/OpenFT/src/ft_conn.c,v retrieving revision 1.46 retrieving revision 1.47 diff -C2 -d -r1.46 -r1.47 *** ft_conn.c 11 Sep 2003 12:51:43 -0000 1.46 --- ft_conn.c 25 Oct 2003 09:24:12 -0000 1.47 *************** *** 21,24 **** --- 21,44 ---- #include "ft_conn.h" + #ifdef HAVE_SYS_TIME_H + # include <sys/time.h> + #endif /* HAVE_SYS_TIME_H */ + + /* TODO: move the RLIMIT_OFILE mess to autoconf */ + #ifdef HAVE_SYS_RESOURCE_H + # include <sys/resource.h> /* getrlimit/setrlimit */ + # ifndef RLIMIT_OFILE + # ifdef RLIMIT_NOFILE + # define RLIMIT_OFILE RLIMIT_NOFILE + # else /* !RLIMIT_NOFILE */ + # define RLIMIT_OFILE 7 + # endif /* RLIMIT_NOFILE */ + # endif /* RLIMIT_OFILE */ + #endif /* HAVE_SYS_RESOURCE_H */ + + #ifdef HAVE_UNISTD_H + # include <unistd.h> + #endif /* HAVE_UNISTD_H */ + /*****************************************************************************/ *************** *** 467,483 **** } ! BOOL ft_conn_initial (void) { ! int n; ! int weight = FT_CFG_INITIAL_WEIGHT; ! /* precalculate some stuff for ft_conn_auth to work properly */ ! if ((max_active = FT_CFG_MAX_ACTIVE) == -1) { ! int max_child = FT_CFG_MAX_CHILDREN; if (FT_SELF->klass & FT_NODE_SEARCH) ! max_active = CLAMP ((max_child + 200), 200, (896 - max_child)); } /* we need some nodes to work with! */ --- 487,558 ---- } ! static int get_fd_limit (void) { ! int limit = -1; ! #ifdef HAVE_SYS_RESOURCE_H ! struct rlimit rlim; ! int ret; ! if ((ret = getrlimit (RLIMIT_OFILE, &rlim)) != 0) { ! FT->err (FT, "getrlimit: %s", GIFT_STRERROR()); ! return limit; ! } ! ! /* make sure we return a meaningful value even if setrlimit fails */ ! limit = (int)rlim.rlim_cur; ! ! /* try to set the new rlimit as high as we are allowed, within reason of ! * course */ ! rlim.rlim_cur = MAX (rlim.rlim_max, 4096); ! ! if ((ret = getrlimit (RLIMIT_OFILE, &rlim)) != 0) ! { ! FT->err (FT, "setrlimit: %s", GIFT_STRERROR()); ! return limit; ! } ! ! limit = rlim.rlim_cur; ! #endif /* HAVE_SYS_RESOURCE_H */ ! ! return limit; ! } ! ! static int get_max_active (void) ! { ! int nconns; ! int fdlim; ! ! /* the default (-1) asks us to make an educated guess */ ! if ((nconns = FT_CFG_MAX_ACTIVE) == -1) ! { ! int nchildren = FT_CFG_MAX_CHILDREN; if (FT_SELF->klass & FT_NODE_SEARCH) ! nconns = (3 * nchildren) / 2; /* n + (n / 2) */ ! else ! nconns = 600; ! } ! ! /* apply pragmatic clamps to the max_active setting */ ! if ((fdlim = get_fd_limit ()) != -1) ! { ! if (nconns > fdlim) ! { ! FT->warn (FT, "clamping max_active to %d!", fdlim); ! nconns = fdlim; ! } } + + return nconns; + } + + BOOL ft_conn_initial (void) + { + int n; + int weight = FT_CFG_INITIAL_WEIGHT; + + /* determine the maximum number of connections to allow */ + max_active = get_max_active (); /* we need some nodes to work with! */ |