0

Requirement: In a poller / worker scenario, pollers should stop polling remote service until a worker is available to take the task.

Background: Due to throttling constraints on the number of requests to the remote service, I am trying to segregate polling from the consumers. The constraint here is, that once a task if picked up by a poller, it will timeout if not processed within a certain time. And our consumers can be arbitrarily long running (10s to 10minutes).

Currently looking at the direct solutions, SynchronousQueue seems to be the most simplified approach.

The problem is that if I have 2 pollers and 4 consumers, then while the 4 consumers are processing, the pollers will first pick/poll two tasks from remote, and then wait for consumers to be available. this will cause the 2 tasks to timeout.

Is there a decent workaround this? Or should i be going for lock based mechanism (like: Semaphore) ?

mathpal
  • 91
  • 9
  • Why are you trying to decide which consumers you want to push work to? Just have the consumers *pull* when they're free. – Andrew Henle Apr 20 '18 at 20:49
  • I am not trying to enforce which consumer gets the work, but rather that once all consumers are occupied, there should not any more polling for new tasks. I can't have all consumers poll directly, as in a distributed setup this will result in severe throttling. As number of consumers can be quite large (50+ threads) per host. and almost 15-20 hosts. Therefore, moving polling to 1-2 poller threads can reduce the overall poll rate from my service. – mathpal Apr 20 '18 at 20:54
  • Please, add language tag. Currently, only your reference notes about java. – Tsyvarev Apr 20 '18 at 22:47

0 Answers0