HADOOP-8071. Avoid an extra packet in client code when nagling is disabled. Contributed by Todd Lipcon.

git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/trunk@1244189 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Todd Lipcon 2012-02-14 19:47:02 +00:00
parent 82ffe0e732
commit f42e58c381
2 changed files with 9 additions and 3 deletions

View File

@ -166,6 +166,8 @@ Release 0.23.2 - UNRELEASED
(szetszwo) (szetszwo)
OPTIMIZATIONS OPTIMIZATIONS
HADOOP-8071. Avoid an extra packet in client code when nagling is
disabled. (todd)
BUG FIXES BUG FIXES

View File

@ -794,14 +794,18 @@ public class Client {
//for serializing the //for serializing the
//data to be written //data to be written
d = new DataOutputBuffer(); d = new DataOutputBuffer();
d.writeInt(0); // placeholder for data length
RpcPayloadHeader header = new RpcPayloadHeader( RpcPayloadHeader header = new RpcPayloadHeader(
call.rpcKind, RpcPayloadOperation.RPC_FINAL_PAYLOAD, call.id); call.rpcKind, RpcPayloadOperation.RPC_FINAL_PAYLOAD, call.id);
header.write(d); header.write(d);
call.rpcRequest.write(d); call.rpcRequest.write(d);
byte[] data = d.getData(); byte[] data = d.getData();
int dataLength = d.getLength(); int dataLength = d.getLength() - 4;
out.writeInt(dataLength); //first put the data length data[0] = (byte)((dataLength >>> 24) & 0xff);
out.write(data, 0, dataLength);//write the data data[1] = (byte)((dataLength >>> 16) & 0xff);
data[2] = (byte)((dataLength >>> 8) & 0xff);
data[3] = (byte)(dataLength & 0xff);
out.write(data, 0, dataLength + 4);//write the data
out.flush(); out.flush();
} }
} catch(IOException e) { } catch(IOException e) {