Updated Branches: refs/heads/apache-blur-0.2 12ef492a4 -> 4c2882f4a
Adding hooks to be able to trace around thrift reading and writing operations. Project: http://git-wip-us.apache.org/repos/asf/incubator-blur/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-blur/commit/4c2882f4 Tree: http://git-wip-us.apache.org/repos/asf/incubator-blur/tree/4c2882f4 Diff: http://git-wip-us.apache.org/repos/asf/incubator-blur/diff/4c2882f4 Branch: refs/heads/apache-blur-0.2 Commit: 4c2882f4af448bb535127c818f885f3934afaeae Parents: 12ef492 Author: Aaron McCurry <[email protected]> Authored: Thu Dec 5 09:50:12 2013 -0500 Committer: Aaron McCurry <[email protected]> Committed: Thu Dec 5 09:50:12 2013 -0500 ---------------------------------------------------------------------- .../apache/blur/server/BlurServerContext.java | 9 ++- .../server/AbstractNonblockingServer.java | 76 +++++++++++++++----- .../apache/blur/thrift/server/ThriftTrace.java | 23 ++++++ .../apache/blur/thrift/server/ThriftTracer.java | 37 ++++++++++ 4 files changed, 126 insertions(+), 19 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/4c2882f4/blur-core/src/main/java/org/apache/blur/server/BlurServerContext.java ---------------------------------------------------------------------- diff --git a/blur-core/src/main/java/org/apache/blur/server/BlurServerContext.java b/blur-core/src/main/java/org/apache/blur/server/BlurServerContext.java index 60c59eb..8061b38 100644 --- a/blur-core/src/main/java/org/apache/blur/server/BlurServerContext.java +++ b/blur-core/src/main/java/org/apache/blur/server/BlurServerContext.java @@ -22,8 +22,10 @@ import org.apache.blur.log.Log; import org.apache.blur.log.LogFactory; import org.apache.blur.thirdparty.thrift_0_9_0.server.ServerContext; import org.apache.blur.thrift.generated.User; +import org.apache.blur.thrift.server.ThriftTrace; +import org.apache.blur.thrift.server.ThriftTracer; -public class BlurServerContext implements ServerContext { +public class BlurServerContext implements ServerContext, ThriftTrace { private static final Log LOG = LogFactory.getLog(BlurServerContext.class); @@ -84,4 +86,9 @@ public class BlurServerContext implements ServerContext { _traceRequestId = null; } + @Override + public ThriftTracer getTracer(String name) { + return ThriftTracer.NOTHING; + } + } http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/4c2882f4/blur-thrift/src/main/java/org/apache/blur/thrift/server/AbstractNonblockingServer.java ---------------------------------------------------------------------- diff --git a/blur-thrift/src/main/java/org/apache/blur/thrift/server/AbstractNonblockingServer.java b/blur-thrift/src/main/java/org/apache/blur/thrift/server/AbstractNonblockingServer.java index 5fee759..667c2a4 100644 --- a/blur-thrift/src/main/java/org/apache/blur/thrift/server/AbstractNonblockingServer.java +++ b/blur-thrift/src/main/java/org/apache/blur/thrift/server/AbstractNonblockingServer.java @@ -50,7 +50,8 @@ import org.slf4j.LoggerFactory; public abstract class AbstractNonblockingServer extends TServer { protected final Logger LOGGER = LoggerFactory.getLogger(getClass().getName()); - public static abstract class AbstractNonblockingServerArgs<T extends AbstractNonblockingServerArgs<T>> extends AbstractServerArgs<T> { + public static abstract class AbstractNonblockingServerArgs<T extends AbstractNonblockingServerArgs<T>> extends + AbstractServerArgs<T> { public long maxReadBufferBytes = Long.MAX_VALUE; public AbstractNonblockingServerArgs(TNonblockingServerTransport transport) { @@ -201,17 +202,44 @@ public abstract class AbstractNonblockingServer extends TServer { */ protected void handleRead(SelectionKey key) { FrameBuffer buffer = (FrameBuffer) key.attachment(); - if (!buffer.read()) { - cleanupSelectionKey(key); - return; + ThriftTracer readTracer = ThriftTracer.NOTHING; + if (buffer.context_ != null) { + ServerContext context = buffer.context_; + if (context instanceof ThriftTrace) { + ThriftTrace thriftTrace = (ThriftTrace) context; + readTracer = thriftTrace.getTracer("thrift - handle read"); + } + } + readTracer.start(); + try { + if (!buffer.read()) { + cleanupSelectionKey(key); + return; + } + } finally { + readTracer.end(); } // if the buffer's frame read is complete, invoke the method. if (buffer.isFrameFullyRead()) { - if (!requestInvoke(buffer)) { - cleanupSelectionKey(key); + ThriftTracer processTracer = ThriftTracer.NOTHING; + if (buffer.context_ != null) { + ServerContext context = buffer.context_; + if (context instanceof ThriftTrace) { + ThriftTrace thriftTrace = (ThriftTrace) context; + processTracer = thriftTrace.getTracer("thrift - handle request"); + } + } + processTracer.start(); + try { + if (!requestInvoke(buffer)) { + cleanupSelectionKey(key); + } + } finally { + processTracer.end(); } } + } /** @@ -219,8 +247,21 @@ public abstract class AbstractNonblockingServer extends TServer { */ protected void handleWrite(SelectionKey key) { FrameBuffer buffer = (FrameBuffer) key.attachment(); - if (!buffer.write()) { - cleanupSelectionKey(key); + ThriftTracer writeTracer = ThriftTracer.NOTHING; + if (buffer.context_ != null) { + ServerContext context = buffer.context_; + if (context instanceof ThriftTrace) { + ThriftTrace thriftTrace = (ThriftTrace) context; + writeTracer = thriftTrace.getTracer("thrift - handle write"); + } + } + writeTracer.start(); + try { + if (!buffer.write()) { + cleanupSelectionKey(key); + } + } finally { + writeTracer.end(); } } @@ -284,26 +325,25 @@ public abstract class AbstractNonblockingServer extends TServer { private ByteBuffer buffer_; private final TByteArrayOutputStream response_; - + // the frame that the TTransport should wrap. private final TMemoryInputTransport frameTrans_; - + // the transport that should be used to connect to clients private final TTransport inTrans_; - + private final TTransport outTrans_; - + // the input protocol to use on frames private final TProtocol inProt_; - + // the output protocol to use on frames private final TProtocol outProt_; - + // context associated with this connection private final ServerContext context_; - public FrameBuffer(final TNonblockingTransport trans, - final SelectionKey selectionKey, + public FrameBuffer(final TNonblockingTransport trans, final SelectionKey selectionKey, final AbstractSelectThread selectThread) { trans_ = trans; selectionKey_ = selectionKey; @@ -320,7 +360,7 @@ public abstract class AbstractNonblockingServer extends TServer { if (eventHandler_ != null) { context_ = eventHandler_.createContext(inProt_, outProt_, selectionKey); } else { - context_ = null; + context_ = null; } } @@ -507,7 +547,7 @@ public abstract class AbstractNonblockingServer extends TServer { public void invoke() { frameTrans_.reset(buffer_.array()); response_.reset(); - + try { if (eventHandler_ != null) { eventHandler_.processContext(context_, inTrans_, outTrans_); http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/4c2882f4/blur-thrift/src/main/java/org/apache/blur/thrift/server/ThriftTrace.java ---------------------------------------------------------------------- diff --git a/blur-thrift/src/main/java/org/apache/blur/thrift/server/ThriftTrace.java b/blur-thrift/src/main/java/org/apache/blur/thrift/server/ThriftTrace.java new file mode 100644 index 0000000..3a42983 --- /dev/null +++ b/blur-thrift/src/main/java/org/apache/blur/thrift/server/ThriftTrace.java @@ -0,0 +1,23 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.blur.thrift.server; + +public interface ThriftTrace { + + ThriftTracer getTracer(String name); + +} http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/4c2882f4/blur-thrift/src/main/java/org/apache/blur/thrift/server/ThriftTracer.java ---------------------------------------------------------------------- diff --git a/blur-thrift/src/main/java/org/apache/blur/thrift/server/ThriftTracer.java b/blur-thrift/src/main/java/org/apache/blur/thrift/server/ThriftTracer.java new file mode 100644 index 0000000..c8a9937 --- /dev/null +++ b/blur-thrift/src/main/java/org/apache/blur/thrift/server/ThriftTracer.java @@ -0,0 +1,37 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.blur.thrift.server; + +public abstract class ThriftTracer { + + public static final ThriftTracer NOTHING = new ThriftTracer() { + @Override + public void start() { + + } + + @Override + public void end() { + + } + }; + + public abstract void start(); + + public abstract void end(); + +}
