-
Notifications
You must be signed in to change notification settings - Fork 4k
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
Conversation
Going to leave this here for a day or two for visibility and review. |
lib/java/src/org/apache/thrift/transport/TFastFramedTransport.java
Outdated
Show resolved
Hide resolved
lib/java/src/org/apache/thrift/transport/TFastFramedTransport.java
Outdated
Show resolved
Hide resolved
lib/java/src/org/apache/thrift/transport/TFastFramedTransport.java
Outdated
Show resolved
Hide resolved
@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) { |
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.
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()
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.
Nice workaround to avoiding the conditional check. One comment about adding an IAE
@allengeorge IAE added with tests. |
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.