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

Use atomic counter for message seqnos #53

Merged
merged 1 commit into from
Jan 3, 2018
Merged

Use atomic counter for message seqnos #53

merged 1 commit into from
Jan 3, 2018

Conversation

vyzo
Copy link
Collaborator

@vyzo vyzo commented Jan 3, 2018

Closes #52

The seqno is now the concatenation of the timestamp and an atomic counter; it's 128-bit wide.

@ghost ghost assigned vyzo Jan 3, 2018
@ghost ghost added the in progress label Jan 3, 2018
@vyzo vyzo requested a review from Stebalien January 3, 2018 09:29
@vyzo
Copy link
Collaborator Author

vyzo commented Jan 3, 2018

so I don't know what's the deal with the jenkins tests: it says "passed but marked as unstable".
What is this supposed to mean?

@vyzo vyzo requested a review from whyrusleeping January 3, 2018 17:08
Copy link
Member

@Stebalien Stebalien left a comment

Choose a reason for hiding this comment

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

LGTM

@vyzo vyzo merged commit 979ae33 into master Jan 3, 2018
@ghost ghost removed the in progress label Jan 3, 2018
@vyzo vyzo deleted the fix/atomic-counter branch January 3, 2018 17:54
binary.BigEndian.PutUint64(seqno, uint64(time.Now().UnixNano()))
seqno := make([]byte, 16)
counter := atomic.AddUint64(&p.counter, 1)
binary.BigEndian.PutUint64(seqno[:8], uint64(time.Now().UnixNano()))
Copy link
Contributor

Choose a reason for hiding this comment

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

If we initially set counter to time.Now().UnixNano(), then we don't need to get the current time every time we send a message.

Not a big deal, but might save us some syscalls

Copy link
Contributor

Choose a reason for hiding this comment

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

It also saves us from having to send a whole extra 8 bytes per message

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

good points, nice small efficiencies. i'll open a new PR.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

actually, there is no syscall involved in getting the time; but still.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

opened follow-up PR.

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.

3 participants