Return-Path: Delivered-To: apache-cvs-archive@hyperreal.org Received: (qmail 9634 invoked by uid 6000); 12 Aug 1999 07:31:05 -0000 Received: (qmail 9614 invoked by uid 2016); 12 Aug 1999 07:31:03 -0000 Delivered-To: apcore-apache-apr-cvs@apache.org Received: (qmail 9612 invoked by uid 168); 12 Aug 1999 07:31:02 -0000 Date: 12 Aug 1999 07:31:02 -0000 Message-ID: <19990812073102.9611.qmail@hyperreal.org> From: rse@hyperreal.org To: apache-apr-cvs@apache.org Subject: cvs commit: apache-apr/pthreads README.rse Sender: apache-cvs-owner@apache.org Precedence: bulk Reply-To: new-httpd@apache.org rse 99/08/12 00:31:02 Added: pthreads README.rse Log: Ralf's latest writeup: ``Get the Apache/pthread beast running''. Those who had great problems to get Apache/pthread running in the past (especially on non-Linux and non-AIX platforms ;) can now give it another try by following the ``FooBar/OS + Pth'' instructions in this document. With this variant Apache/pthread can be used to get a multithreaded Apache running on mostly all current Unix flavors, I think. Revision Changes Path 1.1 apache-apr/pthreads/README.rse Index: README.rse =================================================================== Get the Apache/pthread beast running Ralf S. Engelschall, 12-Aug-1999 ------------------------------------ These are my instructions for getting Apache/pthread running under various platforms (mainly FreeBSD for now). One usually has to fight against two major problems: 1. Apache/pthread (as Apache 1.3) uses an inter-process lockfile for optionally serializing accepts. This means that usually either flock(2) or fcntl(2) is used. The problem is that in a multi-threaded environment this works only by coincidence (usually when threads are implemented in kernel-space). For mostly all user-space implementations this will cause Apache/pthread to hang on connections (actually in the middle of processing the request in case the request processing thread had to be suspended once because of a blocking situation). There are two solutions: If the user-space threading library supports inter-process mutexes (_POSIX_THREAD_PROCESS_SHARED is defined) one can use pthread_mutex_t inside a shared memory segment. But AFAIK there is still no freely available user-space pthread library which supports this (the forthcoming GNU Pth versions will support this, but the stuff is still not released). So the only possibility is to use no accept serialization at all. The effect can be that the server is slower because of contention on the accept socket. 2. Apache/pthread uses poll(2) which is not available on all platforms. There is just one solution: Emulate poll(2) with select(2) For this one can use my poll emulation library which I've comitted to the apache-apr/poll/ repository area. 3. Portable user-space threading environments like GNU Pth cannot easily provide system call wrappers, because there is no 100% portable way to provide this "magically". For instance Pth instead provides two variants: soft syscall wrapping via ``#define _pthread_'' in pthread.h and hard syscall wrapping with syscall(2). The soft syscall wrapping is 100% portable, but requires an #include in _EVERY_ source file of the application which uses a to be wrapped system call, of course. The hard system call wrapping works "magically" just at the linker phase, but has some portability problems. The best solution is to use soft system call wrapping by just including pthread.h in every Apache source file. And here are the success stories for pariticular OS+Pthread variants: o FreeBSD 3.1 + John Birrell' uthread - uthread is a user-space pthread library in FreeBSD's libc_r which contains both thread-safe libc functions and the thread functions. This library replaces libc for threaded applications. For older FreeBSD versions (2.2.x) one has to build libc_r manually as part of a 'make world'. - uthread is a plain user-space implementation and this way the inter-process accept lock file cannot be used (it suspends the whole process and not just the current thread). One has to make sure that no USE_XXX_SERIALIZED_ACCEPT is defined for FreeBSD in src/include/ap_config.h. For this a -DNO_SERIALIZED_ACCEPT can be used. - FreeBSD <= 3.2-STABLE lacks poll(2) in libc_r, altough poll(2) exists in libc since FreeBSD 3.0. One has to use the poll emulation library. Follow these steps: $ cd /apache-apr/poll $ ./configure $ make $ cd /apache-apr/pthread $ CC='cc' \ OPTIM='-O2' \ CFLAGS='-pthread -I\$(SRCDIR)/../../poll -DNO_SERIALIZED_ACCEPT' \ LDFLAGS='-pthread -L\$(SRCDIR)/../../poll' \ LIBS='-lpoll' \ ./configure \ --with-layout=GNU \ --target=apache \ --prefix=/tmp/apache-pthread \ $ make $ make install o FooBar/OS + Ralf S. Engelschall's GNU Pth - Pth is also a user-space pthread library and this way the inter-process accept lock file cannot be used (it suspends the whole process and not just the current thread). One has to make sure that no USE_XXX_SERIALIZED_ACCEPT is defined for FreeBSD in src/include/ap_config.h. For this a -DNO_SERIALIZED_ACCEPT can be used. - FooBar/OS often lacks poll(2), but this is no problem, because GNU Pth on every platforms provides its own poll(2) emulation (based on select(2) which the Pth event manager uses internally). So you don't have to worry about this. Follow these steps: $ cd /apache-apr $ lynx ftp://alpha.gnu.org/gnu/pth/pth-1.1b3.tar.gz [You can use also any later Pth version, of course. ] [Especially release versions >= 1.1.0 from ftp://ftp.gnu.org/gnu/pth/] $ gunzip /apache-apr/pthread $ CC='cc' \ OPTIM='-O2' \ CFLAGS='-I\$(SRCDIR)/../pth-1.1b3 -DPTHREAD_EVERYWHERE -DNO_SERIALIZED_ACCEPT' \ LDFLAGS='-L\$(SRCDIR)/../pth-1.1b3/.libs' \ LIBS="-lpthread" \ ./configure \ --with-layout=GNU \ --target=apache \ --prefix=/tmp/apache-pthread $ make $ make install