I'm having an issue keeping the memory usage of a web spider i wrote down. It runs fine without any issues or bugs except that after a few hours the computer runs out of memory and i get an error that there isnt enough available memory to allocate what i need. I'm running on Windows XP with 4 GB of RAM, watching task manager shows that it steadily climbs
i'm using threading to keep the program running at a decent speed (20 threads) and i spawn threads that detach to do mysql statements as well
i've looked everywhere for help on this issue including here, and seen that there were bug fixes in past versions of perl but it seems like it is a persistent issue.
im using perl 5.10 and threads 1.67
i've told threads to make the stack size 4096 and i've even explicitly declared the detached mysql threads undef when they're done. Final output is as follows:
Out of memory! Callback called exit at C:/perl/lib/HTML/Element.pm line 234. Callback called exit at C:/perl/lib/HTML/Element.pm line 234. Perl exited with active threads: 19 running and unjoined 0 finished and unjoined 2 running and detached
the full program is 700 lines so i've only posted how i spawn the threads
use threads ('stack_size' => 4096); use threads::shared; use threads qw(yield); use Thread::Queue; my $sched = new Thread::Queue; my $parser_thread1 = async { main_loop();}; my $parser_thread2 = async { main_loop();}; my $parser_thread3 = async { main_loop();}; #goes to 20, not elegant but it works $parser_thread1->join; $parser_thread2->join; $parser_thread3->join; #goes to 20 as well sub main_loop { while( schedule_count() and $hit_count < $hit_limit #could be commented out and time() < $expiration and ! $QUIT_NOW ) { yield(); process_url( next_scheduled_url() ); } return; } my $mysql_thread = threads->create('send_parts_to_db', $parts)); $mysql_thread->detach; undef $mysql_thread; #as suggested by someone on perlmonks
As shown i use the same mysql_thread variable for all mysql insertions... but if i ever get an error i can have up to thread # 170+ Is that normal?
In reply to Threads memory consumption is infinite by Godsrock37
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |