Skip to content
This repository was archived by the owner on Jul 12, 2023. It is now read-only.

Limit Concurrency #29

Merged
merged 2 commits into from
Dec 15, 2016
Merged

Limit Concurrency #29

merged 2 commits into from
Dec 15, 2016

Conversation

rouzwawi
Copy link
Member

@rouzwawi rouzwawi commented Dec 14, 2016

todo

  • tests
  • documentation

depends on #23

@rouzwawi rouzwawi force-pushed the limit-concurrency branch 8 times, most recently from 8869805 to 3743521 Compare December 14, 2016 17:18
@rouzwawi rouzwawi changed the title WIP - Limit Concurrency Limit Concurrency Dec 14, 2016
} else {
LOG.info("{} executing retry #{}", key.toKey(), state.data().tries());
// todo: send info event, could not run because resource limit reached
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will this come in this PR?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have a separate ticket for it, so I'll leave the todos.

return emptySet();
}

return Sets.newHashSet(workflowOpt.get().schedule().resources());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is this preferred over new HashSet<>()? I can see the use in pre-jdk7 but not since <> was ok.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mainly habit :)

@rouzwawi rouzwawi force-pushed the limit-concurrency branch 6 times, most recently from 4b22937 to adbe922 Compare December 14, 2016 21:12
final Map<String, Long> currentResourceUsage =
activeStates.parallelStream()
.filter(entry -> !timedOutInstances.contains(entry.workflowInstance()))
.filter(entry -> entry.runState().state() != RunState.State.QUEUED)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After we have filtered out the instances about to time out, shouldn't we then filter only instances whose state is RUNNING?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That was what I did in my first iteration, but it causes a race.

Example: The scheduler will dequeue some instances on tick 1. These go into submitting (not yet running). The scheduler ticks again and sees free slots in the same resources and dequeues even more instances.

By looking at instances not in queued, we avoid this condition.

.filter(entry -> shouldExecute(entry.runState()))
.collect(toCollection(Lists::newArrayList));
Collections.shuffle(eligibleInstances);

Copy link
Contributor

@TinaRanic TinaRanic Dec 14, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it make sense the Resource related methods to be moved to something like ResourceManager?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That makes sense, but I would like to do it at a later point when the patterns have settled a bit.

activeStates.parallelStream()
.map(InstanceState::workflowInstance)
.map(WorkflowInstance::workflowId)
.distinct()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this really needed given you put them in a map in the next step?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, the collector complained about duplicate keys otherwise.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah, these parallel streams… so one could use .collect(toConcurrentMap()) instead

@bergman
Copy link
Contributor

bergman commented Dec 15, 2016

👍

By doing the transition and counter updates on the calling thread and
then enqueing the persistence and output handler calls on the state
manager queue.
@rouzwawi rouzwawi merged commit c711646 into master Dec 15, 2016
@rouzwawi rouzwawi deleted the limit-concurrency branch December 15, 2016 16:29
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants