Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re^2: Thread::Apartment, how do I use main:: subs?

by wilsond (Scribe)
on May 12, 2009 at 05:19 UTC ( #763414=note: print w/ replies, xml ) Need Help??


in reply to Re: Thread::Apartment, how do I use main:: subs?
in thread Thread::Apartment, how do I use main:: subs?

What I've done (maybe temporary) is to use main to spawn a package called LeafBridge::Client within the main thread and use that to spawn the LeafBridge::Client::Controller apartment. On spawn of this controller, I pass in the handle to $self (LB::Client). LB::C::Controller spawns all of the other apartments by calling $client->spawnApartment($controllerClient). $client being the LB::Client handle that was passed in and $controllerClient being the T::A::Client handle. That spawnApartment is called in the context of the LB::C::Controller apartment thread, not in the main thread. Since LB::Client doesn't do anything except run a loop that calls $controller->tick every second, it doesn't really do anything else but provide access to the apartment creation functions and to create the first apartment (LB::C::Controller). LB::C::Controller tracks all apartment threads and allows any apartment to talk to any other apartment by calling $controller->thread('LeafBridge::Client::XMPP')->send(@args) (the thread method passes the T::A::Client handle of the LB::C::XMPP apartment to the caller; send() is a method within the LB::C::XMPP apartment itself (it could be any arbitrary method in the requested apartment thread)). It seems to work well for now. It feels hackish, but it's the best I could do with the knowledge I have right now.


I'm a Linux user. You wouldn't know it since I mostly ask Windows questions. Whee.
If you want to do evil, science provides the most powerful weapons to do evil; but equally, if you want to do good, science puts into your hands the most powerful tools to do so.
- Richard Dawkins


Comment on Re^2: Thread::Apartment, how do I use main:: subs?
Select or Download Code
Re^3: Thread::Apartment, how do I use main:: subs?
by wilsond (Scribe) on May 20, 2009 at 00:35 UTC

    By the way, the "workaround" I've presented above is terribly inefficient. My app is running at 400MB right now and it hardly does more than load. Memory leak anyone? It's beyond time for me to be digging myself out of that leak. *whee*


    I'm a Linux user. You wouldn't know it since I mostly ask Windows questions. Whee.
    If you want to do evil, science provides the most powerful weapons to do evil; but equally, if you want to do good, science puts into your hands the most powerful tools to do so.
    - Richard Dawkins
      My app is running at 400MB right now and it hardly does more than load.

      I found the same thing when I played with T::A a year or two ago. Huge memory usage and glacial speed for relatively little gain.

      In my experience, nearly everything you want to do with threads is easier, lighter and faster using threads directly. So long as you're not wedded to everything being OO, there is rarely a genuine need to pass complex objects around between threads.


      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.

      It wasn't a memory leak. I told it to make a pool of 30 threads at startup. 30 * too much memory = way too much memory. I have it down to 90MB right now, but that is still very, very high. Lots of tweaking to go.


      I'm a Linux user. You wouldn't know it since I mostly ask Windows questions. Whee.
      If you want to do evil, science provides the most powerful weapons to do evil; but equally, if you want to do good, science puts into your hands the most powerful tools to do so.
      - Richard Dawkins

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (6)
As of 2014-07-29 00:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (211 votes), past polls