I am trying to understand your situation. Before suggesting any actual code, I'd like to sanity check my understanding. I think that you want to have multiple DB and remote server interactions underway at the same time? A possible scenario is like below.

The main program queues new work onto a queue that is accessible by multiple worker threads. There will be multiple Worker threads. If a worker thread is not busy and work is available, it accepts new work and processes the DB and remote server work items. If your DB and remote server can handle multiple operations at the same time, this will speed things up.

Ultimately there will be a maximum throughput. Some sort of throttle will probably be necessary on the main program so that the work queue doesn't grow to an infinite size. I suspect there will be other complications with error handling. But is this general idea what you seek?

Main Program: there is just one of these while (I don't know) { generate work item push work onto shared work queue } Worker Bee Thread: There will be N of these running in parallel #each worker gets its own connections connect to DB connect to remote server while (pop from work work queue, if queue not empty) { manipulate DB send to remote server }
Update: Clarification is needed on this point: Remote server connection and sending request is taking about 10ms due to latency Surely you are not connecting and disconnecting for each server request? Connect once, use many. However, 10ms for remote communication overhead doesn't strike me as particularly long. I work with some networks where a simple ping response time takes 60-70ms. BTW, you don't mention DB processing time, but that can be very significant. A DB commit is "expensive" and requires multiple disk operations. Search for "ACID DB". I suspect the DB operation takes longer than the "send to remote server" operation.

In reply to Re: Need suggestion on problem to distribute work by Marshall
in thread Need suggestion on problem to distribute work by smarthacker67

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.