From f42e58c381a1a8d4feb9384de3b8d8c857830d33 Mon Sep 17 00:00:00 2001 From: Todd Lipcon Date: Tue, 14 Feb 2012 19:47:02 +0000 Subject: [PATCH] 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 --- hadoop-common-project/hadoop-common/CHANGES.txt | 2 ++ .../src/main/java/org/apache/hadoop/ipc/Client.java | 10 +++++++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/hadoop-common-project/hadoop-common/CHANGES.txt b/hadoop-common-project/hadoop-common/CHANGES.txt index c60171a4bd7..63f43189c8c 100644 --- a/hadoop-common-project/hadoop-common/CHANGES.txt +++ b/hadoop-common-project/hadoop-common/CHANGES.txt @@ -166,6 +166,8 @@ Release 0.23.2 - UNRELEASED (szetszwo) OPTIMIZATIONS + HADOOP-8071. Avoid an extra packet in client code when nagling is + disabled. (todd) BUG FIXES diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ipc/Client.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ipc/Client.java index eb8e704f5f5..929b1e328cf 100644 --- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ipc/Client.java +++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ipc/Client.java @@ -794,14 +794,18 @@ public class Client { //for serializing the //data to be written d = new DataOutputBuffer(); + d.writeInt(0); // placeholder for data length RpcPayloadHeader header = new RpcPayloadHeader( call.rpcKind, RpcPayloadOperation.RPC_FINAL_PAYLOAD, call.id); header.write(d); call.rpcRequest.write(d); byte[] data = d.getData(); - int dataLength = d.getLength(); - out.writeInt(dataLength); //first put the data length - out.write(data, 0, dataLength);//write the data + int dataLength = d.getLength() - 4; + data[0] = (byte)((dataLength >>> 24) & 0xff); + 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(); } } catch(IOException e) {