Thanks Carl,

Is there any example for the same ?

Thanks
Avinash


On Monday, September 12, 2016 at 11:47:06 PM UTC+5:30, Carl Mastrangelo 
wrote:
>
> You need to provide your on Executor in NettyServerBuilder.  The default 
> is a cached threadpool which spawns threads too quickly under load.
>
> Also, you are using the blocking client API, which won't be as fast as the 
> Async API.  You should only create one channel, and reuse it.  Also, the 
> Channel needs its own threadpool too.
>
> On Monday, September 12, 2016 at 6:59:58 AM UTC-7, Avinash Dongre wrote:
>>
>> Hello All,
>>
>> I am trying to see if I can use this framework in my project. I need to 
>> know what should be my GRPC Server configuration to achieve low latency and 
>> high throughput.
>>
>> This is how I am starting a GRPC which is embedded in another Java 
>> Process.
>>
>> I am not doing anything on the server side, and when I call this method 
>> for 1000000 times. I am getting 
>>
>> *Took 167 Seconds 167085714844 NanoSeconds*
>>
>> This is certainly high, but I am sure I am doing something wrong in 
>> configuring gRPC Server, Please help.
>>
>> private void startGRPCService(GemFireCacheImpl cache) {
>>
>>   int port = system.getConfig().getRpcPort();
>>
>>   if ( this.isServerNode()  && port != 0) {
>>     try {
>>       gRPCServer = NettyServerBuilder.forPort(port)
>>           .addService(new MTableServiceImpl())
>>           .channelType(NioServerSocketChannel.class)
>>           .build()
>>           .start();
>>     } catch (IOException e) {
>>       e.printStackTrace();
>>     }
>>     logger.info("GRPC Server started, listening on " + port);
>>
>>     Runtime.getRuntime().addShutdownHook(new Thread() {
>>       @Override
>>       public void run() {
>>         // Use stderr here since the logger may have been reset by its JVM 
>> shutdown hook.
>>         System.err.println("*** shutting down gRPC server since JVM is 
>> shutting down");
>>         this.stopGRPCServer();
>>         System.err.println("*** server shut down");
>>       }
>>     });
>>   }
>> }
>>
>>
>> Service is implemented as follows, It does nothing but just returns a a 
>> status.
>>
>> public class MyServiceImpl extends MyServiceGrpc.MyServiceImplBase {
>>
>>   private static final Logger logger = LogService.getLogger();
>>
>>   @Override
>>   public void tablePut(PutMessage request, StreamObserver<PutMessageReply> 
>> responseObserver) {
>>     PutMessageReply reply = 
>> PutMessageReply.newBuilder().setStatus(PutMessageReply.OpStatus.SUCCESS).build();
>>     responseObserver.onNext(reply);
>>     responseObserver.onCompleted();
>>   }
>>
>>
>>
>> Client is implemented as follows
>>
>> public class TableServiceClient {
>>   private static final Logger logger = LogService.getLogger();
>>   public static TableServiceClient INSTANCE = new TableServiceClient();
>>   private Map<ServerLocation, TableServiceGrpc.TableServiceBlockingStub> 
>> grpcConnectionMap = new HashMap<>();
>>   private Random r = new Random();
>>   private List<TableServiceGrpc.TableServiceBlockingStub> valuesList;
>>   private int numberOfServers = 0;
>>   private PutMessage.Builder putMessageBuilder = MPutMessage.newBuilder();
>>
>>
>>   public TableServiceClient() {
>>     this.valuesList = new ArrayList<>(grpcConnectionMap.values());
>>     this.numberOfServers = valuesList.size();
>>   }
>>
>>   private TableServiceGrpc.TableServiceBlockingStub getApplicableChannel() {
>>     return this.valuesList.get(r.nextInt(this.numberOfServers));
>>   }
>>
>>   public void put(final String tableName, MPut put, List<Integer> 
>> columnPositions, byte[] value,)
>>  {
>>     TableServiceGrpc.TableServiceBlockingStub channel = 
>> getApplicableChannel();
>>
>>
>>         this.putMessageBuilder.setKey(ByteString.copyFrom(put.getRowKey()))
>>         .setValue(ByteString.copyFrom(value))
>>         .setTableName(tableName);
>>
>>     for (Integer position : columnPositions) {
>>       this.putMessageBuilder.addColumnPositions(position);
>>     }
>>
>>     MPutMessage putMessage = this.putMessageBuilder.build();
>>     MPutMessageReply response;
>>
>>     try {
>>       response = channel.tablePut(putMessage);
>>     } catch (StatusRuntimeException e) {
>>       logger.warn("RPC failed: {0}", e.getStatus());
>>       return;
>>     }
>>     this.putMessageBuilder.clear();
>>     PutMessageReply.OpStatus status = response.getStatus();
>>   }
>> }
>>
>>
>>
>> Thanks
>> Avinash
>>
>>

-- 
You received this message because you are subscribed to the Google Groups 
"grpc.io" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to grpc-io+unsubscr...@googlegroups.com.
To post to this group, send email to grpc-io@googlegroups.com.
Visit this group at https://groups.google.com/group/grpc-io.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/grpc-io/0488bbd3-2205-4caa-baef-7f33a6605fa6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to