Hi,
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:
*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.
Thanks
--
You received this message because you are subscribed to the Google Groups
"Protocol Buffers" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/protobuf.
For more options, visit https://groups.google.com/d/optout.