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

THRIFT-4714: optimize java TFramedTransports to call write only once per flush #1671

Merged
merged 1 commit into from
Jan 4, 2019

Conversation

jeking3
Copy link
Contributor

@jeking3 jeking3 commented Jan 3, 2019

Code calls two writes to the underlying transport per flush: one for the frame size and one for the payload. The result is that folks use TBufferedTransport on top of TFramedTransport to avoid getting two ethernet frames for small packets. This means everything is double-buffered!

Based on THRIFT-1121 and THRIFT-959 this may have been an issue for a long time - the fix was easy however. We make room for the frame size before writing to the buffer, then we only have to pull out the buffer, drop the frame size into the 4 bytes that we pre-allocated, and then write to the underlying transport once.

@jeking3
Copy link
Contributor Author

jeking3 commented Jan 3, 2019

Going to leave this here for a day or two for visibility and review.

@jeking3
Copy link
Contributor Author

jeking3 commented Jan 3, 2019

@allengeorge check this out again, I changed it.

* This allows framed transport to reserve space
* for the frame buffer length.
*/
public AutoExpandingBufferWriteTransport(int initialCapacity, int frontReserve) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Probably ensure that initialCapacity >= frontReserve? Throw an IllegalArgumentException if it doesn't?

Other than that, I like the fact that there's no conditional check on each write()

Copy link
Contributor

@allengeorge allengeorge left a comment

Choose a reason for hiding this comment

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

Nice workaround to avoiding the conditional check. One comment about adding an IAE

@jeking3
Copy link
Contributor Author

jeking3 commented Jan 3, 2019

@allengeorge IAE added with tests.

@jeking3 jeking3 merged commit 6503043 into apache:master Jan 4, 2019
@jeking3 jeking3 deleted the THRIFT-4714 branch January 4, 2019 03:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants