Java Code Examples for io.perfmark.PerfMark#event()

The following examples show how to use io.perfmark.PerfMark#event() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: OkHttpClientTransport.java    From grpc-java with Apache License 2.0 6 votes vote down vote up
@Override
public void rstStream(int streamId, ErrorCode errorCode) {
  logger.logRstStream(OkHttpFrameLogger.Direction.INBOUND, streamId, errorCode);
  Status status = toGrpcStatus(errorCode).augmentDescription("Rst Stream");
  boolean stopDelivery =
      (status.getCode() == Code.CANCELLED || status.getCode() == Code.DEADLINE_EXCEEDED);
  synchronized (lock) {
    OkHttpClientStream stream = streams.get(streamId);
    if (stream != null) {
      PerfMark.event("OkHttpClientTransport$ClientFrameHandler.rstStream",
          stream.transportState().tag());
      finishStream(
          streamId, status,
          errorCode == ErrorCode.REFUSED_STREAM ? RpcProgress.REFUSED : RpcProgress.PROCESSED,
          stopDelivery, null, null);
    }
  }
}
 
Example 2
Source File: NettyClientHandler.java    From grpc-java with Apache License 2.0 6 votes vote down vote up
/**
 * Handler for an inbound HTTP/2 RST_STREAM frame, terminating a stream.
 */
private void onRstStreamRead(int streamId, long errorCode) {
  NettyClientStream.TransportState stream = clientStream(connection().stream(streamId));
  if (stream != null) {
    PerfMark.event("NettyClientHandler.onRstStreamRead", stream.tag());
    Status status = GrpcUtil.Http2Error.statusForCode((int) errorCode)
        .augmentDescription("Received Rst Stream");
    stream.transportReportStatus(
        status,
        errorCode == Http2Error.REFUSED_STREAM.code()
            ? RpcProgress.REFUSED : RpcProgress.PROCESSED,
        false /*stop delivery*/,
        new Metadata());
    if (keepAliveManager != null) {
      keepAliveManager.onDataReceived();
    }
  }
}
 
Example 3
Source File: MigratingThreadDeframer.java    From grpc-java with Apache License 2.0 6 votes vote down vote up
private void requestFromTransportThread(final int numMessages) {
  class RequestAgainOp implements Op {
    @Override public void run(boolean isDeframerOnTransportThread) {
      if (!isDeframerOnTransportThread) {
        // State changed. Go back and try again
        request(numMessages);
        return;
      }
      try {
        deframer.request(numMessages);
      } catch (Throwable t) {
        appListener.deframeFailed(t);
        deframer.close(); // unrecoverable state
      }
      if (!deframer.hasPendingDeliveries()) {
        synchronized (lock) {
          PerfMark.event("MigratingThreadDeframer.deframerOnApplicationThread");
          migratingListener.setDelegate(appListener);
          deframerOnTransportThread = false;
        }
      }
    }
  }

  runWhereAppropriate(new RequestAgainOp());
}
 
Example 4
Source File: MigratingThreadDeframer.java    From grpc-java with Apache License 2.0 6 votes vote down vote up
@Override
public InputStream next() {
  while (true) {
    InputStream is = appListener.messageReadQueuePoll();
    if (is != null) {
      return is;
    }
    Op op;
    synchronized (lock) {
      op = opQueue.poll();
      if (op == null) {
        if (deframer.hasPendingDeliveries()) {
          PerfMark.event("MigratingThreadDeframer.deframerOnTransportThread");
          migratingListener.setDelegate(transportListener);
          deframerOnTransportThread = true;
        }
        messageProducerEnqueued = false;
        return null;
      }
    }
    op.run(/*isDeframerOnTransportThread=*/false);
  }
}
 
Example 5
Source File: NettyClientHandler.java    From grpc-java with Apache License 2.0 5 votes vote down vote up
private void onHeadersRead(int streamId, Http2Headers headers, boolean endStream) {
  // Stream 1 is reserved for the Upgrade response, so we should ignore its headers here:
  if (streamId != Http2CodecUtil.HTTP_UPGRADE_STREAM_ID) {
    NettyClientStream.TransportState stream = clientStream(requireHttp2Stream(streamId));
    PerfMark.event("NettyClientHandler.onHeadersRead", stream.tag());
    stream.transportHeadersReceived(headers, endStream);
  }

  if (keepAliveManager != null) {
    keepAliveManager.onDataReceived();
  }
}
 
Example 6
Source File: NettyClientHandler.java    From grpc-java with Apache License 2.0 5 votes vote down vote up
/**
 * Handler for an inbound HTTP/2 DATA frame.
 */
private void onDataRead(int streamId, ByteBuf data, int padding, boolean endOfStream) {
  flowControlPing().onDataRead(data.readableBytes(), padding);
  NettyClientStream.TransportState stream = clientStream(requireHttp2Stream(streamId));
  PerfMark.event("NettyClientHandler.onDataRead", stream.tag());
  stream.transportDataReceived(data, endOfStream);
  if (keepAliveManager != null) {
    keepAliveManager.onDataReceived();
  }
}
 
Example 7
Source File: ClientCallImpl.java    From grpc-java with Apache License 2.0 5 votes vote down vote up
ClientCallImpl(
    MethodDescriptor<ReqT, RespT> method, Executor executor, CallOptions callOptions,
    ClientTransportProvider clientTransportProvider,
    ScheduledExecutorService deadlineCancellationExecutor,
    CallTracer channelCallsTracer,
    boolean retryEnabled) {
  this.method = method;
  // TODO(carl-mastrangelo): consider moving this construction to ManagedChannelImpl.
  this.tag = PerfMark.createTag(method.getFullMethodName(), System.identityHashCode(this));
  // If we know that the executor is a direct executor, we don't need to wrap it with a
  // SerializingExecutor. This is purely for performance reasons.
  // See https://github.com/grpc/grpc-java/issues/368
  if (executor == directExecutor()) {
    this.callExecutor = new SerializeReentrantCallsDirectExecutor();
    callExecutorIsDirect = true;
  } else {
    this.callExecutor = new SerializingExecutor(executor);
    callExecutorIsDirect = false;
  }
  this.channelCallsTracer = channelCallsTracer;
  // Propagate the context from the thread which initiated the call to all callbacks.
  this.context = Context.current();
  this.unaryRequest = method.getType() == MethodType.UNARY
      || method.getType() == MethodType.SERVER_STREAMING;
  this.callOptions = callOptions;
  this.clientTransportProvider = clientTransportProvider;
  this.deadlineCancellationExecutor = deadlineCancellationExecutor;
  this.retryEnabled = retryEnabled;
  PerfMark.event("ClientCall.<init>", tag);
}
 
Example 8
Source File: ZuulEndPointRunner.java    From zuul with Apache License 2.0 5 votes vote down vote up
@Override
public void filter(final HttpRequestMessage zuulReq) {
    if (zuulReq.getContext().isCancelled()) {
        PerfMark.event(getClass().getName(), "filterCancelled");
        zuulReq.disposeBufferedBody();
        logger.debug("Request was cancelled, UUID {}", zuulReq.getContext().getUUID());
        return;
    }

    final String endpointName = getEndPointName(zuulReq.getContext());
    PerfMark.startTask(getClass().getName(), "filter");
    try {
        Preconditions.checkNotNull(zuulReq, "input message");
        addPerfMarkTags(zuulReq);

        final ZuulFilter<HttpRequestMessage, HttpResponseMessage> endpoint = getEndpoint(endpointName, zuulReq);
        logger.debug("Got endpoint {}, UUID {}", endpoint.filterName(), zuulReq.getContext().getUUID());
        setEndpoint(zuulReq, endpoint);
        final HttpResponseMessage zuulResp = filter(endpoint, zuulReq);

        if ((zuulResp != null)&&(! (endpoint instanceof ProxyEndpoint))) {
            //EdgeProxyEndpoint calls invokeNextStage internally
            logger.debug("Endpoint calling invokeNextStage, UUID {}", zuulReq.getContext().getUUID());
            invokeNextStage(zuulResp);
        }
    }
    catch (Exception ex) {
        handleException(zuulReq, endpointName, ex);
    } finally {
        PerfMark.stopTask(getClass().getName(), "filter");
    }
}
 
Example 9
Source File: OkHttpClientTransport.java    From grpc-java with Apache License 2.0 4 votes vote down vote up
/**
 * Handle an HTTP2 DATA frame.
 */
@SuppressWarnings("GuardedBy")
@Override
public void data(boolean inFinished, int streamId, BufferedSource in, int length)
    throws IOException {
  logger.logData(OkHttpFrameLogger.Direction.INBOUND,
      streamId, in.buffer(), length, inFinished);
  OkHttpClientStream stream = getStream(streamId);
  if (stream == null) {
    if (mayHaveCreatedStream(streamId)) {
      synchronized (lock) {
        frameWriter.rstStream(streamId, ErrorCode.INVALID_STREAM);
      }
      in.skip(length);
    } else {
      onError(ErrorCode.PROTOCOL_ERROR, "Received data for unknown stream: " + streamId);
      return;
    }
  } else {
    // Wait until the frame is complete.
    in.require(length);

    Buffer buf = new Buffer();
    buf.write(in.buffer(), length);
    PerfMark.event("OkHttpClientTransport$ClientFrameHandler.data",
        stream.transportState().tag());
    synchronized (lock) {
      // TODO(b/145386688): This access should be guarded by 'stream.transportState().lock';
      // instead found: 'OkHttpClientTransport.this.lock'
      stream.transportState().transportDataReceived(buf, inFinished);
    }
  }

  // connection window update
  connectionUnacknowledgedBytesRead += length;
  if (connectionUnacknowledgedBytesRead >= initialWindowSize * DEFAULT_WINDOW_UPDATE_RATIO) {
    synchronized (lock) {
      frameWriter.windowUpdate(0, connectionUnacknowledgedBytesRead);
    }
    connectionUnacknowledgedBytesRead = 0;
  }
}
 
Example 10
Source File: OkHttpClientTransport.java    From grpc-java with Apache License 2.0 4 votes vote down vote up
/**
 * Handle HTTP2 HEADER and CONTINUATION frames.
 */
@SuppressWarnings("GuardedBy")
@Override
public void headers(boolean outFinished,
    boolean inFinished,
    int streamId,
    int associatedStreamId,
    List<Header> headerBlock,
    HeadersMode headersMode) {
  logger.logHeaders(OkHttpFrameLogger.Direction.INBOUND, streamId, headerBlock, inFinished);
  boolean unknownStream = false;
  Status failedStatus = null;
  if (maxInboundMetadataSize != Integer.MAX_VALUE) {
    int metadataSize = headerBlockSize(headerBlock);
    if (metadataSize > maxInboundMetadataSize) {
      failedStatus = Status.RESOURCE_EXHAUSTED.withDescription(
          String.format(
              "Response %s metadata larger than %d: %d",
              inFinished ? "trailer" : "header",
              maxInboundMetadataSize,
              metadataSize));
    }
  }
  synchronized (lock) {
    OkHttpClientStream stream = streams.get(streamId);
    if (stream == null) {
      if (mayHaveCreatedStream(streamId)) {
        frameWriter.rstStream(streamId, ErrorCode.INVALID_STREAM);
      } else {
        unknownStream = true;
      }
    } else {
      if (failedStatus == null) {
        PerfMark.event("OkHttpClientTransport$ClientFrameHandler.headers",
            stream.transportState().tag());
        // TODO(b/145386688): This access should be guarded by 'stream.transportState().lock';
        // instead found: 'OkHttpClientTransport.this.lock'
        stream.transportState().transportHeadersReceived(headerBlock, inFinished);
      } else {
        if (!inFinished) {
          frameWriter.rstStream(streamId, ErrorCode.CANCEL);
        }
        stream.transportState().transportReportStatus(failedStatus, false, new Metadata());
      }
    }
  }
  if (unknownStream) {
    // We don't expect any server-initiated streams.
    onError(ErrorCode.PROTOCOL_ERROR, "Received header for unknown stream: " + streamId);
  }
}