Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I'm not familiar with the specifics of your problem, but it sounds a lot like <a href="http://en.wikipedia.org/wiki/Hazard_%28computer_architecture%29#Eliminating_hazards" rel="nofollow noreferrer">data hazards</a> in pipeline CPUs.</p> <p>In your case you want to maximize the utilization of your functional units (streams) without introducing data hazards. Maybe you can write a simple scheduler that looks ahead into the next n instructions and schedules them on to streams?</p> <pre><code>/** * Keeps track of which stream is scheduled to process each account. * If an account is not currently scheduled to be processed, it doesn't appear in the keySet of this map. */ Map&lt;Account, Stream&gt; accountsInFlight; // use a synchronized implementation void schedule(Instruction instruction) { // If the input account is in flight somewhere, use that stream if (accountsInFlight.containsKey(instruction.getInAccount())) { scheduleToStream(instruction, accountsInFlight.get(instruction.getInAccount())); // If the output account is in flight somewhere, use that stream } else if (accountsInFlight.containsKey(instruction.getOutAccount())) { scheduleToStream(instruction, accountsInFlight.get(instruction.getOutAccount())); // If neither are in flight, this is a good candidate for parallel execution, // put it in a different stream } else { Stream stream = // pick a stream (maybe the one with the shortest queue?) scheduleToStream(instruction, stream); } } private void scheduleToStream(Instruction instruction, Stream stream) { stream.addToQueue(instruction); // Update accountsInFlight accountsInFlight.put(instruction.getInAccount(), stream); accountsInFlight.put(instruction.getOutAccount(), stream); } // Remove accounts from the map when the instruction completes </code></pre> <p>Note that this is all fake code: it's not optimized nor does it cover all cases correctly, but maybe it'll give you some ideas to get started.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload