I have created a very simple .proto file:
syntax = "proto2";
package Metadata; 
option java_package = "metadata";
option java_outer_classname = "Metadata";
option optimize_for=SPEED;
message PutMessage {
 optional string key =1;
 optional int64 dt = 2; 
}
I have a create a simple client-server program that server echoes client message. All messages are PutMessage:
Server:
public class Server {
 public static void main(String args[]) throws IOException, InterruptedException {
 ServerSocket ss = new ServerSocket(8080);
 System.out.println("Listening for client");
 Socket socket = ss.accept();
 System.out.println("Server Results: ");
 while (true) {
 Long parseStart = System.nanoTime();
 PutMessage sm = PutMessage.parseDelimitedFrom(socket.getInputStream());
 Long parseEnd = System.nanoTime();
 Long writeStart = System.nanoTime();
 sm.writeDelimitedTo(socket.getOutputStream());
 Long writeEnd = System.nanoTime();
 System.out.println("Parse time: " + (parseEnd - parseStart));
 System.out.println("Write time: " + (writeEnd - writeStart));
 }
 }
}
Client:
public class Client {
 public static void main (String args[]) throws IOException, InterruptedException{
 Socket socket = new Socket("127.0.0.1", 8080);
 int A = new Integer(args[0]);
 PutMessage cm = PutMessage.newBuilder().setDt(3434).setKey("sdfwsdf").build();
 System.out.println("Client Results7: ");
 for (int i=0;i < A; i++){
 Long writeStart = System.nanoTime();
 cm.writeDelimitedTo(socket.getOutputStream());
 Long writeEnd = System.nanoTime();
 Long parseStart = System.nanoTime();
 cm.parseDelimitedFrom(socket.getInputStream());
 Long parseEnd = System.nanoTime();
 System.out.println("Write time: " + (writeEnd - writeStart));
 System.out.println("Parse time: " + (parseEnd - parseStart));
 }
 }
}
When I run client and server on Windows it is very fast. But when I run on Ubuntu, it takes a long time (70(ms)) for the server to parse the client message: These are some results when I pass 3 to the client:
All in nanoseconds
Windows:
Client Results: 
Write time: 54401508
Parse time: 95818962
Write time: 279563
Parse time: 201593
Write time: 200568
Parse time: 138500
Server Results: 
Parse time: 207099065
Write time: 42572640
Parse time: 20808241
Write time: 156966
Parse time: 209801
Write time: 124649
Ubuntu:
Client Results:
Write time: 31205019
Parse time: 86399222
Write time: 101132
Parse time: 40619478
Write time: 214496
Parse time: 79164985
Server Results:
Parse time: 183947743
Write time: 25819286
Parse time: 28680184
Write time: 292955
Parse time: 79299932
Write time: 298012
I found that, if I remove setDt from put message and when it is only setKey, it is fast on Ubuntu too. But I need to have dt. I have no clue, why it is fast on Windows and slow on Ubuntu. I thought maybe my machine is different, but without setDt it is fast on Ubuntu, so the problem is not the Hardware.
I have also tried proto3, same results. Any help is greatly appreciated.
Update: Both OSs are 64-bit. Java versions are:
Ubuntu:
java version "1.8.0_66" 
Java(TM) SE Runtime Environment (build 1.8.0_66-b17) 
Java HotSpot(TM) 64-Bit Server VM (build 25.66-b17, mixed mode) 
Windows:
java version "1.8.0_151" 
Java(TM) SE Runtime Environment (build 1.8.0_151-b12) 
Java HotSpot(TM) 64-Bit Server VM (build 25.151-b12, mixed mode)
Thanks
Update: I redid the experiment on two AWS EC2 instances. One Windows and the other Amazon Linux. I didn't use Ubuntu this time, but I got same results. Again I got much faster results on Windows. It is really weird!
 
    