@@ -504,20 +504,34 @@ public void heartbeat(CommonProviderRequest req) throws PolarisException {
504504 ServiceKey serviceKey = new ServiceKey (req .getNamespace (), req .getService ());
505505 long startTimestamp = 0L ;
506506 try {
507+ long t1 = System .currentTimeMillis ();
507508 waitDiscoverReady ();
509+ long t2 = System .currentTimeMillis ();
508510 connection = connectionManager
509511 .getConnection (GrpcUtil .OP_KEY_INSTANCE_HEARTBEAT , ClusterType .HEALTH_CHECK_CLUSTER );
512+ long t3 = System .currentTimeMillis ();
510513 req .setTargetServer (connectionToTargetNode (connection ));
514+ long t4 = System .currentTimeMillis ();
511515 PolarisGRPCGrpc .PolarisGRPCBlockingStub stub = PolarisGRPCGrpc .newBlockingStub (connection .getChannel ());
516+ long t5 = System .currentTimeMillis ();
512517 stub = GrpcUtil .attachRequestHeader (stub , GrpcUtil .nextHeartbeatReqId ());
518+ long t6 = System .currentTimeMillis ();
513519 stub = GrpcUtil .attachAccessToken (connectorConfig .getToken (), stub );
514520 startTimestamp = System .currentTimeMillis ();
521+ if (startTimestamp - t1 > 1000 ) {
522+ LOG .warn ("waitDiscoverReady cost {} ms, getConnection cost {} ms, connectionToTargetNode cost {} ms, newBlockingStub cost {} ms, attachRequestHeader cost {} ms, attachAccessToken cost {} ms" ,
523+ t2 - t1 , t3 - t2 , t4 - t3 , t5 - t4 , t6 - t5 , startTimestamp - t6 );
524+ } else if (LOG .isDebugEnabled ()) {
525+ LOG .debug ("waitDiscoverReady cost {} ms, getConnection cost {} ms, connectionToTargetNode cost {} ms, newBlockingStub cost {} ms, attachRequestHeader cost {} ms, attachAccessToken cost {} ms" ,
526+ t2 - t1 , t3 - t2 , t4 - t3 , t5 - t4 , t6 - t5 , startTimestamp - t6 );
527+ }
515528 LOG .debug ("start heartbeat at {} ms." , startTimestamp );
516529 ResponseProto .Response heartbeatResponse = stub .withDeadlineAfter (req .getTimeoutMs (),
517530 TimeUnit .MILLISECONDS ).heartbeat (buildHeartbeatRequest (req ));
518531 GrpcUtil .checkResponse (heartbeatResponse );
519532 LOG .debug ("received heartbeat response {}" , heartbeatResponse );
520533 } catch (Throwable t ) {
534+ LOG .warn ("heartbeat fail, req: {}, msg: {}" , req , t .getMessage ());
521535 if (t instanceof PolarisException ) {
522536 //服务端异常不进行重试
523537 throw t ;
@@ -531,7 +545,12 @@ public void heartbeat(CommonProviderRequest req) throws PolarisException {
531545 req .getInstanceID (), req .getHost (), req .getPort (), serviceKey ), t );
532546 } finally {
533547 long endTimestamp = System .currentTimeMillis ();
534- LOG .debug ("end heartbeat at {} ms. Diff {} ms" , endTimestamp , endTimestamp - startTimestamp );
548+ long cost = endTimestamp - startTimestamp ;
549+ if (cost > 1000 ) {
550+ LOG .warn ("end heartbeat at {} ms. Diff {} ms" , endTimestamp , cost );
551+ } else if (LOG .isDebugEnabled ()) {
552+ LOG .debug ("end heartbeat at {} ms. Diff {} ms" , endTimestamp , cost );
553+ }
535554 if (null != connection ) {
536555 connection .release (GrpcUtil .OP_KEY_INSTANCE_HEARTBEAT );
537556 }
0 commit comments