Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re^9: Consumes memory then crashs

by BrowserUk (Patriarch)
on Mar 25, 2012 at 09:36 UTC ( [id://961476]=note: print w/replies, xml ) Need Help??


in reply to Re^8: Consumes memory then crashs
in thread Consumes memory then crashs

my point was merely that threaded code is hard to get right ...

If you don't follow the rules, the simplest things can screw up:

perl -e "fork while fork"
And here's a bit of the output:

Don't blame Perl or threads because your C runtime libraries are paying lip service to the realities of concurrency.

If it doesn't take care of things, you'll have to do it.

The addition of my $old = select $fh; $|++; select $old; might sort out the interleaving problem.

And use threads stack_size => 4096; will substantially reduce the memory footprint.

But that's all irrelevant. Like saying a bendy-bus is 25x better than a family car because it can carry 100 people.

The 500 do-almost-nothing threads in your code

Not my code!

And what is the point of running 500 threads?

It takes ~40MB to run 4 threads. That's a whole 2% of the ram of the lowest spec commodity box you'll ever find for sale.

And with 4 threads, it takes:

c:\test>junk39 -THREADS=4 >nul 51.556654214859 at C:\test\junk39.pl line 55, <> line 1

51 seconds to pull 501 names.

With 8 threads:

c:\test>junk39 -THREADS=8 >nul 49.5222151279449 at C:\test\junk39.pl line 55, <> line 1.

49 seconds. So doubling the number of threads gained almost nothing. The pipe or the remote server is the limiting factor.

I'd love to compare like with like, but having installed the 131 file that make up the POE behemoth:

ppm> install 1 Downloading POE-1.352...done Downloading POE-Test-Loops-1.351...done Unpacking POE-1.352...done Unpacking POE-Test-Loops-1.351...done Generating HTML for POE-1.352...done Generating HTML for POE-Test-Loops-1.351...done Updating files in site area...done 131 files installed

I was still missing stuff your script needed:

c:\test>mbethke.pl Can't locate POE/Component/Client/HTTP.pm in @INC (@INC contains: c:/P +erl64/site/lib c:/Perl64/lib .) BEGIN failed--compilation aborted at (eval 33) line 1. could not import qw(Component::Client::HTTP) at C:\test\mbethke.pl lin +e 4 BEGIN failed--compilation aborted at C:\test\mbethke.pl line 4.

So, then I tried to download that, but one of its dozen or so dependancies was unavailable:

1: POE-Component-Client-HTTP a HTTP user-agent component Version: 0.945 Released: 2012-03-10 Author: Rocco Caputo <rcaputo@cpan.org> Provide: POE::Component::Client::HTTP version 0.945 Provide: POE::Component::Client::HTTP::Request version 0.945 Provide: POE::Component::Client::HTTP::RequestFactory version 0.945 Provide: POE::Filter::HTTPChunk version 0.945 Provide: POE::Filter::HTTPHead version 0.945 Require: HTTP::Headers version 5.81 or better Require: HTTP::Request version 5.811 or better Require: HTTP::Request::Common version 5.811 or better Require: HTTP::Response version 5.813 or better Require: HTTP::Status version 5.811 or better Require: Net::HTTP::Methods version 5.812 or better Require: POE version 1.312 or better Require: POE::Component::Client::Keepalive version 0.269 or better Require: Socket::GetAddrInfo version 0.19 or better Require: Test::More version 0.96 or better Require: Test::POE::Server::TCP version 1.14 or better Require: URI version 1.37 or better Repo: ActiveState Package Repository CPAN: http://search.cpan.org/dist/POE-Component-Client-HTTP-0.945/ ppm> install 1 ppm install failed: Can't find any package that provides Socket::GetAd +drInfo for POE-Component-Client-HTTP Can't find any package that provides Socket::GetAddrInfo for POE-Compo +nent-Resolver

It might take a bit less memory, but it certainly won't be quicker because the limitation is the pipe and/or remote server.

I guess I could try installing the 270 module mojo behemothe, but it never terminates:

c:\test>zwon >nul Too late to run CHECK block at c:/Perl64/site/lib/EV.pm line 84, <> li +ne 501. Terminating on signal SIGINT(2)

One way uses 0.5% of my memory; only needs what came installed with my Perl installation; and works.

The other two require gobs of extra code and either don't run or never finish. The decision is an easy one for me.

All that's left for me to do is free up about 50 MB of space on my harddrive by throwing away all the crap installed to write this post:

ppm> uninstall POE POE: uninstalled ppm> uninstall mojolicious Mojolicious: uninstalled

There, all done.


With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

The start of some sanity?

Replies are listed 'Best First'.
Re^10: Consumes memory then crashs
by mbethke (Hermit) on Mar 25, 2012 at 23:33 UTC

    Don't fret over the couple of kilobytes of crap® you had to download. I installed a whole Strawberry Perl just to test your code on Windows :)

    Don't blame Perl or threads because your C runtime libraries are paying lip service to the realities of concurrency.

    Assuming this to be the case, I have bad news for you: so does Windows' C library. Here's a snippet of your "fixed" code's output on the latest Strawberry on XP---the runtime was just as atrocious as on Linux BTW:

    $ uniq -c outfile |head -n10 819 Thread 2 1 ThThread 1 818 Thread 1 1 ThThread 3 818 Thread 3 1 ThThread 4 818 Thread 4 1 ThThread 5 818 Thread 5 1 ThThread 6

    At Thread 20 it gets a bit more irregular ...

    If it doesn't take care of things, you'll have to do it.

    No, you'll have to do it. If you want to show it can be done correctly using threading that is.

    The addition of my $old = select $fh; $|++; select $old; might sort out the interleaving problem.

    That doesn't sound overly confident ...

    And what is the point of running 500 threads?

    Contrary to what you wrote, a thread is not just a means of improving efficiency on multiprocessors. It's just a logical program flow that's supposed to correspond to a certain task, and there are plenty of tasks that could make use of hundreds of threads: simulations, network monitoring, sensor data collection, crawling slow sites, etc. If threading in the "use threads" sense was halfway efficient for it that is.

    It takes ~40MB to run 4 threads. That's a whole 2% of the ram of the lowest spec commodity box you'll ever find for sale.

    You still get 1 GB netbooks, but whatever. So you need only twice the memory to get correct results most of the time, with nondeterministic failures in-between, after the first "Service Pack". At least the other side's IIS doesn't seem to scale either so you don't have to put the thread code to this test. Sorry, even though I have conceded from the start that there are rare cases where threads are the model of choice this is not gonna convince me that we're looking at one.

    As for POE on Windows, on my fresh Strawberry install I can type "cpan POE" and then "cpan POE::Component::Client::HTTP" to end up with a working installation of everything required. Don't blame POE when ActiveState's repository absorbs excrement.

    One way uses 0.5% of my memory; only needs what came installed with my Perl installation; and works. The other two require gobs of extra code and either don't run or never finish. The decision is an easy one for me.

    No, it does not work, at least not reliably. That was the whole point. The failure rate may be acceptable for you but I don't think it's "a simple solution to thread this properly" as the OP asked.

      on the latest Strawberry

      Ah! That's built with the gcc runtime isn't it!


      With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority".
      In the absence of evidence, opinion is indistinguishable from prejudice.

      The start of some sanity?

        on the latest Strawberry
        Ah! That's built with the gcc runtime isn't it!

        Yes. If you insist, here's some uniq'd output from a freshly installed ActivePerl 5.14.2 which they tell me is built with VisualStudio:

        $ uniq -c outfile | head -n25 682 Thread 2 1 Thread 2Thread 3 681 Thread 3 1 Thread 3Thread 4 681 Thread 4 1 Thread 4Thread 5 681 Thread 5 1 Thread 5Thread 1 681 Thread 1 1 Thread 1Thread 6 681 Thread 6 1 Thread 6Thread 7 681 Thread 7 1 Thread 7Thread 8 681 Thread 8 1 Thread 8Thread 9 681 Thread 9 1 Thread 9Thread 10 629 Thread 10 1 ThThread 11 629 Thread 11 1 ThThread 12 629 Thread 12 1 ThThread 13 629 Thread 13

        If Perl's threading primitives' semantics were broken unless compiled with a runtime that <<10% of the installed Perls use, I'd still call Perl broken. If I can reproduce the bug on each an every Perl I look at though nobody seems to have complained about the primitives you use being buggy, chances are your Perl code is broken.

        I don't know which it is, but it remains that I haven't seen a reliable threaded implementation yet. I for one would centralize the printing and use another Queue to feed back the results from the threads as at least the queue locking seems (as far as I've looked which is not very deep at all) to be working. But then again, why? I don't get the resistance against POE which fits on a floppy disk and is some 20kLOC without POD when common threading implementations are on the same order of magnitude (of rather more complex C code at that) and 20 MB of RAM are insignificant to you.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://961476]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (7)
As of 2024-03-28 11:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found