View Single Post
  #1   (View Single Post)  
Old 6th July 2010
vikashb vikashb is offline
New User
 
Join Date: Jul 2010
Posts: 1
Default syslog strangeness on freebsd 8.0 and 8.1-RC

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 ?
is this a bug ?

C code below
PHP 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(message0sizeof(message));

   
va_list args;

   
va_start(argsfmt);
   
vsnprintf(messagesizeof(message), fmtargs);
   
va_end(args);

   if ( 
LogToSTDOUT )
   {
      
printf("%s\n"message);
   }

   
syslog(LOG_NOTICE"%s"message);

}

unsigned long int getTimeNow()
{
   
struct timeval tv;

   if ( 
gettimeofday(&tvNULL) == -)
   {
      
LogMessage(0"ERROR(%d) %s\n"errnostrerror(errno));
      
tv.tv_sec 0;
   }

   return 
tv.tv_sec;
}

void HandleSignal(int sig)
{
   
loop 0;
   
LogMessage(0"loop  = %d\n"loop);
   
signal(sigSIG_IGN);
   
usleep(1000);
}

void *worker(int n)
{
   while ( 
loop )
   {
      
LogMessage(0"worker #%d logging"n);
      
usleep(1000);
   }

   
pthread_exit(0);
}

int main(int argccharargv[])
{
   
pthread_ttpool;

   
int workers 1000irc;

   
openlog(ProgramNameLOG_PIDLOG_MAIL);

   
unsigned long int duration 120StartTimeTimeNow;

   
signal(SIGINTHandleSignal);
   
signal(SIGTERMHandleSignal);
   
signal(SIGHUPHandleSignal);
   
signal(SIGQUITHandleSignal);

   
StartTime getTimeNow();

   
tpool = (pthread_t*)malloc(workers sizeof(pthread_t));

   if ( 
tpool == NULL )
   {
      
LogMessage(0"malloc failed \n");
      
closelog();
      exit(-
1);
   }

   
memset(tpool0sizeof(pthread_t) * workers);

   
loop 1;

   for ( 
0workersi++ )
   {
      
rc pthread_create(&tpool[i], NULL, (void *(*)(void*))&worker, (void*)i);

      if ( 
rc != )
      {
         
LogMessage(0"pthread_create #%d failed\n");
         
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 ( 
0workersi++ )
   {
      
pthread_cancel(tpool[i]);
   }

   for ( 
0workersi++ )
   {
      
pthread_join(tpool[i], NULL);
   }

   
free(tpool);
   
closelog();
   exit(
0);

Reply With Quote