in reply to Re: a question on threads
in thread a question on threads
i assume that a combination of our two approaches might be sufficient even for time of high traffic & loads.sub event_handler { my $worker_thread = sub { my $row = shift; my $event = SOD::EventCooker->new($row); if (exists $p_ids{$row->{'ev_p_id'}}) { lock $sessions{$p_ids{$row->{'ev_p_id'}}}; my $session = thaw sessions{$p_ids{$row->{'ev_p_id'}}}; $event->evaluate($session->{PLAYER}->{GAMESTATS}); $sessions{$p_ids{$row->{'ev_p_id'}}} = freeze $session; } else { $event->evaluate; } }; my $dist_thread = sub { my @threads; my $thread_time = time; my $dbh = DBI->connect("DBI:mysql:database=$appdata{DBBASE}" +, $appdata{DBUSER}, $appdata{DBPASS}, { RaiseError => 1, AutoCommit => 1 }) || die $dbh->errstr; my $res = $dbh->selectall_hashref("SELECT * FROM event WHERE + ev_time<=$thread_time", 'ev_time'); $dbh->do("DELETE FROM event WHERE ev_time<=$thread_time"); map { push @threads, threads->new($worker_thread->($res->{$_}) +); } sort keys(%$res); map { $_->detach; } @threads; $dbh->disconnect; undef $dbh; }; while (1) { sleep 1; last if $tflag; threads->new($dist_thread)->detach; } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: a question on threads
by BrowserUk (Patriarch) on May 11, 2005 at 09:19 UTC | |
by thcsoft (Monk) on May 12, 2005 at 02:46 UTC |