performance tuning
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@12495 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
parent
ec60a3ae0b
commit
e599375a82
38
src/switch.c
38
src/switch.c
|
@ -37,6 +37,12 @@
|
||||||
#define _XOPEN_SOURCE 600
|
#define _XOPEN_SOURCE 600
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifndef WIN32
|
||||||
|
#ifdef HAVE_SETRLIMIT
|
||||||
|
#include <sys/resource.h>
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
#include <switch.h>
|
#include <switch.h>
|
||||||
#include "private/switch_core_pvt.h"
|
#include "private/switch_core_pvt.h"
|
||||||
|
|
||||||
|
@ -274,6 +280,10 @@ int main(int argc, char *argv[])
|
||||||
switch_status_t destroy_status;
|
switch_status_t destroy_status;
|
||||||
switch_file_t *fd;
|
switch_file_t *fd;
|
||||||
switch_memory_pool_t *pool = NULL;
|
switch_memory_pool_t *pool = NULL;
|
||||||
|
#ifdef HAVE_SETRLIMIT
|
||||||
|
struct rlimit rlp;
|
||||||
|
int waste = 0;
|
||||||
|
#endif
|
||||||
|
|
||||||
if (argv[0] && strstr(argv[0], "freeswitchd")) {
|
if (argv[0] && strstr(argv[0], "freeswitchd")) {
|
||||||
nc++;
|
nc++;
|
||||||
|
@ -291,6 +301,7 @@ int main(int argc, char *argv[])
|
||||||
#endif
|
#endif
|
||||||
"\t-help -- this message\n"
|
"\t-help -- this message\n"
|
||||||
#ifdef HAVE_SETRLIMIT
|
#ifdef HAVE_SETRLIMIT
|
||||||
|
"\t-waste -- allow memory waste\n"
|
||||||
"\t-core -- dump cores\n"
|
"\t-core -- dump cores\n"
|
||||||
#endif
|
#endif
|
||||||
"\t-hp -- enable high priority settings\n"
|
"\t-hp -- enable high priority settings\n"
|
||||||
|
@ -374,6 +385,7 @@ int main(int argc, char *argv[])
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (argv[x] && !strcmp(argv[x], "-uninstall")) {
|
if (argv[x] && !strcmp(argv[x], "-uninstall")) {
|
||||||
x++;
|
x++;
|
||||||
if (argv[x] && strlen(argv[x])) {
|
if (argv[x] && strlen(argv[x])) {
|
||||||
|
@ -429,13 +441,17 @@ int main(int argc, char *argv[])
|
||||||
#endif
|
#endif
|
||||||
#ifdef HAVE_SETRLIMIT
|
#ifdef HAVE_SETRLIMIT
|
||||||
if (argv[x] && !strcmp(argv[x], "-core")) {
|
if (argv[x] && !strcmp(argv[x], "-core")) {
|
||||||
struct rlimit rlp;
|
|
||||||
memset(&rlp, 0, sizeof(rlp));
|
memset(&rlp, 0, sizeof(rlp));
|
||||||
rlp.rlim_cur = RLIM_INFINITY;
|
rlp.rlim_cur = RLIM_INFINITY;
|
||||||
rlp.rlim_max = RLIM_INFINITY;
|
rlp.rlim_max = RLIM_INFINITY;
|
||||||
setrlimit(RLIMIT_CORE, &rlp);
|
setrlimit(RLIMIT_CORE, &rlp);
|
||||||
known_opt++;
|
known_opt++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (argv[x] && !strcmp(argv[x], "-waste")) {
|
||||||
|
waste++;
|
||||||
|
known_opt++;
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (argv[x] && !strcmp(argv[x], "-hp")) {
|
if (argv[x] && !strcmp(argv[x], "-hp")) {
|
||||||
|
@ -600,12 +616,32 @@ int main(int argc, char *argv[])
|
||||||
#endif
|
#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) {
|
if (high_prio) {
|
||||||
set_high_priority();
|
set_high_priority();
|
||||||
}
|
}
|
||||||
|
|
||||||
switch_core_setrlimits();
|
switch_core_setrlimits();
|
||||||
|
|
||||||
|
|
||||||
#ifndef WIN32
|
#ifndef WIN32
|
||||||
if (runas_user || runas_group) {
|
if (runas_user || runas_group) {
|
||||||
if (change_user_group(runas_user, runas_group) < 0) {
|
if (change_user_group(runas_user, runas_group) < 0) {
|
||||||
|
|
|
@ -792,7 +792,7 @@ SWITCH_DECLARE(void) switch_core_setrlimits(void)
|
||||||
#ifndef __FreeBSD__
|
#ifndef __FreeBSD__
|
||||||
memset(&rlp, 0, sizeof(rlp));
|
memset(&rlp, 0, sizeof(rlp));
|
||||||
rlp.rlim_cur = SWITCH_THREAD_STACKSIZE;
|
rlp.rlim_cur = SWITCH_THREAD_STACKSIZE;
|
||||||
rlp.rlim_max = SWITCH_SYSTEM_THREAD_STACKSIZE;
|
rlp.rlim_max = SWITCH_THREAD_STACKSIZE;
|
||||||
setrlimit(RLIMIT_STACK, &rlp);
|
setrlimit(RLIMIT_STACK, &rlp);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -808,6 +808,8 @@ SWITCH_DECLARE(void) switch_core_setrlimits(void)
|
||||||
setrlimit(RLIMIT_CPU, &rlp);
|
setrlimit(RLIMIT_CPU, &rlp);
|
||||||
setrlimit(RLIMIT_DATA, &rlp);
|
setrlimit(RLIMIT_DATA, &rlp);
|
||||||
setrlimit(RLIMIT_FSIZE, &rlp);
|
setrlimit(RLIMIT_FSIZE, &rlp);
|
||||||
|
setrlimit(RLIMIT_NPROC, &rlp);
|
||||||
|
setrlimit(RLIMIT_RTPRIO, &rlp);
|
||||||
#if !defined(__OpenBSD__) && !defined(__NetBSD__)
|
#if !defined(__OpenBSD__) && !defined(__NetBSD__)
|
||||||
setrlimit(RLIMIT_AS, &rlp);
|
setrlimit(RLIMIT_AS, &rlp);
|
||||||
#endif
|
#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_threadattr_detach_set(thd_attr, 1);
|
||||||
switch_thread_create(&thread, thd_attr, system_thread, sth, sth->pool);
|
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) {
|
if (wait) {
|
||||||
switch_thread_cond_wait(sth->cond, sth->mutex);
|
switch_thread_cond_wait(sth->cond, sth->mutex);
|
||||||
ret = sth->ret;
|
ret = sth->ret;
|
||||||
|
|
Loading…
Reference in New Issue