-
Notifications
You must be signed in to change notification settings - Fork 190
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
Conversation
so I don't know what's the deal with the jenkins tests: it says "passed but marked as unstable". |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
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())) |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
opened follow-up PR.
Closes #52
The seqno is now the concatenation of the timestamp and an atomic counter; it's 128-bit wide.