From owner-freebsd-threads@FreeBSD.ORG Thu Jul 31 19:31:40 2003 Return-Path: Delivered-To: freebsd-threads@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id D5D1637B401 for ; Thu, 31 Jul 2003 19:31:40 -0700 (PDT) Received: from ns.aratech.co.kr (ns.aratech.co.kr [61.34.11.200]) by mx1.FreeBSD.org (Postfix) with ESMTP id 19C5D43F93 for ; Thu, 31 Jul 2003 19:31:40 -0700 (PDT) (envelope-from tj@atj.dyndns.org) Received: from tj.aratech.co.kr ([61.34.11.212] helo=atj.dyndns.org ident=mail) by ns.aratech.co.kr with esmtp (Exim 3.36 #1 (Debian)) id 19iOhv-0001OH-00 for ; Fri, 01 Aug 2003 10:27:47 +0900 Received: from tj by atj.dyndns.org with local (Exim 4.20) id 19iOTN-00085r-31 for freebsd-threads@freebsd.org; Fri, 01 Aug 2003 10:12:45 +0900 Date: Fri, 1 Aug 2003 10:12:45 +0900 To: freebsd-threads@freebsd.org Message-ID: <20030801011245.GA31048@atj.dyndns.org> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.5.4i From: TeJun Huh Subject: Regarding KSE X-BeenThere: freebsd-threads@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list Reply-To: tejun@aratech.co.kr List-Id: Threading on FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 01 Aug 2003 02:31:41 -0000 Hello, I'm currently evaluating various thread packages for a paper. The focus is on aptness for Internet servers, so performance and scalability are main concerns. I'm trying to evaluate M:N threading (scheduler activaton) and 1:1 threading using KSE and maybe traditional libc_r on FreeBSD 5.1. I've encountered several problems with KSE. I made a small test case program to demonstrate the problem. The program accepts one argument telling it how many threads should be created. The main thread creates given number of threads with user allocated stack (pthread_attr_setstack()). After createing all threads the main thread waits forever. Each created thread reads fd 0 (stdin). After reading some input from stdin, it prints the input and exits. The source of test program is appended at the tail of this mail. First problem is that I can hang whole operating system (even ctrl-alt-sec doesn't work). Creating 160 threads and pressing ctrl-c after all threads are created hang the kernel reliably. Secondly, I cannot get more than 150 threads active at once. I guess this is the limit of KSEs per process. Is there any way to increase this number? I'm looking at ten thousands threads at least. Thanks in advance. /*****************************************************************/ /***************** test program source follows *******************/ /* compile with '$ gcc -D_THREAD_SAFE -o test test.c -lkse' ******/ /*****************************************************************/ #include #include #include #include static void * service_startup(void *arg) { char buf[64]; int ret; printf("service startup %d\n", (int)arg); if ((ret = read(0, buf, sizeof(buf)-1)) < 0) printf("read failed %d\n", errno); else { buf[ret] = '\0'; printf("read: \"%s\"\n", buf); } printf("exiting\n"); return NULL; } #define STACK_SIZE 32768 int main(int argc, char **argv) { static const struct timespec ts1sec = { 1, 0 }; int nr, i; if (argc < 2) { fprintf(stderr, "babo\n"); return 1; } nr = atoi(argv[1]); for (i = 0; i < nr; i++) { void *stack; pthread_t thr; pthread_attr_t attr; if ((stack = malloc(STACK_SIZE)) == NULL) { fprintf(stderr, "malloc failed\n"); return 1; } pthread_attr_init(&attr); pthread_attr_setdetachstate(&attr, 1); pthread_attr_setstack(&attr, stack, STACK_SIZE); if (pthread_create(&thr, &attr, service_startup, (void *)i) < 0) { fprintf(stderr, "pthread_create failed\n"); return 1; } } while (1) nanosleep(&ts1sec, NULL); return 0; }