cvs commit: apachen/src/test time-sem.c

1998-01-22 Thread jim
jim 98/01/22 15:12:10

  Modified:.STATUS
   htdocs/manual/misc FAQ.html perf-tuning.html
   htdocs/manual/mod core.html
   src  CHANGES PORTING
   src/main conf.h http_main.c httpd.h
   src/os/win32 os.h
   src/test time-sem.c
  Log:
  Submitted by: Jim Jagielski
  
  Do make the code a bit clearer, some minor #define changes (and
  the resultant flow-thru in the docs).
  
 SAFE_UNSERIALIZED_ACCEPT  -   SINGLE_LISTEN_UNSERIALIZED_ACCEPT
 HAVE_MMAP -   USE_MMAP_SCOREBOARD
 HAVE_SHMGET   -   USE_SHMGET_SCOREBOARD
  
  Revision  ChangesPath
  1.116 +1 -1  apachen/STATUS
  
  Index: STATUS
  ===
  RCS file: /export/home/cvs/apachen/STATUS,v
  retrieving revision 1.115
  retrieving revision 1.116
  diff -u -r1.115 -r1.116
  --- STATUS1998/01/22 00:03:37 1.115
  +++ STATUS1998/01/22 23:11:45 1.116
  @@ -32,7 +32,7 @@
   * Ken's [PATCH] for #1479, #1480
   * Dean's [PATCH] fail gracefully if cd fails
   * Dean's [PATCH] Re: general/1491: mmap_handler error_log entry
  -* Marc's [PATCH] FreeBSD 2.2+ can use SAFE_UNSERIALIZED_ACCEPT
  +* Marc's [PATCH] FreeBSD 2.2+ can use SINGLE_LISTEN_UNSERIALIZED_ACCEPT
   * Ken's [PATCH] Configure be more verbose when it can't find
 Configuration
   * Paul's [PATCH] Proper reporting of Win32 errors
  
  
  
  1.97  +2 -2  apachen/htdocs/manual/misc/FAQ.html
  
  Index: FAQ.html
  ===
  RCS file: /export/home/cvs/apachen/htdocs/manual/misc/FAQ.html,v
  retrieving revision 1.96
  retrieving revision 1.97
  diff -u -r1.96 -r1.97
  --- FAQ.html  1997/12/16 16:52:19 1.96
  +++ FAQ.html  1998/01/22 23:11:48 1.97
  @@ -15,7 +15,7 @@
 !--#include virtual=header.html --
 H1 ALIGN=CENTERApache Server Frequently Asked Questions/H1
 P
  -  $Revision: 1.96 $ ($Date: 1997/12/16 16:52:19 $)
  +  $Revision: 1.97 $ ($Date: 1998/01/22 23:11:48 $)
 /P
 P
 The latest version of this FAQ is always available from the main
  @@ -1803,7 +1803,7 @@
 A HREF=http://www.linuxhq.com/HOWTO/META-FAQ.html;
 Linux newsgroup/mailing list/A.
 As a last-resort workaround, you can
  -  comment out the CODE#define HAVE_SHMGET/CODE definition in the
  +  comment out the CODE#define USE_SHMGET_SCOREBOARD/CODE definition in 
the
 SAMPLINUX/SAMP section of
 SAMPsrc/conf.h/SAMP and rebuild the server.  This will produce
 a server which is slower and less reliable.
  
  
  
  1.4   +5 -5  apachen/htdocs/manual/misc/perf-tuning.html
  
  Index: perf-tuning.html
  ===
  RCS file: /export/home/cvs/apachen/htdocs/manual/misc/perf-tuning.html,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- perf-tuning.html  1997/10/25 05:35:43 1.3
  +++ perf-tuning.html  1998/01/22 23:11:49 1.4
  @@ -415,7 +415,7 @@
   But unserialized single-socket showed an extra 100ms latency on
   each request.  This latency is probably a wash on long haul lines,
   and only an issue on LANs.  If you want to override the single socket
  -serialization you can define codeSAFE_UNSERIALIZED_ACCEPT/code
  +serialization you can define codeSINGLE_LISTEN_UNSERIALIZED_ACCEPT/code
   and then single-socket servers will not serialize at all.
   
   h4Lingering Close/h4
  @@ -493,8 +493,8 @@
   implemented using shared memory.  The rest default to using an
   on-disk file.  The on-disk file is not only slow, but it is unreliable
   (and less featured).  Peruse the codesrc/main/conf.h/code file
  -for your architecture and look for either codeHAVE_MMAP/code or
  -codeHAVE_SHMGET/code.  Defining one of those two enables the
  +for your architecture and look for either codeUSE_MMAP_SCOREBOARD/code or
  +codeUSE_SHMGET_SCOREBOARD/code.  Defining one of those two enables the
   supplied shared memory code.  If your system has another type of
   shared memory then edit the file codesrc/main/http_main.c/code and
   add the hooks necessary to use it in Apache.  (Send us back a patch
  @@ -570,7 +570,7 @@
   /pre/blockquote
   
   These two calls can be removed by defining
  -codeSAFE_UNSERIALIZED_ACCEPT/code as described earlier.
  +codeSINGLE_LISTEN_UNSERIALIZED_ACCEPT/code as described earlier.
   
   pNotice the codeSIGUSR1/code manipulation:
   
  @@ -751,7 +751,7 @@
   which were described earlier.
   
   pLet's apply some of these optimizations:
  -code-DSAFE_UNSERIALIZED_ACCEPT -DBUFFERED_LOGS/code and
  +code-DSINGLE_LISTEN_UNSERIALIZED_ACCEPT -DBUFFERED_LOGS/code and
   codeRule STATUS=no/code.  Here's the final trace:
   
   blockquotepre
  
  
  
  1.89  +2 -2  apachen/htdocs/manual/mod/core.html
  
  Index: core.html
  

cvs commit: apachen/src/test time-sem.c

1997-11-10 Thread dgaudet
dgaudet 97/11/09 17:47:50

  Modified:src/test time-sem.c
  Log:
  Yet more updates.  It now works on linux again (I lost the old version which
  runs under linux).  It includes the correct flock() code.  It attempts to
  yield its slice up to other processes ...
  
  Revision  ChangesPath
  1.4   +141 -24   apachen/src/test/time-sem.c
  
  Index: time-sem.c
  ===
  RCS file: /export/home/cvs/apachen/src/test/time-sem.c,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- time-sem.c1997/11/04 08:33:13 1.3
  +++ time-sem.c1997/11/10 01:47:49 1.4
  @@ -15,7 +15,11 @@
We're not sure what the tunable is, so there's a define
NO_SEM_UNDO which can be used to simulate us trapping/blocking
signals to be able to properly release the semaphore on a clean
  - child death.
  + child death.  You'll also need to define NEED_UNION_SEMUN
  + under solaris.
  +
  +You'll need to define HAVE_SHMGET if anonymous shared mmap() doesn't
  +work on your system (i.e. linux).
   
   argv[1] is the #children, argv[2] is the #iterations per child
   
  @@ -55,6 +59,9 @@
   
   static int fcntl_fd=-1;
   
  +#define accept_mutex_child_init()
  +#define accept_mutex_cleanup()
  +
   /*
* Initialize mutex lock.
* Must be safe to call this on a restart.
  @@ -113,23 +120,37 @@
   
   static int flock_fd=-1;
   
  +#define FNAME test-lock-thing
  +
   /*
* Initialize mutex lock.
* Must be safe to call this on a restart.
*/
  -void
  -accept_mutex_init(void)
  +void accept_mutex_init(void)
   {
   
  -printf(opening test-lock-thing in current directory\n);
  -flock_fd = open(test-lock-thing, O_CREAT | O_WRONLY | O_EXCL, 0644);
  +printf(opening  FNAME  in current directory\n);
  +flock_fd = open(FNAME, O_CREAT | O_WRONLY | O_EXCL, 0644);
   if (flock_fd == -1)
   {
perror (open);
fprintf (stderr, Cannot open lock file: %s\n, test-lock-thing);
exit (1);
   }
  -unlink(test-lock-thing);
  +}
  +
  +void accept_mutex_child_init(void)
  +{
  +flock_fd = open(FNAME, O_WRONLY, 0600);
  +if (flock_fd == -1) {
  + perror(open);
  + exit(1);
  +}
  +}
  +
  +void accept_mutex_cleanup(void)
  +{
  +unlink(FNAME);
   }
   
   void accept_mutex_on(void)
  @@ -166,13 +187,19 @@
   static sigset_t accept_previous_mask;
   #endif
   
  +#define accept_mutex_child_init()
  +#define accept_mutex_cleanup()
  +
   void accept_mutex_init(void)
   {
  -  union semun {
  -   int val;
  -   struct semid_ds *buf;
  -   ushort *array;
  -  };
  +#ifdef NEED_UNION_SEMUN
  +/* believe it or not, you need to define this under solaris */
  +union semun {
  + int val;
  + struct semid_ds *buf;
  + ushort *array;
  +};
  +#endif
   
   union semun ick;
   
  @@ -251,6 +278,9 @@
   static sigset_t accept_block_mask;
   static sigset_t accept_previous_mask;
   
  +#define accept_mutex_child_init()
  +#define accept_mutex_cleanup()
  +
   void accept_mutex_init(void)
   {
   pthread_mutexattr_t mattr;
  @@ -311,9 +341,15 @@
   }
   
   #elif defined (USE_USLOCK_SERIALIZED_ACCEPT)
  +
   #include ulocks.h
  +
   static usptr_t *us = NULL;
   static ulock_t uslock = NULL;
  +
  +#define accept_mutex_child_init()
  +#define accept_mutex_cleanup()
  +
   void accept_mutex_init(void)
   {
   ptrdiff_t old;
  @@ -364,6 +400,94 @@
   #endif
   
   
  +#ifndef HAVE_SHMGET
  +static void *get_shared_mem(size_t size)
  +{
  +int fd;
  +void *result;
  +
  +/* allocate shared memory for the shared_counter */
  +fd = open (/dev/zero, O_RDWR);
  +if (fd == -1) {
  + perror (open);
  + exit (1);
  +}
  +result = (unsigned long *)mmap ((caddr_t)0, size,
  + PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0);
  +if (result == (void *)(caddr_t)-1) {
  + perror (mmap);
  + exit (1);
  +}
  +close (fd);
  +return result;
  +}
  +#else
  +#include sys/types.h
  +#include sys/ipc.h
  +#include sys/shm.h
  +
  +static void *get_shared_mem(size_t size)
  +{
  +key_t shmkey = IPC_PRIVATE;
  +int shmid = -1;
  +void *result;
  +#ifdef MOVEBREAK
  +char *obrk;
  +#endif
  +
  +if ((shmid = shmget(shmkey, size, IPC_CREAT | SHM_R | SHM_W)) == -1) {
  + perror(shmget);
  + exit(1);
  +}
  +
  +#ifdef MOVEBREAK
  +/*
  + * Some SysV systems place the shared segment WAY too close
  + * to the dynamic memory break point (sbrk(0)). This severely
  + * limits the use of malloc/sbrk in the program since sbrk will
  + * refuse to move past that point.
  + *
  + * To get around this, we move the break point way up there,
  + * attach the segment and then move break back down. Ugly
  + */
  +if ((obrk = sbrk(MOVEBREAK)) == 

cvs commit: apachen/src/test time-sem.c

1997-11-04 Thread dgaudet
dgaudet 97/11/03 23:57:43

  Modified:src/test time-sem.c
  Log:
  make it clear that fcntl/flock open lock file in cwd
  
  Revision  ChangesPath
  1.2   +2 -0  apachen/src/test/time-sem.c
  
  Index: time-sem.c
  ===
  RCS file: /export/home/cvs/apachen/src/test/time-sem.c,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- time-sem.c1997/11/04 02:47:13 1.1
  +++ time-sem.c1997/11/04 07:57:43 1.2
  @@ -59,6 +59,7 @@
   unlock_it.l_type   = F_UNLCK;  /* set exclusive/write lock */
   unlock_it.l_pid= 0;/* pid not actually interesting */
   
  +printf(opening test-lock-thing in current directory\n);
   fcntl_fd = open(test-lock-thing, O_CREAT | O_WRONLY | O_EXCL, 0644);
   if (fcntl_fd == -1)
   {
  @@ -105,6 +106,7 @@
   accept_mutex_init(void)
   {
   
  +printf(opening test-lock-thing in current directory\n);
   flock_fd = open(test-lock-thing, O_CREAT | O_WRONLY | O_EXCL, 0644);
   if (flock_fd == -1)
   {
  
  
  


cvs commit: apachen/src/test time-sem.c

1997-11-04 Thread dgaudet
dgaudet 97/11/04 00:33:13

  Modified:src/test time-sem.c
  Log:
  latest greatest time-sem.c
  
  Revision  ChangesPath
  1.3   +64 -15apachen/src/test/time-sem.c
  
  Index: time-sem.c
  ===
  RCS file: /export/home/cvs/apachen/src/test/time-sem.c,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- time-sem.c1997/11/04 07:57:43 1.2
  +++ time-sem.c1997/11/04 08:33:13 1.3
  @@ -1,23 +1,38 @@
   /*
  -Date: Sat, 1 Nov 1997 16:53:52 -0800 (PST)
  -From: Dean Gaudet [EMAIL PROTECTED]
  +time-sem.c has the basics of the semaphores we use in http_main.c.  It's
  +intended for timing differences between various methods on an
  +architecture.  In practice we've found many things affect which semaphore
  +to be used:
  +
  +- NFS filesystems absolutely suck for fcntl() and flock()
  +
  +- uslock absolutely sucks on single-processor IRIX boxes, but
  + absolutely rocks on multi-processor boxes.  The converse
  + is true for fcntl.  sysvsem seems a moderate balance.
  +
  +- Under Solaris you can't have too many processes use SEM_UNDO, there
  + might be a tuneable somewhere that increases the limit from 29.
  + We're not sure what the tunable is, so there's a define
  + NO_SEM_UNDO which can be used to simulate us trapping/blocking
  + signals to be able to properly release the semaphore on a clean
  + child death.
  +
  +argv[1] is the #children, argv[2] is the #iterations per child
  +
  +You should run each over many different #children inputs, and choose
  +#iter such that the program runs for at least a second or so... or even
  +longer depending on your patience.
   
  -This time-sem.c includes the necessary signal manipulations to allow us to
  -continue to use pthreads.  It appears to still be and order of magnitude
  -faster than fcntl locking.  I'm a little too busy to make a patch though,
  -so if someone could take the pthread code in time-sem.c here and compare
  -it against the server ... and generate a patch, that'd be great.  You also
  -have to properly release the mutex on any of the three unblocked signals --
  -which you should do in the handlers we already have for those signals,
  -so that we don't have to also instate a handler during the critical
  -section ...
  -
  -Dean
  +compile with:
   
   gcc -o time-FCNTL -Wall -O time-sem.c -DUSE_FCNTL_SERIALIZED_ACCEPT
   gcc -o time-FLOCK -Wall -O time-sem.c -DUSE_FLOCK_SERIALIZED_ACCEPT
  -gcc -o time-SEM -Wall -O time-sem.c -DUSE_SYSVSEM_SERIALIZED_ACCEPT
  +gcc -o time-SYSVSEM -Wall -O time-sem.c -DUSE_SYSVSEM_SERIALIZED_ACCEPT
  +gcc -o time-SYSVSEM2 -Wall -O time-sem.c -DUSE_SYSVSEM_SERIALIZED_ACCEPT 
-DNO_SEM_UNDO
   gcc -o time-PTHREAD -Wall -O time-sem.c -DUSE_PTHREAD_SERIALIZED_ACCEPT 
-lpthread
  +gcc -o time-USLOCK -Wall -O time-sem.c -DUSE_USLOCK_SERIALIZED_ACCEPT
  +
  +not all versions work on all systems.
   */
   
   #include errno.h
  @@ -146,6 +161,10 @@
   #include sys/sem.h
   
   static   int sem_id = -1;
  +#ifdef NO_SEM_UNDO
  +static sigset_t accept_block_mask;
  +static sigset_t accept_previous_mask;
  +#endif
   
   void accept_mutex_init(void)
   {
  @@ -167,15 +186,29 @@
  perror (semctl);
   exit(1);
   }
  +#ifdef NO_SEM_UNDO
  +sigfillset(accept_block_mask);
  +sigdelset(accept_block_mask, SIGHUP);
  +sigdelset(accept_block_mask, SIGTERM);
  +sigdelset(accept_block_mask, SIGUSR1);
  +#endif
   }
   
   void accept_mutex_on()
   {
   struct sembuf op;
   
  +#ifdef NO_SEM_UNDO
  +if (sigprocmask(SIG_BLOCK, accept_block_mask, accept_previous_mask)) {
  + perror(sigprocmask(SIG_BLOCK));
  + exit (1);
  +}
  +op.sem_flg = 0;
  +#else
  +op.sem_flg = SEM_UNDO;
  +#endif
   op.sem_num = 0;
   op.sem_op  = -1;
  -op.sem_flg = SEM_UNDO;
   if (semop(sem_id, op, 1)  0) {
perror (accept_mutex_on);
exit (1);
  @@ -188,15 +221,30 @@
   
   op.sem_num = 0;
   op.sem_op  = 1;
  +#ifdef NO_SEM_UNDO
  +op.sem_flg = 0;
  +#else
   op.sem_flg = SEM_UNDO;
  +#endif
   if (semop(sem_id, op, 1)  0) {
perror (accept_mutex_off);
   exit (1);
   }
  +#ifdef NO_SEM_UNDO
  +if (sigprocmask(SIG_SETMASK, accept_previous_mask, NULL)) {
  + perror(sigprocmask(SIG_SETMASK));
  + exit (1);
  +}
  +#endif
   }
   
   #elif defined (USE_PTHREAD_SERIALIZED_ACCEPT)
   
  +/* note: pthread mutexes aren't released on child death, hence the
  + * signal goop ... in a real implementation we'd do special things
  + * during hup, term, usr1.
  + */
  +
   #include pthread.h
   
   static pthread_mutex_t *mutex;
  @@ -403,5 +451,6 @@
   }
   last.tv_usec = ms;
   printf (%8lu.%06lu\n, last.tv_sec, last.tv_usec);
  +exit(0);
   }