Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update sequence impl to tune controller memory consumption #2387

Merged
merged 6 commits into from
Jun 20, 2017

Conversation

starpit
Copy link
Contributor

@starpit starpit commented Jun 15, 2017

Fixes #2386

This PR changes SequenceActions to use foldLeft rather than scanLeft. The change requires the introduction of a new accumulator data structure, to maintain the accumulated state for the reduction. The accumulated state includes an array of handles to logs (for the components), the cumulative duration, and a few other bits needed for creation of the final sequence activation record.

This fix also patches a closely related memory drag, caused by the way timeouts of sequence invocations are handled. See #2294 which patches other parts of the controller for the same kind of timeout drag. This patch needs to be a little different, due to the complex way the SequenceActions impl uses nested Promises.

PG3 625 🔵

@rabbah rabbah self-assigned this Jun 15, 2017
@rabbah rabbah added controller review Review for this PR has been requested and yet needs to be done. labels Jun 15, 2017
@rabbah rabbah force-pushed the sequence_avoid_keeping_N_in_mem branch 2 times, most recently from 828162f to c061fe0 Compare June 15, 2017 21:37
@rabbah
Copy link
Member

rabbah commented Jun 15, 2017

@tardieu @markusthoemmes @ioana-blue might any of you want to review this?
if you do, may I suggest using split mode or import into your favorite IDE.

@rabbah rabbah force-pushed the sequence_avoid_keeping_N_in_mem branch from c061fe0 to 792d3f2 Compare June 15, 2017 21:40
@rabbah
Copy link
Member

rabbah commented Jun 15, 2017

@starpit as I noted on slack, we should have unit tests for the new/refactored code. It's far more testable now and we can get good coverage. If you don't have bandwidth for this, I will work on that tomorrow.

@rabbah rabbah force-pushed the sequence_avoid_keeping_N_in_mem branch from 792d3f2 to dd99793 Compare June 15, 2017 23:28
starpit and others added 2 commits June 17, 2017 10:11
…gs in heap.

switch to scheduleOnce+weakrefs for timeout handling in SequenceActions
switch SequenceAccounting to store array of ActivationId rather than array of String -- cheaper in memory
use better (non-dragging) impl of withTimeout
use a getAndSet(null) pattern to avoid two copies of responses being alive simultaneously
Remove pre-allocated array and use mutable array buffer.
Terminate the fold when shortcuirting.
Use copy constructor for fail.
Remove promise.
Dusting of tests.
@rabbah rabbah force-pushed the sequence_avoid_keeping_N_in_mem branch 4 times, most recently from 239b6b9 to 62d65d1 Compare June 19, 2017 19:30
@rabbah rabbah force-pushed the sequence_avoid_keeping_N_in_mem branch from 62d65d1 to 8c2175c Compare June 19, 2017 22:05
@rabbah rabbah force-pushed the sequence_avoid_keeping_N_in_mem branch from 8a41fdd to f97f892 Compare June 19, 2017 22:20
.map(currentMax => Some(Math.max(prevMax, currentMax)))
.getOrElse(prevMemoryLimit)
}.getOrElse(newMemoryLimit)
}
Copy link
Contributor

@markusthoemmes markusthoemmes Jun 20, 2017

Choose a reason for hiding this comment

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

Is this the same as:

(prevMemoryLimit ++ newMemoryLimit).reduceOption(Math.max)

?

protected[actions] case class SequenceAccounting(
atomicActionCnt: Int,
previousResponse: AtomicReference[ActivationResponse],
logs: mutable.ArrayBuffer[ActivationId],
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we rely on this being an ArrayBuffer anywhere, or could it aswell be the more general Buffer?

/** The previous activation failed (this is used when there is no activation record or an internal error. */
def fail(failureResponse: ActivationResponse, activationId: Option[ActivationId]) = {
require(!failureResponse.isSuccess)
activationId.foreach(logs += _)
Copy link
Contributor

Choose a reason for hiding this comment

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

logs.appendAll(activationId)?

Copy link
Contributor Author

@starpit starpit left a comment

Choose a reason for hiding this comment

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

LGTM

@rabbah rabbah merged commit 7f399a4 into apache:master Jun 20, 2017
houshengbo pushed a commit to houshengbo/openwhisk that referenced this pull request Jun 23, 2017
- switch to scheduleOnce+weakrefs for timeout handling in SequenceActions
- switch SequenceAccounting to store array of ActivationId rather than array of String -- cheaper in memory
-  use better (non-dragging) impl of withTimeout
- use a getAndSet(null) pattern to avoid two copies of responses being alive simultaneously
- refactor top level sequence scheduler to eliminate promises
houshengbo pushed a commit to houshengbo/openwhisk that referenced this pull request Jun 23, 2017
- switch to scheduleOnce+weakrefs for timeout handling in SequenceActions
- switch SequenceAccounting to store array of ActivationId rather than array of String -- cheaper in memory
-  use better (non-dragging) impl of withTimeout
- use a getAndSet(null) pattern to avoid two copies of responses being alive simultaneously
- refactor top level sequence scheduler to eliminate promises
jonpspri pushed a commit to jonpspri/openwhisk that referenced this pull request Jul 4, 2017
- switch to scheduleOnce+weakrefs for timeout handling in SequenceActions
- switch SequenceAccounting to store array of ActivationId rather than array of String -- cheaper in memory
-  use better (non-dragging) impl of withTimeout
- use a getAndSet(null) pattern to avoid two copies of responses being alive simultaneously
- refactor top level sequence scheduler to eliminate promises
houshengbo pushed a commit to houshengbo/openwhisk that referenced this pull request Jul 17, 2017
- switch to scheduleOnce+weakrefs for timeout handling in SequenceActions
- switch SequenceAccounting to store array of ActivationId rather than array of String -- cheaper in memory
-  use better (non-dragging) impl of withTimeout
- use a getAndSet(null) pattern to avoid two copies of responses being alive simultaneously
- refactor top level sequence scheduler to eliminate promises
houshengbo pushed a commit to houshengbo/openwhisk that referenced this pull request Jul 21, 2017
- switch to scheduleOnce+weakrefs for timeout handling in SequenceActions
- switch SequenceAccounting to store array of ActivationId rather than array of String -- cheaper in memory
-  use better (non-dragging) impl of withTimeout
- use a getAndSet(null) pattern to avoid two copies of responses being alive simultaneously
- refactor top level sequence scheduler to eliminate promises
houshengbo pushed a commit to houshengbo/openwhisk that referenced this pull request Nov 13, 2017
- switch to scheduleOnce+weakrefs for timeout handling in SequenceActions
- switch SequenceAccounting to store array of ActivationId rather than array of String -- cheaper in memory
-  use better (non-dragging) impl of withTimeout
- use a getAndSet(null) pattern to avoid two copies of responses being alive simultaneously
- refactor top level sequence scheduler to eliminate promises
houshengbo pushed a commit to houshengbo/openwhisk that referenced this pull request Nov 13, 2017
- switch to scheduleOnce+weakrefs for timeout handling in SequenceActions
- switch SequenceAccounting to store array of ActivationId rather than array of String -- cheaper in memory
-  use better (non-dragging) impl of withTimeout
- use a getAndSet(null) pattern to avoid two copies of responses being alive simultaneously
- refactor top level sequence scheduler to eliminate promises
houshengbo pushed a commit to houshengbo/openwhisk that referenced this pull request Nov 13, 2017
- switch to scheduleOnce+weakrefs for timeout handling in SequenceActions
- switch SequenceAccounting to store array of ActivationId rather than array of String -- cheaper in memory
-  use better (non-dragging) impl of withTimeout
- use a getAndSet(null) pattern to avoid two copies of responses being alive simultaneously
- refactor top level sequence scheduler to eliminate promises
houshengbo pushed a commit to houshengbo/openwhisk that referenced this pull request Nov 13, 2017
- switch to scheduleOnce+weakrefs for timeout handling in SequenceActions
- switch SequenceAccounting to store array of ActivationId rather than array of String -- cheaper in memory
-  use better (non-dragging) impl of withTimeout
- use a getAndSet(null) pattern to avoid two copies of responses being alive simultaneously
- refactor top level sequence scheduler to eliminate promises
houshengbo pushed a commit to houshengbo/openwhisk that referenced this pull request Nov 14, 2017
- switch to scheduleOnce+weakrefs for timeout handling in SequenceActions
- switch SequenceAccounting to store array of ActivationId rather than array of String -- cheaper in memory
-  use better (non-dragging) impl of withTimeout
- use a getAndSet(null) pattern to avoid two copies of responses being alive simultaneously
- refactor top level sequence scheduler to eliminate promises
houshengbo pushed a commit to houshengbo/openwhisk that referenced this pull request Nov 14, 2017
- switch to scheduleOnce+weakrefs for timeout handling in SequenceActions
- switch SequenceAccounting to store array of ActivationId rather than array of String -- cheaper in memory
-  use better (non-dragging) impl of withTimeout
- use a getAndSet(null) pattern to avoid two copies of responses being alive simultaneously
- refactor top level sequence scheduler to eliminate promises
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
controller review Review for this PR has been requested and yet needs to be done.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

the sequence impl drags memory
3 participants