Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 1 Oct 2005 15:58:49 -0400 (EDT)
From:      John Gillis <zefram@zefram.net>
To:        Anton Berezin <tobez@FreeBSD.org>
Cc:        perl@FreeBSD.org
Subject:   Re: ports/86687: Perl ithreads coredump
Message-ID:  <20051001154734.E17540@dante.zefram.net>
In-Reply-To: <200509282107.j8SL7oGO005442@freefall.freebsd.org>
References:  <200509282107.j8SL7oGO005442@freefall.freebsd.org>

next in thread | previous in thread | raw e-mail | index | archive | help
	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;
}




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20051001154734.E17540>