Advertisement
udit7294

Untitled

Sep 30th, 2016
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.36 KB | None | 0 0
  1. //GRPC
  2.  
  3. public RouteGuideClient(ManagedChannelBuilder<?> channelBuilder) {
  4.     channel = channelBuilder.build();
  5.     blockingStub = RouteGuideGrpc.newBlockingStub(channel);
  6.     asyncStub = RouteGuideGrpc.newStub(channel);
  7.   }
  8.  
  9. RouteGuideClient client = new RouteGuideClient("localhost", 8980);
  10. try {
  11.   final long startTime = System.nanoTime();
  12.  
  13.   for (int i = 0; i < 10000; i++)
  14.     client.getFeature(409146138, -746188906);
  15.  
  16.   final long endTime = System.nanoTime();
  17.   info("method 1 : " + (endTime - startTime));
  18. }
  19. public void getFeature(int lat, int lon) {
  20.   try {
  21.     Point request = Point.newBuilder().setLatitude(lat).setLongitude(lon).build();
  22.     Feature feature = blockingStub.getFeature(request);
  23.   } catch (RuntimeException e) {
  24.     logger.log(Level.WARNING, "RPC failed", e);
  25.     throw e;
  26.   }
  27. }
  28.  
  29.  
  30.  
  31.  
  32. //Thrift
  33.  
  34. int diff;
  35. Transport transport = new TSocket("localhost", 9090);
  36. transport.open();
  37.  
  38. TProtocol protocol = new TBinaryProtocol(transport);
  39. MultiplicationService.Client client = new MultiplicationService.Client(protocol);
  40. final long startTime = System.nanoTime();
  41. try {
  42.   for (int i = 0; i < 10000; i++)
  43.      diff = client.calculate(i, i);
  44. } catch (InvalidOperation io) {
  45.   System.out.println("Invalid operation: " + io.why);
  46. }
  47. final long endTime = System.nanoTime();
  48. System.out.println("method 1 : " + (endTime - startTime));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement