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

Migrating Agents to greener pastures #1051

Merged
merged 5 commits into from
Jan 28, 2013
Merged

Conversation

viktorklang
Copy link
Member

A re-envisioning of Agents

  • no longer have to be .close()'d
  • removed redundant methods
  • cleaned up method parameters
  • new impl 68 lines smaller :)

@@ -116,7 +108,7 @@ class Agent[T](initialValue: T, refFactory: ActorRefFactory, system: ActorSystem
* Dispatch a function to update the internal state.
*/
def send(f: T ⇒ T): Unit = {
def dispatch = updater ! Update(f)
def dispatch = updater.execute(new Runnable { def run = ref.single.transformAndGet(f) })
Copy link
Contributor

Choose a reason for hiding this comment

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

We don't use the return value, so could use transform instead of transformAndGet.

@viktorklang
Copy link
Member Author

Regarding remState + attach that's a remnant from when remState didn't call attach, good call. Attach is a conditional construct required for guaranteeing invariants, so it should most definitely be in remState. remState is also private, so it is under control. Thanks for reviewing Rich! I'll add tests to both the EC impl and the java API of Agent :-)

Docs for Agents also needs rewriting

@viktorklang
Copy link
Member Author

Rewrote Agent docs and added some more tests, will commence writing some tests for the new ExecutionContext.

@viktorklang
Copy link
Member Author

Added tests for the new EC


private final val state = new AtomicInteger(0)
@tailrec private final def addState(newState: Int): Boolean = {
val c = state.get;
Copy link
Contributor

Choose a reason for hiding this comment

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

Come on √ - a semicolon? For real?

Copy link
Member Author

Choose a reason for hiding this comment

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

Lol – I confess, I experimented having it as a one-liner. Residue must go!

@viktorklang
Copy link
Member Author

Addressed Rich's nice catches :-)

sec.isEmpty must be === true
}

"execute 'throughput' number of tasks per sweep" in {
Copy link
Contributor

Choose a reason for hiding this comment

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

how does suspend interact with throughtput?

Copy link
Contributor

Choose a reason for hiding this comment

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

I see below that is supposed to interrupt batches, but a test would be nice

Copy link
Member Author

Choose a reason for hiding this comment

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

The test below makes sure that the EC is loaded with all the tasks before starting to process, so that it will resubmit after "throughput" number of tasks processed. suspension aborts the current batch, otherwise it wouldn't suspend?

@rkuhn
Copy link
Contributor

rkuhn commented Jan 24, 2013

Yes, I like it now! (and you know what that means ;-) )

@viktorklang
Copy link
Member Author

Added suspension test :-)

@rkuhn
Copy link
Contributor

rkuhn commented Jan 24, 2013

ah, I can’t take it, the SUSPENSE

now it only need migration docs

@viktorklang
Copy link
Member Author

As soon as everyone has OK:ed this change in Agents, I'll add migration docs :-)

@akka-ci
Copy link

akka-ci commented Jan 25, 2013

Started jenkins job akka-pr-validator at https://jenkins.akka.io/job/akka-pr-validator/347/

@akka-ci
Copy link

akka-ci commented Jan 25, 2013

jenkins job akka-pr-validator: Success - https://jenkins.akka.io/job/akka-pr-validator/347/

sec.suspend()
def perform(f: Int ⇒ Int) = sec execute new Runnable { def run = counter.set(f(counter.get)) }
perform(_ + 1)
1 to 10 foreach { _ ⇒ perform(identity) }
Copy link
Member

Choose a reason for hiding this comment

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

What does this line? Why?

Copy link
Member Author

Choose a reason for hiding this comment

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

It adds 10 tasks to do nothing. We do this to simulate that other stuff gets added in between.

@patriknw
Copy link
Member

+1

@bantonsson
Copy link
Member

LGTM. Really like the SerializedSuspendableExecutionContext.

@bantonsson
Copy link
Member

Oh, I almost forgot. The doc doesn't build. KITTEH PLS COME BACK.

@viktorklang
Copy link
Member Author

Thanks Björn! Currently fixing the docs

@rkuhn
Copy link
Contributor

rkuhn commented Jan 28, 2013

LGTM: merge after KITTEH has approved

@akka-ci
Copy link

akka-ci commented Jan 28, 2013

Started jenkins job akka-pr-validator at https://jenkins.akka.io/job/akka-pr-validator/347/

@akka-ci
Copy link

akka-ci commented Jan 28, 2013

jenkins job akka-pr-validator: Success - https://jenkins.akka.io/job/akka-pr-validator/347/

viktorklang added a commit that referenced this pull request Jan 28, 2013
 Migrating Agents to greener pastures
@viktorklang viktorklang merged commit d6addd9 into master Jan 28, 2013
@viktorklang viktorklang deleted the wip-agent-rework-√ branch January 28, 2013 15:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants