Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
Well, what I need to do is a bit more complicated than that ;-).

Basically, I have a very complex object of class WeBiText. The object carries out a complex search algorithm, part of which, called the L1 Search, does a number of searches on Yahoo, that produces hits to be processed by the rest of the search algorithm. Because the Yahoo searches take a long time to execute, I want the L1 search to be done in a separate thread, and in such a way that it communicates the hits it finds back to the main search algorithm as soon as it finds them. That way, the main search doesn't have to wait for the complete set of L1 hits before it starts doing its work.

There are issues that complicates things.
  1. WeBiText is not thread safe, because it needs some modules which are not thread-safe.
  2. A consequence of this is that all threads in the thread pool must be created before any instance of WeBiText is created.
  3. Another consequence is that WeBiText instances can't be shared between threads and must instead be serialized and deserialized across threads.
  4. Also, I run hundreds of automated tests on WeBiText, using PerlUnit
A consequence of points 2 and 4, is that threads must be "reusable", otherwise I would have to create hundreds of threads at the start, before I run the tests which create WeBiText instances. So the pool must allow a client to "reserve" a thread and later on release it so it can be reused. This is one functionality that Thread::Pool provides.

Also, a consequence of point 3 is that the L1 search cannot directly notify the WeBiText instance running in the main thread when it finds a new L1 hit, because it doesn't receive a shared instance of that WeBiText instances. The best that can be done is for the L1 thread to receive a serialization of the master thread's WeBiText instance, and use that serialization to recreate the instance in the L1 search thread. But any change to the state of that recreated instance won't affect the state of the original instance running in the main thread.

My solution to this is for the L1 search to put its hits on an "outgoing" queue that is shared between the two threads. The problem is that both threads must know about this queue. But since WeBiText instances must be created after the threads are created, it means that any queue that it creates cannot be shared with those threads. So, it's the pools responsibility to provide a results queue that is associated with a particular thread. Those hits queues must be reserved and released just like the threads.

Note that this behaviour is not provided by Thread::Pool, and I need to implement it myself anyway. But since Thread::Pool already provides reusable threads, I thought I'd start from it. Maybe that was a mistake.

As you can see, this is not something that can be implemented in a couple of lines ;-).

In reply to Re^8: Why do my threads sometimes die silenty? by alain_desilets
in thread Why do my threads sometimes die silenty? by alain_desilets

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 sharing their wisdom with the Monastery: (4)
As of 2024-04-26 00:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found