Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

Howdy monks! So I have been trying to code a script to fetch info for game, and I found with out threads this is simply to slow to be effective. However, In an attempt to make things faster I added threading, but now when I run the script it quickly shoots up to 4gb memory then crashes. Now I am completely new to this so some one school me on what I'm doing wrong so this never happens again. note, the var $names is 16k lines long

use threads; use warnings; use LWP::Simple; $names=''; my $re69='((?:[a-z0-9_]+))'; open (lookup, '>>rstlookup.txt'); my @a = (); my @b = (); print "Starting main program\n"; my $nb_process = 16832; my $nb_compute = 20; my $i=0; my @running = (); my @Threads; while (scalar @Threads < $nb_compute) { @running = threads->list(threads::running); while ($names =~ m/$re69/isg) { if (scalar @running < $nb_process) { $name = $1; my $thread = threads->new(\&lookup); push (@Threads, $thread); my $tid = $thread->tid; } @running = threads->list(threads::running); foreach my $thr (@Threads) { if ($thr->is_running()) { my $tid = $thr->tid; } elsif ($thr->is_joinable()) { my $tid = $thr->tid; $thr->join; } } } @running = threads->list(threads::running); $i++; } while (scalar @running != 0) { foreach my $thr (@Threads) { $thr->join if ($thr->is_joinable()); } @running = threads->list(threads::running); } sub lookup { my $name2 = $name; my $lookup = get("http://rscript.org/lookup.php?type=track&time=62 +899200&user=".$name2."&skill=all"); print "Looking up $name2...\n"; $reg1='(ERROR)'; if ($lookup) { my $re1='(gain)'; my $re2='(:)'; my $re3='(Overall)'; my $re4='(:)'; my $re5='(\\d+)'; my $re6='(:)'; my $re7='(\\d+)'; my $re=$re1.$re2.$re3.$re4.$re5.$re6.$re7; if ($lookup =~ m/$re/isg) { print lookup "$name2 $7\n"; } } if ($lookup =~ m/$reg1/isg) { print lookup "$name2 doesn't exist \ +n" } else{ print lookup "$name2 0\n"; } } close (lookup);

In reply to Consumes memory then crashs by allhellno

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (7)
As of 2024-04-18 12:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found