Commit 324c41ba authored by sbbs's avatar sbbs
Browse files

Fixed high-CPU utilization after server recycling issue: if the sem_chk_freq

value is missing or set to 0 in the sbbs.ini file, the sanity checking this
value (setting it to 2 seconds) will not occur after a server recycle and the
sbbs.ini is re-parsed. So if for any reason, the sem_chk_freq value becomes
0, these server threads won't hog the CPU because they all YIELD at the
top of thier main loops.

Also, changed all the thread names (e.g. adding "sbbs/" prefix), so they're
more sensible in the Linux 'top' output.

Also, started adding 'vi' modelines to auto-set tabstops when using vi/vim.
parent dad8799c
/* ftpsrvr.c */
/* Synchronet FTP server */
/* $Id$ */
// vi: tabstop=4
/****************************************************************************
* @format.tab-size 4 (Plain Text/Source Code File Header) *
......@@ -1251,7 +1250,7 @@ static void send_thread(void* arg)
xfer=*(xfer_t*)arg;
free(arg);
SetThreadName("FTP Send");
SetThreadName("sbbs/FTP Send");
thread_up(TRUE /* setuid */);
length=flength(xfer.filename);
......@@ -1376,7 +1375,7 @@ static void send_thread(void* arg)
}
total+=wr;
*xfer.lastactive=time(NULL);
YIELD();
//YIELD();
}
if((i=ferror(fp))!=0)
......@@ -1511,7 +1510,7 @@ static void receive_thread(void* arg)
xfer=*(xfer_t*)arg;
free(arg);
SetThreadName("FTP RECV");
SetThreadName("sbbs/FTP Receive");
thread_up(TRUE /* setuid */);
if((fp=fopen(xfer.filename,xfer.append ? "ab" : "wb"))==NULL) {
......@@ -2371,7 +2370,7 @@ static void ctrl_thread(void* arg)
#endif
login_attempt_t attempted;
SetThreadName("FTP CTRL");
SetThreadName("sbbs/FTP Control");
thread_up(TRUE /* setuid */);
lastactive=time(NULL);
......@@ -4777,7 +4776,7 @@ void DLLCALL ftp_server(void* arg)
ftp_ver();
startup=(ftp_startup_t*)arg;
SetThreadName("FTP Server");
SetThreadName("sbbs/FTP Server");
#ifdef _THREAD_SUID_BROKEN
if(thread_suid_broken)
......@@ -4970,7 +4969,7 @@ void DLLCALL ftp_server(void* arg)
lprintf(LOG_INFO,"FTP Server thread started");
while(ftp_set!=NULL && !terminate_server) {
YIELD();
if(protected_uint32_value(thread_count) <= 1) {
if(!(startup->options&FTP_OPT_NO_RECYCLE)) {
if((p=semfile_list_check(&initialized,recycle_semfiles))!=NULL) {
......
/* js_global.c */
/* Synchronet JavaScript "global" object properties/methods for all servers */
/* $Id$ */
// vi: tabstop=4
/****************************************************************************
* @format.tab-size 4 (Plain Text/Source Code File Header) *
......@@ -124,7 +123,7 @@ static void background_thread(void* arg)
jsval result=JSVAL_VOID;
jsval exit_code;
SetThreadName("JS Background");
SetThreadName("sbbs/JS Background");
msgQueueAttach(bg->msg_queue);
JS_SetContextThread(bg->cx);
JS_BEGINREQUEST(bg->cx);
......
/* $Id$ */
// vi: tabstop=4
#include "js_rtpool.h"
#include <threadwrap.h> /* Must be included after jsapi.h */
......@@ -25,7 +26,7 @@ static link_list_t rt_list;
#define TRIGGER_THREAD_STACK_SIZE (256*1024)
static void trigger_thread(void *args)
{
SetThreadName("JSRT Trigger");
SetThreadName("sbbs/JSRT Trigger");
for(;;) {
list_node_t *node;
pthread_mutex_lock(&jsrt_mutex);
......
/* mailsrvr.c */
/* Synchronet Mail (SMTP/POP3) server and sendmail threads */
/* $Id$ */
// vi: tabstop=4
/****************************************************************************
* @format.tab-size 4 (Plain Text/Source Code File Header) *
......@@ -827,7 +826,7 @@ static void pop3_thread(void* arg)
pop3_t pop3=*(pop3_t*)arg;
login_attempt_t attempted;
SetThreadName("POP3");
SetThreadName("sbbs/POP3");
thread_up(TRUE /* setuid */);
free(arg);
......@@ -2499,7 +2498,7 @@ static void smtp_thread(void* arg)
,ENCODING_QUOTED_PRINTABLE
} content_encoding = ENCODING_NONE;
SetThreadName("SMTP");
SetThreadName("sbbs/SMTP");
thread_up(TRUE /* setuid */);
free(arg);
......@@ -4533,7 +4532,7 @@ static void sendmail_thread(void* arg)
BOOL sending_locally=FALSE;
link_list_t failed_server_list;
SetThreadName("SendMail");
SetThreadName("sbbs/SendMail");
thread_up(TRUE /* setuid */);
terminate_sendmail=FALSE;
......@@ -4546,7 +4545,7 @@ static void sendmail_thread(void* arg)
listInit(&failed_server_list, /* flags: */0);
while((!terminated) && !terminate_sendmail) {
YIELD();
if(startup->options&MAIL_OPT_NO_SENDMAIL) {
sem_trywait_block(&sendmail_wakeup_sem,1000);
continue;
......@@ -5224,7 +5223,7 @@ void DLLCALL mail_server(void* arg)
startup->shutdown_now=FALSE;
terminate_server=FALSE;
SetThreadName("Mail Server");
SetThreadName("sbbs/Mail Server");
protected_uint32_init(&thread_count, 0);
do {
......@@ -5408,6 +5407,7 @@ void DLLCALL mail_server(void* arg)
lprintf(LOG_INFO,"Mail Server thread started");
while(!terminated && !terminate_server) {
YIELD();
if(protected_uint32_value(thread_count) <= (unsigned int)(1+(sendmail_running?1:0))) {
if(!(startup->options&MAIL_OPT_NO_RECYCLE)) {
......
/* Synchronet terminal server thread and related functions */
/* $Id$ */
// vi: tabstop=4
/****************************************************************************
* @format.tab-size 4 (Plain Text/Source Code File Header) *
......@@ -1662,7 +1663,7 @@ void input_thread(void *arg)
SOCKET high_socket;
SOCKET sock;
SetThreadName("Node Input");
SetThreadName("sbbs/Terminal Input");
thread_up(TRUE /* setuid */);
#ifdef _DEBUG
......@@ -1933,7 +1934,7 @@ void passthru_output_thread(void* arg)
int rd;
int wr;
SetThreadName("Passthrough Output");
SetThreadName("sbbs/Passthrough Output");
thread_up(FALSE /* setuid */);
while(sbbs->client_socket!=INVALID_SOCKET && sbbs->passthru_socket!=INVALID_SOCKET && !terminate_server) {
......@@ -2047,7 +2048,7 @@ void passthru_input_thread(void* arg)
BYTE ch;
int i;
SetThreadName("Passthrough Input");
SetThreadName("sbbs/Passthrough Input");
thread_up(FALSE /* setuid */);
while(sbbs->passthru_socket!=INVALID_SOCKET && !terminate_server) {
......@@ -2138,7 +2139,7 @@ void output_thread(void* arg)
struct timeval tv;
ulong mss=IO_THREAD_BUF_SIZE;
SetThreadName("Node Output");
SetThreadName("sbbs/Terminal Output");
thread_up(TRUE /* setuid */);
if(sbbs->cfg.node_num)
......@@ -2378,7 +2379,7 @@ void event_thread(void* arg)
sbbs_srand(); /* Seed random number generator */
SetThreadName("BBS Events");
SetThreadName("sbbs/Events");
thread_up(TRUE /* setuid */);
#ifdef JAVASCRIPT
......@@ -4130,7 +4131,7 @@ void node_thread(void* arg)
sbbs_t* sbbs = (sbbs_t*) arg;
update_clients();
SetThreadName("Node");
SetThreadName("sbbs/Terminal Node");
thread_up(TRUE /* setuid */);
#ifdef _DEBUG
......@@ -4641,7 +4642,7 @@ void DLLCALL bbs_thread(void* arg)
startup->shutdown_now=FALSE;
terminate_server=false;
SetThreadName("BBS");
SetThreadName("sbbs/Terminal Server");
do {
......@@ -4975,7 +4976,7 @@ NO_SSH:
lprintf(LOG_INFO,"Terminal Server thread started for nodes %d through %d", first_node, last_node);
while(!terminate_server) {
YIELD();
if(protected_uint32_value(node_threads_running)==0) { /* check for re-run flags and recycle/shutdown sem files */
if(!(startup->options&BBS_OPT_NO_RECYCLE)) {
......
/* sbbscon.c */
/* Synchronet vanilla/console-mode "front-end" */
/* $Id$ */
// vi: tabstop=4
/****************************************************************************
* @format.tab-size 4 (Plain Text/Source Code File Header) *
......@@ -1102,7 +1101,7 @@ static void handle_sigs(void)
int sig=0;
sigset_t sigs;
SetThreadName("Signal Handler");
SetThreadName("sbbs/Signal Handler");
thread_up(NULL,TRUE,TRUE);
/* Write the standard .pid file if created/open */
......
/* services.c */
/* Synchronet Services */
/* $Id$ */
// vi: tabstop=4
/****************************************************************************
* @format.tab-size 4 (Plain Text/Source Code File Header) *
......@@ -980,7 +979,7 @@ static void js_service_thread(void* arg)
lprintf(LOG_DEBUG,"%04d %s JavaScript service thread started", socket, service->protocol);
SetThreadName("JS Service");
SetThreadName("sbbs/JS Service");
thread_up(TRUE /* setuid */);
protected_uint32_adjust(&threads_pending_start, -1);
......@@ -1183,7 +1182,7 @@ static void js_static_service_thread(void* arg)
lprintf(LOG_DEBUG,"%s static JavaScript service thread started", service->protocol);
SetThreadName("JS Static Service");
SetThreadName("sbbs/JS Static Service");
thread_up(TRUE /* setuid */);
protected_uint32_adjust(&threads_pending_start, -1);
......@@ -1282,7 +1281,7 @@ static void native_static_service_thread(void* arg)
lprintf(LOG_DEBUG,"%04d %s static service thread started", inst.socket, inst.service->protocol);
SetThreadName("Static Service");
SetThreadName("sbbs/Static Service");
thread_up(TRUE /* setuid */);
protected_uint32_adjust(&threads_pending_start, -1);
......@@ -1345,7 +1344,7 @@ static void native_service_thread(void* arg)
lprintf(LOG_DEBUG,"%04d %s service thread started", socket, service->protocol);
SetThreadName("Native Service");
SetThreadName("sbbs/Native Service");
thread_up(TRUE /* setuid */);
protected_uint32_adjust(&threads_pending_start, -1);
......@@ -1740,7 +1739,7 @@ void DLLCALL services_thread(void* arg)
startup->recycle_now=FALSE;
startup->shutdown_now=FALSE;
SetThreadName("Services");
SetThreadName("sbbs/Services");
do {
......@@ -1913,7 +1912,7 @@ void DLLCALL services_thread(void* arg)
/* Main Server Loop */
while(!terminated) {
YIELD();
if(active_clients()==0 && protected_uint32_value(threads_pending_start)==0) {
if(!(startup->options&BBS_OPT_NO_RECYCLE)) {
if((p=semfile_list_check(&initialized,recycle_semfiles))!=NULL) {
......@@ -1953,10 +1952,8 @@ void DLLCALL services_thread(void* arg)
high_socket=service[i].set->socks[j].sock;
}
}
if(high_socket==0) { /* No dynamic services? */
YIELD();
if(high_socket==0) /* No dynamic services? */
continue;
}
tv.tv_sec=startup->sem_chk_freq;
tv.tv_usec=0;
if((result=select(high_socket+1,&socket_set,NULL,NULL,&tv))<1) {
......
/* websrvr.c */
/* Synchronet Web Server */
/* $Id$ */
// vi: tabstop=4
/****************************************************************************
* @format.tab-size 4 (Plain Text/Source Code File Header) *
......@@ -6010,7 +6009,7 @@ void http_output_thread(void *arg)
int i;
unsigned mss=OUTBUF_LEN;
SetThreadName("HTTP Output");
SetThreadName("sbbs/HTTP Output");
thread_up(TRUE /* setuid */);
obuf=&(session->outbuf);
......@@ -6146,7 +6145,7 @@ void http_session_thread(void* arg)
char *uname;
#endif
SetThreadName("HTTP Session");
SetThreadName("sbbs/HTTP Session");
pthread_mutex_lock(&((http_session_t*)arg)->struct_filled);
pthread_mutex_unlock(&((http_session_t*)arg)->struct_filled);
pthread_mutex_destroy(&((http_session_t*)arg)->struct_filled);
......@@ -6512,7 +6511,7 @@ void http_logging_thread(void* arg)
if(!base[0])
SAFEPRINTF(base,"%slogs/http-",scfg.logs_dir);
SetThreadName("HTTP Logging");
SetThreadName("sbbs/HTTP Logging");
filename[0]=0;
newfilename[0]=0;
......@@ -6626,7 +6625,7 @@ void DLLCALL web_server(void* arg)
startup=(web_startup_t*)arg;
SetThreadName("Web Server");
SetThreadName("sbbs/Web Server");
web_ver(); /* get CVS revision */
if(startup==NULL) {
......@@ -6840,7 +6839,7 @@ void DLLCALL web_server(void* arg)
status("Listening");
while(!terminated && !terminate_server) {
YIELD();
/* check for re-cycle/shutdown semaphores */
if(protected_uint32_value(thread_count) <= (unsigned int)(2 /* web_server() and http_output_thread() */ + (http_logging_thread_running?1:0))) {
if(!(startup->options&BBS_OPT_NO_RECYCLE)) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment