Author: anthm Date: Fri Mar 6 20:20:29 2009 New Revision: 12495 Log: performance tuning Modified: freeswitch/trunk/src/switch.c freeswitch/trunk/src/switch_core.c Modified: freeswitch/trunk/src/switch.c ============================================================================== --- freeswitch/trunk/src/switch.c (original) +++ freeswitch/trunk/src/switch.c Fri Mar 6 20:20:29 2009 @@ -37,6 +37,12 @@ #define _XOPEN_SOURCE 600 #endif +#ifndef WIN32 +#ifdef HAVE_SETRLIMIT +#include <sys/resource.h> +#endif +#endif + #include <switch.h> #include "private/switch_core_pvt.h" @@ -274,6 +280,10 @@ switch_status_t destroy_status; switch_file_t *fd; switch_memory_pool_t *pool = NULL; +#ifdef HAVE_SETRLIMIT + struct rlimit rlp; + int waste = 0; +#endif if (argv[0] && strstr(argv[0], "freeswitchd")) { nc++; @@ -291,6 +301,7 @@ #endif "\t-help -- this message\n" #ifdef HAVE_SETRLIMIT + "\t-waste -- allow memory waste\n" "\t-core -- dump cores\n" #endif "\t-hp -- enable high priority settings\n" @@ -374,6 +385,7 @@ exit(0); } } + if (argv[x] && !strcmp(argv[x], "-uninstall")) { x++; if (argv[x] && strlen(argv[x])) { @@ -429,13 +441,17 @@ #endif #ifdef HAVE_SETRLIMIT if (argv[x] && !strcmp(argv[x], "-core")) { - struct rlimit rlp; memset(&rlp, 0, sizeof(rlp)); rlp.rlim_cur = RLIM_INFINITY; rlp.rlim_max = RLIM_INFINITY; setrlimit(RLIMIT_CORE, &rlp); known_opt++; } + + if (argv[x] && !strcmp(argv[x], "-waste")) { + waste++; + known_opt++; + } #endif if (argv[x] && !strcmp(argv[x], "-hp")) { @@ -600,12 +616,32 @@ #endif } +#ifdef HAVE_SETRLIMIT + if (!waste) { + memset(&rlp, 0, sizeof(rlp)); + getrlimit(RLIMIT_STACK, &rlp); + if (rlp.rlim_max > SWITCH_THREAD_STACKSIZE) { + memset(&rlp, 0, sizeof(rlp)); + rlp.rlim_cur = SWITCH_THREAD_STACKSIZE; + rlp.rlim_max = SWITCH_THREAD_STACKSIZE; + setrlimit(RLIMIT_STACK, &rlp); + fprintf(stderr, "Error: stacksize %d is too large: run ulimit -s %d or run %s -waste.\nauto-adjusting stack size for optimal performance....\n", + SWITCH_THREAD_STACKSIZE / 1024, SWITCH_THREAD_STACKSIZE / 1024, argv[0]); + return (int)execv(argv[0], argv); + } + } +#endif + + + + if (high_prio) { set_high_priority(); } switch_core_setrlimits(); + #ifndef WIN32 if (runas_user || runas_group) { if (change_user_group(runas_user, runas_group) < 0) { Modified: freeswitch/trunk/src/switch_core.c ============================================================================== --- freeswitch/trunk/src/switch_core.c (original) +++ freeswitch/trunk/src/switch_core.c Fri Mar 6 20:20:29 2009 @@ -792,7 +792,7 @@ #ifndef __FreeBSD__ memset(&rlp, 0, sizeof(rlp)); rlp.rlim_cur = SWITCH_THREAD_STACKSIZE; - rlp.rlim_max = SWITCH_SYSTEM_THREAD_STACKSIZE; + rlp.rlim_max = SWITCH_THREAD_STACKSIZE; setrlimit(RLIMIT_STACK, &rlp); #endif @@ -808,6 +808,8 @@ setrlimit(RLIMIT_CPU, &rlp); setrlimit(RLIMIT_DATA, &rlp); setrlimit(RLIMIT_FSIZE, &rlp); + setrlimit(RLIMIT_NPROC, &rlp); + setrlimit(RLIMIT_RTPRIO, &rlp); #if !defined(__OpenBSD__) && !defined(__NetBSD__) setrlimit(RLIMIT_AS, &rlp); #endif @@ -1632,6 +1634,15 @@ switch_threadattr_detach_set(thd_attr, 1); switch_thread_create(&thread, thd_attr, system_thread, sth, sth->pool); + +#if defined(HAVE_SETRLIMIT) && !defined(__FreeBSD__) + rlim.rlim_cur = SWITCH_THREAD_STACKSIZE; + rlim.rlim_max = SWITCH_THREAD_STACKSIZE; + if (setrlimit(RLIMIT_STACK, &rlim) < 0) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Setting stack size failed!\n"); + } +#endif + if (wait) { switch_thread_cond_wait(sth->cond, sth->mutex); ret = sth->ret;