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

Optimize Single Message Processing in Mailbox #90

Merged
merged 4 commits into from
Feb 14, 2017

Conversation

daumayr
Copy link
Contributor

@daumayr daumayr commented Jan 16, 2017

Replaces the current Mailbox implementation with a approach similar to how SPromise handles chained Promises. This brings a performance improvement due to currently low mailbox utilization (many contain only one message).

@daumayr daumayr force-pushed the mailbox-alternative branch 9 times, most recently from c9eaa0e to 988efea Compare January 23, 2017 12:00
Copy link
Owner

@smarr smarr left a comment

Choose a reason for hiding this comment

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

A few change requests, mostly about naming.
But, I'd also like to know why you prefer ArrayList over Mailbox.

@@ -57,7 +59,11 @@ public static Actor createActor() {
private static final int THREAD_ID_SHIFT = 56;

/** Buffer for incoming messages. */
private Mailbox mailbox = Mailbox.createNewMailbox(16);
private EventualMessage message;
Copy link
Owner

Choose a reason for hiding this comment

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

Hm, perhaps this would be better firstMessage, to make the semantics clear.

And, I think the comment could be extended to say that we optimize the case that there is one message, and only put everything afterwards into the moreMessages data structure.

@@ -57,7 +59,11 @@ public static Actor createActor() {
private static final int THREAD_ID_SHIFT = 56;

/** Buffer for incoming messages. */
private Mailbox mailbox = Mailbox.createNewMailbox(16);
private EventualMessage message;
private List<EventualMessage> moreMessages;
Copy link
Owner

Choose a reason for hiding this comment

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

Why do you use an ArrayList here, instead of a Mailbox, any specific reason?
Mailbox was implemented to avoid copying the array of ArrayList when the mailbox becomes to small.

Perhaps a better name would be mailboxExtension. The code below doesn't read well at the moment, from the perspective of terminology/word choice.

private EventualMessage message;
private List<EventualMessage> moreMessages;

private long sendTimeStamp;
Copy link
Owner

Choose a reason for hiding this comment

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

better firstMessageTimeStamp

private List<EventualMessage> moreMessages;

private long sendTimeStamp;
private List<Long> moreSendTimeStamps;
Copy link
Owner

Choose a reason for hiding this comment

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

Better mailboxExtensionTimeStamps

sendTimeStamp = System.currentTimeMillis();
}
} else {
sendMoreMessages(msg);
Copy link
Owner

Choose a reason for hiding this comment

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

better appendToMailbox(msg)

/**
* Is scheduled on the fork/join pool and executes messages for a specific
* actor.
*/
private static final class ExecAllMessages implements Runnable {
private final Actor actor;
private Mailbox current;
private EventualMessage current;
Copy link
Owner

Choose a reason for hiding this comment

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

better firstMessage

/**
* Is scheduled on the fork/join pool and executes messages for a specific
* actor.
*/
private static final class ExecAllMessages implements Runnable {
private final Actor actor;
private Mailbox current;
private EventualMessage current;
private List<EventualMessage> moreCurrent;
Copy link
Owner

Choose a reason for hiding this comment

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

better mailboxExtension

private EventualMessage current;
private List<EventualMessage> moreCurrent;
private long baseMessageId;
private long sendTimeStamp;
Copy link
Owner

Choose a reason for hiding this comment

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

and for the time stamps, same wording as above, please

int i = 0;
if (size > 1) {
for (EventualMessage msg : moreCurrent) {
actor.logMessageBeingExecuted(msg);
Copy link
Owner

Choose a reason for hiding this comment

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

this block looks identical to the handling of the first message. could this be a helper method?

@daumayr daumayr force-pushed the mailbox-alternative branch 3 times, most recently from 2963bba to 4191ede Compare January 30, 2017 09:13
@smarr smarr changed the title Mailbox alternative Optimize Mailbox for single message Feb 14, 2017
@smarr smarr changed the title Optimize Mailbox for single message Optimize Single Message Processing in Mailbox Feb 14, 2017
now uses SPromise like queuing
Fixed Validition.Philosophers resolving promise twice.
Fixed RejectedExecutionException when sending messages while shutting down, throw ThreadDeath instead.
Signed-off-by: Stefan Marr <git@stefan-marr.de>
@smarr smarr merged commit 85b10fa into smarr:master Feb 14, 2017
@smarr smarr deleted the mailbox-alternative branch February 14, 2017 15:10
@smarr smarr added this to the v0.2.0 milestone Mar 6, 2017
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.

2 participants