[Zope-dev] pthreads and BSD

Giorgos Verigakis verigak@algol.vtrip-ltd.com
Fri, 24 Aug 2001 20:21:08 +0300 (EEST)


Hello, I was having some problems on Zope's perfomance on FreeBSD and
OpenBSD. I've sent some mails to zope/freebsd-hackers and openbsd-tech
but I couldn't get any usefull info.
To summarize, I've written a small program (see below) that makes a lot
of requests to Zope. While on Linux I didn't have any problems, on
FreeBSD and OpenBSD it slowed Zope down and when I tried to access some
page from my browser it would make even more than 5 minutes to load.
I tried this with both 2.3.3 and 2.4.0 + HotFix.
Now, when I compile python 2.1.1 with PTH instead of pthreads, the
problem is solved and Zope responses normally.

So, is this a bug on Free/OpenBSD's libc_r or is it Zope's?
(I tried FreeBSD 4.3-Release, FreeBSD 4-stable and OpenBSD 2.9-Release)

Giorgos Verigakis

PS: please cc me, because I'm not on this list


--------------------- 8< ---------------------
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>

int main(int argc, char *argv[])
{
	struct sockaddr_in sa;
	struct hostent *hp;
	int s, c;
	int i, t, len;
	unsigned long sleeptime;
	char request[128];
	char *url="/foo";

	if (argc != 4) {
		printf("Usage: %s <host> <port> <rate>\n", argv[0]);
		printf("rate in hits/sec\n");
		exit(1);
	}

	if ((hp = gethostbyname(argv[1])) == NULL) {
		printf("error looking up host\n");
		exit(1);
	}

	sprintf(request, "GET %s HTTP/1.0\015\012\015\012", url);
	len = strlen(request);
	sleeptime = (1 / atof(argv[3])) * 1000000;

	bzero(&sa, sizeof(sa));
	bcopy(hp->h_addr, (char *)&sa.sin_addr, hp->h_length);
	sa.sin_family = hp->h_addrtype;
	sa.sin_port = htons(atoi(argv[2]));

	for (i = 0;; i++) {
		if (( s = socket(hp->h_addrtype, SOCK_STREAM, 0)) < 0) {
			printf("Socket error\n");
			continue;
		}

		if (c = connect(s, (struct sockaddr *) &sa, sizeof sa) < 0) {
			printf("Connection error\n");
			close(s);
			continue;
		}

		t = write(s, request, len);
		printf("i=%d: %d bytes\n", i, t);

		usleep(sleeptime);

		close(c);
		close(s);
	}

}
--------------------- 8< ---------------------