performance tuning

git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@12495 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
Anthony Minessale 2009-03-07 02:20:29 +00:00
parent ec60a3ae0b
commit e599375a82
2 changed files with 49 additions and 2 deletions

View File

@ -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 @@ int main(int argc, char *argv[])
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 @@ int main(int argc, char *argv[])
#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 @@ int main(int argc, char *argv[])
exit(0);
}
}
if (argv[x] && !strcmp(argv[x], "-uninstall")) {
x++;
if (argv[x] && strlen(argv[x])) {
@ -429,13 +441,17 @@ int main(int argc, char *argv[])
#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 @@ int main(int argc, char *argv[])
#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) {

View File

@ -792,7 +792,7 @@ SWITCH_DECLARE(void) switch_core_setrlimits(void)
#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 @@ SWITCH_DECLARE(void) switch_core_setrlimits(void)
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_DECLARE(int) switch_system(const char *cmd, switch_bool_t wait)
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;