in reply to Splitting one large timeout into few smaller ones..

Could you fork each task and wait for it, setting a timeout in the wait?

Caution: Contents may have been coded under pressure.
  • Comment on Re: Splitting one large timeout into few smaller ones..

Replies are listed 'Best First'.
Re^2: Splitting one large timeout into few smaller ones..
by Eyck (Priest) on Apr 07, 2005 at 14:56 UTC
    Tasks cannot be reordered. Lets look at something like this
    1. Start processing/new transaction
    2. Get message from spool(requires contacting remote spool)
    3. verify signature (requires contacting remote keyservers)
    4. uncompress/convert/split
    5. Send required files(remote...)
    6. Request additional parts(remote..)
    7. End transaction

    Or, better yet, think of pop3 client,

    1. Authenticate
    2. Get list of new mails
    3. Get mail body (repeat) ...

    Imagine what happens when you implement it like this:

    auth(); @uidls=getuidls(); foreach $uidl (@uidls) { fork || getmail($uidl); };

    getting back to my original problem, you can easily put timeout protection inside getuidl and getmail, but what you created is either instant DOS against your provider, and yourself (try that code with 1000s of mails to download..).

    Not to mention that now you have to devise a clever way for generating for example unique filename for every mail you're downloading and few similar headaches.

    Of course if you're trying to write reasonable code, and use just one connection for downloading those mails, you need to devise a clever scheme of locking and passing socket fd around to your children etc...

      I didn't suggest you reorder tasks. You fork and wait. If the wait times out, you kill the child and error out. You only have one spawned sub-process at a time.

      Update: you'd have to rig up the timeout yourself, depending on what your system supports. You want to poll and sleep until the process completes, or until you've waited long enough for it. Or you could set an alarm, do a wait, and if the wait returns, unset the alarm.


      Caution: Contents may have been coded under pressure.
        Please provide sample code/pseudocode, because I don't quite follow. Here's how it looks right now:
        Event->idle(min=>$mint,max=>$maxt, cb=> [$sth,"method"], max_cb_tm=>$timeout,);
        where $timeout is my large timeout value, roughly every $mint seconds $sth->method() is called, if it takes longer then $timeout it is killed off.

        I don't know where am I supposed to fork.