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

Fix alignment in blockWriteStream. #82

Closed
wants to merge 1 commit into from

Conversation

adamfaulkner
Copy link
Contributor

There was a bug that caused packet size to always equal chunkSize (512 bytes). I discovered this when debugging performance with perf trace.

Fixed this by taking alignment = (chunkSize - (offset % chunkSize)) % chunkSize, which will be 0 when the offset is aligned.

Added a simple test to verify this.

@adamfaulkner
Copy link
Contributor Author

adamfaulkner commented Aug 9, 2017

BTW I needed this in order for performance to be adequate. Uploading a 8GB file was taking > 1hr. After this change it took 90 seconds.

@adamfaulkner
Copy link
Contributor Author

I added an issue #84


packet := bws.makePacket()
// if we are totally aligned, then the packet should be outboundPacketSize.
if len(packet.data) != outboundPacketSize {
Copy link
Owner

Choose a reason for hiding this comment

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

Can you use assert.NotEqual here (and assert.Equal below)?

func TestPacketAlignment(t *testing.T) {
// Verify that alignment is correctly handled in blockWriteStream.
bws := &blockWriteStream{}
// Write some data so we can test making packets.
Copy link
Owner

Choose a reason for hiding this comment

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

You can get rid of these two comments, they're just noisy.

@@ -173,7 +173,7 @@ func (s *blockWriteStream) makePacket() outboundPacket {
// gets unhappy unless we first align to a chunk boundary with a small packet.
// Otherwise it yells at us with "a partial chunk must be sent in an
// individual packet" or just complains about a corrupted block.
alignment := outboundChunkSize - (int(s.offset) % outboundChunkSize)
alignment := (outboundChunkSize - (int(s.offset) % outboundChunkSize)) % outboundChunkSize
Copy link
Owner

@colinmarc colinmarc Aug 16, 2017

Choose a reason for hiding this comment

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

I think I see the problem now, ugh. An extra % just makes this line more confusing, though. I think something like this would scan better:

alignment := int(s.offset) % outboundChunkSize
if alignment != 0 && packetLength > outboundChunkSize {
    packetLength = outboundChunkSize - alignment
}

What do you think?

@colinmarc
Copy link
Owner

Gah, thanks for catching this. Super terrible. I've got some nitpicks on the fix and the test changes, then I'll merge.

@colinmarc
Copy link
Owner

I merged your fix in cdda132. Thanks again!

@colinmarc colinmarc closed this Aug 22, 2017
@adamfaulkner
Copy link
Contributor Author

Ah sorry for not addressing those nitpicks, I've been super busy! Thanks for merging my fix.

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

2 participants