syslog strangeness on freebsd 8.0 and 8.1-RC when using threads
Vikash Badal
Vikash.Badal at is.co.za
Wed Jul 7 15:43:31 UTC 2010
Can someone please assist me with some strangeness on FreeBSD 8.0 and 8.1-RC2
using a threaded test code code, I see the that freebsd 8.x seems to be using more memory when using the syslog() call from a c program:
Results:
7.2
without syslog
PID USERNAME THR PRI NICE SIZE RES STATE TIME WCPU COMMAND
26872 vikashb 1001 8 0 128M 14236K RUN 0:00 0.00% a.out
with syslog
PID USERNAME THR PRI NICE SIZE RES STATE TIME WCPU COMMAND
26881 vikashb 1001 44 0 128M 26236K RUN 0:00 0.00% a.out
8.0-RELEASE-p3
without syslog
PID USERNAME THR PRI NICE SIZE RES STATE TIME WCPU COMMAND
61529 vikashb 1001 44 0 129M 14840K RUN 0:01 0.00% a.out
with syslog
PID USERNAME THR PRI NICE SIZE RES STATE TIME WCPU COMMAND
61507 vikashb 1001 44 0 257M 42708K RUN 0:30 0.00% a.out
8.1-RC2
without syslog
PID USERNAME THR PRI NICE SIZE RES STATE TIME WCPU COMMAND
33062 vikashb 1001 44 0 129M 14804K RUN 0:00 0.00% a.out
with syslog
PID USERNAME THR PRI NICE SIZE RES STATE TIME WCPU COMMAND
33056 vikashb 1001 44 0 257M 42708K RUN 0:03 0.00% a.out
I have not been able to find any reasonable information via google.
Why does syslog result in more memory being consumed on 8.x as opposed to 7.2 ?
<CODE>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/time.h>
#include <stdarg.h>
#include <errno.h>
#include <syslog.h>
#include <signal.h>
#include <pthread.h>
char *ProgramName = "WTF";
int loop = 0;
int LogToSTDOUT = 1;
void LogMessage(int debug, const char *fmt,...)
{
extern int LogToSTDOUT;
char message[8192];
memset(message, 0, sizeof(message));
va_list args;
va_start(args, fmt);
vsnprintf(message, sizeof(message), fmt, args);
va_end(args);
if ( LogToSTDOUT )
{
printf("%s\n", message);
}
syslog(LOG_NOTICE, "%s", message);
}
unsigned long int getTimeNow()
{
struct timeval tv;
if ( gettimeofday(&tv, NULL) == -1 )
{
LogMessage(0, "ERROR(%d) %s\n", errno, strerror(errno));
tv.tv_sec = 0;
}
return tv.tv_sec;
}
void HandleSignal(int sig)
{
loop = 0;
LogMessage(0, "loop = %d\n", loop);
signal(sig, SIG_IGN);
usleep(1000);
}
void *worker(int n)
{
while ( loop )
{
LogMessage(0, "worker #%d logging", n);
usleep(1000);
}
pthread_exit(0);
}
int main(int argc, char* argv[])
{
pthread_t* tpool;
int workers = 1000, i, rc;
openlog(ProgramName, LOG_PID, LOG_MAIL);
unsigned long int duration = 120, StartTime, TimeNow;
signal(SIGINT, HandleSignal);
signal(SIGTERM, HandleSignal);
signal(SIGHUP, HandleSignal);
signal(SIGQUIT, HandleSignal);
StartTime = getTimeNow();
tpool = (pthread_t*)malloc(workers * sizeof(pthread_t));
if ( tpool == NULL )
{
LogMessage(0, "malloc failed \n");
closelog();
exit(-1);
}
memset(tpool, 0, sizeof(pthread_t) * workers);
loop = 1;
for ( i = 0; i < workers; i++ )
{
rc = pthread_create(&tpool[i], NULL, (void *(*)(void*))&worker, (void*)i);
if ( rc != 0 )
{
LogMessage(0, "pthread_create #%d failed\n", i );
pthread_cancel(tpool[i]);
}
else
{
pthread_detach(tpool[i]);
}
}
LogMessage(0, "loop = %d\n", loop);
while ( loop )
{
TimeNow = getTimeNow();
if ( ( TimeNow - StartTime ) > duration )
{
loop = 0;
}
usleep(1000);
}
for ( i = 0; i < workers; i++ )
{
pthread_cancel(tpool[i]);
}
for ( i = 0; i < workers; i++ )
{
pthread_join(tpool[i], NULL);
}
free(tpool);
closelog();
exit(0);
}
</CODE>
Please note: This email and its content are subject to the disclaimer as displayed at the following link http://www.is.co.za/legal/E-mail+Confidentiality+Notice+and+Disclaimer.htm. Should you not have Web access, send a mail to disclaimers at is.co.za and a copy will be emailed to you.
_______________________________________________
freebsd-questions at freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to "freebsd-questions-unsubscribe at freebsd.org"
Please note: This email and its content are subject to the disclaimer as displayed at the following link http://www.is.co.za/legal/E-mail+Confidentiality+Notice+and+Disclaimer.htm. Should you not have Web access, send a mail to disclaimers at is.co.za and a copy will be emailed to you.
More information about the freebsd-threads
mailing list