From owner-freebsd-perl@FreeBSD.ORG Sat Oct 1 19:58:50 2005 Return-Path: X-Original-To: perl@FreeBSD.org Delivered-To: freebsd-perl@FreeBSD.ORG Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 05D2316A41F; Sat, 1 Oct 2005 19:58:50 +0000 (GMT) (envelope-from zefram@zefram.net) Received: from dante.zefram.net (dante.zefram.net [66.92.77.109]) by mx1.FreeBSD.org (Postfix) with ESMTP id 069DB43D46; Sat, 1 Oct 2005 19:58:48 +0000 (GMT) (envelope-from zefram@zefram.net) Received: by dante.zefram.net (Postfix, from userid 1000) id A4B5813A; Sat, 1 Oct 2005 15:58:49 -0400 (EDT) Received: from localhost (localhost [127.0.0.1]) by dante.zefram.net (Postfix) with ESMTP id 9B0DB94; Sat, 1 Oct 2005 15:58:49 -0400 (EDT) Date: Sat, 1 Oct 2005 15:58:49 -0400 (EDT) From: John Gillis To: Anton Berezin In-Reply-To: <200509282107.j8SL7oGO005442@freefall.freebsd.org> Message-ID: <20051001154734.E17540@dante.zefram.net> References: <200509282107.j8SL7oGO005442@freefall.freebsd.org> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Cc: perl@FreeBSD.org Subject: Re: ports/86687: Perl ithreads coredump X-BeenThere: freebsd-perl@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: maintainer of a number of perl-related ports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 01 Oct 2005 19:58:50 -0000 Here's a sample script that creates the same core dump. It creates 50 threads that look up 1000 hostnames from a database of unique hostnames. They are all unique. It then just runs gethostbyname. The actual script uses IO::Socket::INET... but I didn't want to connect to so many hosts at once.. Without further adieu, here's the script: #!/usr/bin/perl -w use threads; use Socket; $SIG{INT} = \&catch_die; my @threads; my $shutdown :shared = 0; for (1 .. 50) { shift @threads, threads->new(\&thr); } sub thr { my $i = 0; my $dbi = DBI->connect("DBI:mysql:database=spider","xxx","xxx") or die "Unable to connect to MySQL: $!\n"; my $sth = $dbi->prepare("SELECT id, host FROM site LIMIT " . (threads->tid * 1000) . ", 1000"); $sth->execute; return if !$sth->rows; while ($shutdown == 0 && $i < 999) { my @row = $sth->fetchrow(); my $host = $row[1]; my $iaddr = gethostbyname($host) || print "Host $host not found."; $i++; } } while ($shutdown == 0) { sleep(5); } print "Waiting for threads\n"; foreach $thread (@threads) { $thread->join; } sub catch_die { # Shit. Gotta clean our act up. print "Closing once current page has been indexed.\n"; $shutdown = 1; }