You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@giraph.apache.org by ma...@apache.org on 2014/02/14 17:53:03 UTC
[2/2] git commit: updated refs/heads/trunk to 62f9fd3
GIRAPH-840: Upgrade to netty 4 (pavanka via majakabiljo)
Project: http://git-wip-us.apache.org/repos/asf/giraph/repo
Commit: http://git-wip-us.apache.org/repos/asf/giraph/commit/62f9fd3f
Tree: http://git-wip-us.apache.org/repos/asf/giraph/tree/62f9fd3f
Diff: http://git-wip-us.apache.org/repos/asf/giraph/diff/62f9fd3f
Branch: refs/heads/trunk
Commit: 62f9fd3fd3c13c8387e7448c4f3ea6b8f65b8a8c
Parents: c5f2d61
Author: Maja Kabiljo <ma...@fb.com>
Authored: Fri Feb 14 08:51:22 2014 -0800
Committer: Maja Kabiljo <ma...@fb.com>
Committed: Fri Feb 14 08:52:42 2014 -0800
----------------------------------------------------------------------
CHANGELOG | 2 +
giraph-core/pom.xml | 2 +-
.../apache/giraph/comm/netty/ByteCounter.java | 204 +------------
.../giraph/comm/netty/ByteCounterDelegate.java | 193 +++++++++++++
.../giraph/comm/netty/ChannelRotater.java | 8 +-
.../giraph/comm/netty/InboundByteCounter.java | 97 +++++++
.../apache/giraph/comm/netty/NettyClient.java | 284 ++++++++++---------
.../apache/giraph/comm/netty/NettyServer.java | 244 ++++++++--------
.../giraph/comm/netty/OutboundByteCounter.java | 97 +++++++
...aptiveReceiveBufferSizePredictorFactory.java | 133 ---------
.../netty/handler/AuthorizeServerHandler.java | 23 +-
.../comm/netty/handler/RequestDecoder.java | 38 +--
.../comm/netty/handler/RequestEncoder.java | 41 ++-
.../giraph/comm/netty/handler/RequestInfo.java | 2 +-
.../netty/handler/RequestServerHandler.java | 49 ++--
.../netty/handler/ResponseClientHandler.java | 73 ++---
.../comm/netty/handler/ResponseEncoder.java | 38 +--
.../comm/netty/handler/SaslClientHandler.java | 59 ++--
.../comm/netty/handler/SaslServerHandler.java | 39 +--
.../apache/giraph/conf/GiraphConfiguration.java | 26 ++
.../org/apache/giraph/conf/GiraphConstants.java | 12 +-
.../utils/DynamicChannelBufferInputStream.java | 6 +-
.../utils/DynamicChannelBufferOutputStream.java | 20 +-
.../org/apache/giraph/utils/PipelineUtils.java | 57 ++++
.../apache/giraph/utils/ProgressableUtils.java | 16 +-
pom.xml | 6 +-
26 files changed, 977 insertions(+), 792 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/giraph/blob/62f9fd3f/CHANGELOG
----------------------------------------------------------------------
diff --git a/CHANGELOG b/CHANGELOG
index 3e1acc2..1c8729f 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -1,6 +1,8 @@
Giraph Change Log
Release 1.1.0 - unreleased
+ GIRAPH-840: Upgrade to netty 4 (pavanka via majakabiljo)
+
GIRAPH-816: ByteArrayPartition not combining vertex edges (cmuchins via majakabiljo)
GIRAPH-844: TextInputFormat for SimpleShortestPaths (ssc)
http://git-wip-us.apache.org/repos/asf/giraph/blob/62f9fd3f/giraph-core/pom.xml
----------------------------------------------------------------------
diff --git a/giraph-core/pom.xml b/giraph-core/pom.xml
index 90dd5e4..944ad4b 100644
--- a/giraph-core/pom.xml
+++ b/giraph-core/pom.xml
@@ -492,7 +492,7 @@ under the License.
</dependency>
<dependency>
<groupId>io.netty</groupId>
- <artifactId>netty</artifactId>
+ <artifactId>netty-all</artifactId>
</dependency>
<dependency>
<groupId>net.iharder</groupId>
http://git-wip-us.apache.org/repos/asf/giraph/blob/62f9fd3f/giraph-core/src/main/java/org/apache/giraph/comm/netty/ByteCounter.java
----------------------------------------------------------------------
diff --git a/giraph-core/src/main/java/org/apache/giraph/comm/netty/ByteCounter.java b/giraph-core/src/main/java/org/apache/giraph/comm/netty/ByteCounter.java
index 6bba199..444e5a6 100644
--- a/giraph-core/src/main/java/org/apache/giraph/comm/netty/ByteCounter.java
+++ b/giraph-core/src/main/java/org/apache/giraph/comm/netty/ByteCounter.java
@@ -18,198 +18,18 @@
package org.apache.giraph.comm.netty;
-import org.apache.giraph.metrics.GiraphMetrics;
-import org.apache.giraph.metrics.MeterDesc;
-import org.apache.giraph.metrics.MetricNames;
-import org.apache.giraph.metrics.ResetSuperstepMetricsObserver;
-import org.apache.giraph.metrics.SuperstepMetricsRegistry;
-import org.apache.giraph.time.SystemTime;
-import org.apache.giraph.time.Time;
-import org.apache.log4j.Logger;
-import org.jboss.netty.buffer.ChannelBuffer;
-import org.jboss.netty.channel.ChannelEvent;
-import org.jboss.netty.channel.ChannelHandlerContext;
-import org.jboss.netty.channel.MessageEvent;
-import org.jboss.netty.channel.SimpleChannelHandler;
-
-import com.yammer.metrics.core.Histogram;
-import com.yammer.metrics.core.Meter;
-import com.yammer.metrics.core.NoOpHistogram;
-import com.yammer.metrics.core.NoOpMeter;
-
-import java.text.DecimalFormat;
-import java.util.concurrent.atomic.AtomicLong;
-
-/**
- * Keep track of the bytes sent/received and provide some metrics when
- * desired as part of the Netty Channel stack.
- */
-public class ByteCounter extends SimpleChannelHandler implements
- ResetSuperstepMetricsObserver {
- /** Megabyte in bytes */
- public static final double MEGABYTE = 1024f * 1024f;
- /** Helper to format the doubles */
- private static final DecimalFormat DOUBLE_FORMAT =
- new DecimalFormat("#######.####");
- /** Class logger */
- private static final Logger LOG =
- Logger.getLogger(ByteCounter.class);
- /** Class timer */
- private static final Time TIME = SystemTime.get();
- /** All bytes ever sent */
- private final AtomicLong bytesSent = new AtomicLong();
- /** Total sent requests */
- private final AtomicLong sentRequests = new AtomicLong();
- /** All bytes ever received */
- private final AtomicLong bytesReceived = new AtomicLong();
- /** Total received requests */
- private final AtomicLong receivedRequests = new AtomicLong();
- /** Start time (for bandwidth calculation) */
- private final AtomicLong startMsecs = new AtomicLong(TIME.getMilliseconds());
- /** Last updated msecs for getMetricsWindow */
- private final AtomicLong metricsWindowLastUpdatedMsecs = new AtomicLong();
-
- // Metrics
- /** Meter of requests sent */
- private Meter sentRequestsMeter = NoOpMeter.INSTANCE;
- /** Histogram of bytes sent */
- private Histogram sentBytesHist = NoOpHistogram.INSTANCE;
- /** Meter of requests received */
- private Meter receivedRequestsMeter = NoOpMeter.INSTANCE;
- /** Histogram of bytes received */
- private Histogram receivedBytesHist = NoOpHistogram.INSTANCE;
-
- /** Constructor */
- public ByteCounter() {
- // Initialize Metrics
- GiraphMetrics.get().addSuperstepResetObserver(this);
- }
-
- @Override
- public void newSuperstep(SuperstepMetricsRegistry superstepMetrics) {
- sentRequestsMeter = superstepMetrics.getMeter(MeterDesc.SENT_REQUESTS);
- sentBytesHist = superstepMetrics.getUniformHistogram(
- MetricNames.SENT_BYTES);
- receivedRequestsMeter = superstepMetrics.getMeter(
- MeterDesc.RECEIVED_REQUESTS);
- receivedBytesHist = superstepMetrics.getUniformHistogram(
- MetricNames.RECEIVED_BYTES);
- }
-
- @Override
- public void handleUpstream(ChannelHandlerContext ctx, ChannelEvent e)
- throws Exception {
- if (e instanceof MessageEvent &&
- ((MessageEvent) e).getMessage() instanceof ChannelBuffer) {
- ChannelBuffer b = (ChannelBuffer) ((MessageEvent) e).getMessage();
- int receivedBytes = b.readableBytes();
- bytesReceived.addAndGet(receivedBytes);
- receivedBytesHist.update(receivedBytes);
- receivedRequests.incrementAndGet();
- receivedRequestsMeter.mark();
- if (LOG.isDebugEnabled()) {
- LOG.debug("handleUpstream: " + ctx.getName() + " buffer size = " +
- receivedBytes + ", total bytes = " + bytesReceived.get());
- }
- }
-
- super.handleUpstream(ctx, e);
- }
-
- @Override
- public void handleDownstream(ChannelHandlerContext ctx, ChannelEvent e)
- throws Exception {
- if (e instanceof MessageEvent &&
- ((MessageEvent) e).getMessage() instanceof ChannelBuffer) {
- ChannelBuffer b = (ChannelBuffer) ((MessageEvent) e).getMessage();
- int sentBytes = b.readableBytes();
- bytesSent.addAndGet(sentBytes);
- sentBytesHist.update(sentBytes);
- sentRequests.incrementAndGet();
- sentRequestsMeter.mark();
- if (LOG.isDebugEnabled()) {
- LOG.debug("handleDownstream: " + ctx.getName() + " buffer size = " +
- sentBytes + ", total bytes = " + bytesSent.get());
- }
- }
-
- super.handleDownstream(ctx, e);
- }
-
- /**
- * Reset all the bytes kept track of.
- */
- private void resetBytes() {
- bytesSent.set(0);
- sentRequests.set(0);
- bytesReceived.set(0);
- receivedRequests.set(0);
- }
-
- /**
- * Reset the start msecs.
- */
- private void resetStartMsecs() {
- startMsecs.set(TIME.getMilliseconds());
- }
+/** ByteCounter interface */
+public interface ByteCounter {
/**
* Reset everything this object keeps track of
*/
- public void resetAll() {
- resetBytes();
- resetStartMsecs();
- }
-
- public long getBytesSent() {
- return bytesSent.get();
- }
-
- public long getBytesReceived() {
- return bytesReceived.get();
- }
-
- /**
- * @return Mbytes sent / sec in the current interval
- */
- public double getMbytesPerSecSent() {
- return bytesSent.get() * 1000f /
- (1 + TIME.getMilliseconds() - startMsecs.get()) / MEGABYTE;
- }
-
- /**
- * @return Mbytes received / sec in the current interval
- */
- public double getMbytesPerSecReceived() {
- return bytesReceived.get() * 1000f /
- (1 + TIME.getMilliseconds() - startMsecs.get()) / MEGABYTE;
- }
+ void resetAll();
/**
* @return A string containing all the metrics
*/
- public String getMetrics() {
- double mBytesSent = bytesSent.get() / MEGABYTE;
- double mBytesReceived = bytesReceived.get() / MEGABYTE;
- long curSentRequests = sentRequests.get();
- long curReceivedRequests = receivedRequests.get();
- double mBytesSentPerReq =
- (curSentRequests == 0) ? 0 : mBytesSent / curSentRequests;
- double mBytesReceivedPerReq =
- (curReceivedRequests == 0) ? 0 : mBytesReceived / curReceivedRequests;
- return "MBytes/sec sent = " +
- DOUBLE_FORMAT.format(getMbytesPerSecSent()) +
- ", MBytes/sec received = " +
- DOUBLE_FORMAT.format(getMbytesPerSecReceived()) +
- ", MBytesSent = " + DOUBLE_FORMAT.format(mBytesSent) +
- ", MBytesReceived = " + DOUBLE_FORMAT.format(mBytesReceived) +
- ", ave sent req MBytes = " +
- DOUBLE_FORMAT.format(mBytesSentPerReq) +
- ", ave received req MBytes = " +
- DOUBLE_FORMAT.format(mBytesReceivedPerReq) +
- ", secs waited = " +
- ((TIME.getMilliseconds() - startMsecs.get()) / 1000f);
- }
+ String getMetrics();
/**
* Get the metrics if a given window of time has passed. Return null
@@ -218,19 +38,5 @@ public class ByteCounter extends SimpleChannelHandler implements
* @param minMsecsWindow Msecs of the minimum window
* @return Metrics or else null if the window wasn't met
*/
- public String getMetricsWindow(int minMsecsWindow) {
- long lastUpdatedMsecs = metricsWindowLastUpdatedMsecs.get();
- long curMsecs = TIME.getMilliseconds();
- if (curMsecs - lastUpdatedMsecs > minMsecsWindow) {
- // Make sure that only one thread does this update
- if (metricsWindowLastUpdatedMsecs.compareAndSet(lastUpdatedMsecs,
- curMsecs)) {
- String metrics = getMetrics();
- resetAll();
- return metrics;
- }
- }
-
- return null;
- }
+ String getMetricsWindow(int minMsecsWindow);
}
http://git-wip-us.apache.org/repos/asf/giraph/blob/62f9fd3f/giraph-core/src/main/java/org/apache/giraph/comm/netty/ByteCounterDelegate.java
----------------------------------------------------------------------
diff --git a/giraph-core/src/main/java/org/apache/giraph/comm/netty/ByteCounterDelegate.java b/giraph-core/src/main/java/org/apache/giraph/comm/netty/ByteCounterDelegate.java
new file mode 100644
index 0000000..710ec9d
--- /dev/null
+++ b/giraph-core/src/main/java/org/apache/giraph/comm/netty/ByteCounterDelegate.java
@@ -0,0 +1,193 @@
+/*
+ * 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.giraph.comm.netty;
+
+import com.yammer.metrics.core.Histogram;
+import com.yammer.metrics.core.Meter;
+import com.yammer.metrics.core.NoOpHistogram;
+import com.yammer.metrics.core.NoOpMeter;
+import io.netty.buffer.ByteBuf;
+import org.apache.giraph.metrics.MeterDesc;
+import org.apache.giraph.metrics.MetricNames;
+import org.apache.giraph.metrics.SuperstepMetricsRegistry;
+import org.apache.giraph.time.SystemTime;
+import org.apache.giraph.time.Time;
+
+import java.text.DecimalFormat;
+import java.util.concurrent.atomic.AtomicLong;
+
+/**
+ * Delegate Object to help keep track of the bytes processed and provide some
+ * metrics when desired as part of the Netty Channel stack.
+ */
+public class ByteCounterDelegate implements ByteCounter {
+ /** Megabyte in bytes */
+ public static final double MEGABYTE = 1024f * 1024f;
+ /** Helper to format the doubles */
+ private static final DecimalFormat DOUBLE_FORMAT =
+ new DecimalFormat("#######.####");
+ /** Class timer */
+ private static final Time TIME = SystemTime.get();
+ /** All bytes ever processed */
+ private final AtomicLong bytesProcessed = new AtomicLong();
+ /** Total processed requests */
+ private final AtomicLong processedRequests = new AtomicLong();
+ /** Start time (for bandwidth calculation) */
+ private final AtomicLong startMsecs = new AtomicLong();
+ /** Last updated msecs for getMetricsWindow */
+ private final AtomicLong metricsWindowLastUpdatedMsecs = new AtomicLong();
+
+ // Metrics
+ /** Meter of requests sent */
+ private Meter processedRequestsMeter = NoOpMeter.INSTANCE;
+ /** Histogram of bytes sent */
+ private Histogram processedBytesHist = NoOpHistogram.INSTANCE;
+
+ /** Is it delegate for InBoundByteCounter */
+ private final boolean isInbound;
+
+ /**
+ * Constructor to specify if delegate is created by InBound/ Outbound counter
+ *
+ * @param isInBound switch to specify if instantiated by inbound counter
+ */
+ public ByteCounterDelegate(boolean isInBound) {
+ this.isInbound = isInBound;
+ }
+
+ /**
+ * Called by Inbound/ Outbound counters to refresh meters on a new superstep
+ *
+ * @param superstepMetrics superstepmetrics registry
+ */
+ public void newSuperstep(SuperstepMetricsRegistry superstepMetrics) {
+ if (isInbound) {
+ processedRequestsMeter = superstepMetrics.getMeter(
+ MeterDesc.RECEIVED_REQUESTS);
+ processedBytesHist = superstepMetrics.getUniformHistogram(
+ MetricNames.RECEIVED_BYTES);
+ } else {
+ processedRequestsMeter = superstepMetrics.getMeter(
+ MeterDesc.SENT_REQUESTS);
+ processedBytesHist = superstepMetrics.getUniformHistogram(
+ MetricNames.SENT_BYTES);
+ }
+ }
+
+ /**
+ * Updates properties based on bytes sent / received
+ *
+ * @param buf ByteBuf received by the counter
+ * @return number of readable bytes
+ */
+ public int byteBookkeeper(ByteBuf buf) {
+ int processedBytes = buf.readableBytes();
+ bytesProcessed.addAndGet(processedBytes);
+ processedBytesHist.update(processedBytes);
+ processedRequests.incrementAndGet();
+ processedRequestsMeter.mark();
+ return processedBytes;
+ }
+
+ /**
+ * Reset all the bytes kept track of.
+ */
+ public void resetBytes() {
+ bytesProcessed.set(0);
+ processedRequests.set(0);
+ }
+
+ /**
+ * Reset the start msecs.
+ */
+ public void resetStartMsecs() {
+ startMsecs.set(TIME.getMilliseconds());
+ }
+
+ @Override
+ public void resetAll() {
+ resetBytes();
+ resetStartMsecs();
+ }
+
+ public long getBytesProcessed() {
+ return bytesProcessed.get();
+ }
+
+ /**
+ * @return Mbytes processed / sec in the current interval
+ */
+ public double getMbytesPerSecProcessed() {
+ return bytesProcessed.get() * 1000f /
+ (1 + TIME.getMilliseconds() - startMsecs.get()) / MEGABYTE;
+ }
+
+ /**
+ * Helper method used by getMetrics to create its return string
+ * @param mBytesProcessed mbytes processed
+ * @param mBytesProcessedPerReq mbytes processed per request
+ * @return A string containing all the metrics
+ */
+ public String getMetricsHelper(double mBytesProcessed,
+ double mBytesProcessedPerReq) {
+ if (isInbound) {
+ return "MBytes/sec received = " +
+ DOUBLE_FORMAT.format(getMbytesPerSecProcessed()) +
+ ", MBytesReceived = " + DOUBLE_FORMAT.format(mBytesProcessed) +
+ ", ave received req MBytes = " +
+ DOUBLE_FORMAT.format(mBytesProcessedPerReq) +
+ ", secs waited = " +
+ ((TIME.getMilliseconds() - startMsecs.get()) / 1000f);
+ } else {
+ return "MBytes/sec sent = " +
+ DOUBLE_FORMAT.format(getMbytesPerSecProcessed()) +
+ ", MBytesSent = " + DOUBLE_FORMAT.format(mBytesProcessed) +
+ ", ave sent req MBytes = " +
+ DOUBLE_FORMAT.format(mBytesProcessedPerReq) +
+ ", secs waited = " +
+ ((TIME.getMilliseconds() - startMsecs.get()) / 1000f);
+ }
+ }
+
+ @Override
+ public String getMetrics() {
+ double mBytesProcessed = bytesProcessed.get() / MEGABYTE;
+ long curProcessedRequests = processedRequests.get();
+ double mBytesProcessedPerReq = (curProcessedRequests == 0) ? 0 :
+ mBytesProcessed / curProcessedRequests;
+
+ return getMetricsHelper(mBytesProcessed, mBytesProcessedPerReq);
+ }
+
+ @Override
+ public String getMetricsWindow(int minMsecsWindow) {
+ long lastUpdatedMsecs = metricsWindowLastUpdatedMsecs.get();
+ long curMsecs = TIME.getMilliseconds();
+ if (curMsecs - lastUpdatedMsecs > minMsecsWindow) {
+ // Make sure that only one thread does this update
+ if (metricsWindowLastUpdatedMsecs.compareAndSet(lastUpdatedMsecs,
+ curMsecs)) {
+ String metrics = getMetrics();
+ resetAll();
+ return metrics;
+ }
+ }
+ return null;
+ }
+}
http://git-wip-us.apache.org/repos/asf/giraph/blob/62f9fd3f/giraph-core/src/main/java/org/apache/giraph/comm/netty/ChannelRotater.java
----------------------------------------------------------------------
diff --git a/giraph-core/src/main/java/org/apache/giraph/comm/netty/ChannelRotater.java b/giraph-core/src/main/java/org/apache/giraph/comm/netty/ChannelRotater.java
index c6f47bb..b9e806d 100644
--- a/giraph-core/src/main/java/org/apache/giraph/comm/netty/ChannelRotater.java
+++ b/giraph-core/src/main/java/org/apache/giraph/comm/netty/ChannelRotater.java
@@ -20,9 +20,11 @@ package org.apache.giraph.comm.netty;
import java.util.List;
import com.google.common.collect.Lists;
-import org.jboss.netty.channel.Channel;
-import org.jboss.netty.channel.ChannelFuture;
-import org.jboss.netty.channel.ChannelFutureListener;
+
+import io.netty.channel.Channel;
+import io.netty.channel.ChannelFuture;
+import io.netty.channel.ChannelFutureListener;
+
/**
* Maintains multiple channels and rotates between them. This is thread-safe.
http://git-wip-us.apache.org/repos/asf/giraph/blob/62f9fd3f/giraph-core/src/main/java/org/apache/giraph/comm/netty/InboundByteCounter.java
----------------------------------------------------------------------
diff --git a/giraph-core/src/main/java/org/apache/giraph/comm/netty/InboundByteCounter.java b/giraph-core/src/main/java/org/apache/giraph/comm/netty/InboundByteCounter.java
new file mode 100644
index 0000000..bcc888d
--- /dev/null
+++ b/giraph-core/src/main/java/org/apache/giraph/comm/netty/InboundByteCounter.java
@@ -0,0 +1,97 @@
+/*
+ * 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.giraph.comm.netty;
+
+import org.apache.giraph.metrics.GiraphMetrics;
+import org.apache.giraph.metrics.ResetSuperstepMetricsObserver;
+import org.apache.giraph.metrics.SuperstepMetricsRegistry;
+import org.apache.log4j.Logger;
+
+import io.netty.buffer.ByteBuf;
+import io.netty.channel.ChannelHandlerContext;
+import io.netty.channel.ChannelInboundHandlerAdapter;
+import io.netty.channel.ChannelHandler.Sharable;
+
+
+/**
+ * Keep track of the bytes received and provide some metrics when
+ * desired as part of the Netty Channel stack.
+ */
+@Sharable
+public class InboundByteCounter extends ChannelInboundHandlerAdapter implements
+ ByteCounter, ResetSuperstepMetricsObserver {
+ /** Class logger */
+ private static final Logger LOG =
+ Logger.getLogger(InboundByteCounter.class);
+ /** ByteCounter delegate object */
+ private final ByteCounterDelegate delegate = new ByteCounterDelegate(true);
+
+ /** Constructor */
+ public InboundByteCounter() {
+ // Initialize Metrics
+ GiraphMetrics.get().addSuperstepResetObserver(this);
+ }
+
+ public long getBytesReceived() {
+ return delegate.getBytesProcessed();
+ }
+
+ /**
+ * @return Mbytes received / sec in the current interval
+ */
+ public double getMbytesPerSecReceived() {
+ return delegate.getMbytesPerSecProcessed();
+ }
+
+ @Override
+ public void channelRead(ChannelHandlerContext ctx, Object msg)
+ throws Exception {
+ if (msg instanceof ByteBuf) {
+ ByteBuf buf = (ByteBuf) msg;
+ int receivedBytes = delegate.byteBookkeeper(buf);
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("channelRead: " + ctx.channel().toString() + " buffer " +
+ "size = " + receivedBytes + ", total bytes = " +
+ getBytesReceived());
+ }
+
+ }
+ ctx.fireChannelRead(msg);
+ }
+
+ @Override
+ public void newSuperstep(SuperstepMetricsRegistry superstepMetrics) {
+ delegate.newSuperstep(superstepMetrics);
+ }
+
+ @Override
+ public void resetAll() {
+ delegate.resetAll();
+ }
+
+ @Override
+ public String getMetrics() {
+ return delegate.getMetrics();
+ }
+
+ @Override
+ public String getMetricsWindow(int minMsecsWindow) {
+ return delegate.getMetricsWindow(minMsecsWindow);
+ }
+}
http://git-wip-us.apache.org/repos/asf/giraph/blob/62f9fd3f/giraph-core/src/main/java/org/apache/giraph/comm/netty/NettyClient.java
----------------------------------------------------------------------
diff --git a/giraph-core/src/main/java/org/apache/giraph/comm/netty/NettyClient.java b/giraph-core/src/main/java/org/apache/giraph/comm/netty/NettyClient.java
index 83f1654..c40c2b8 100644
--- a/giraph-core/src/main/java/org/apache/giraph/comm/netty/NettyClient.java
+++ b/giraph-core/src/main/java/org/apache/giraph/comm/netty/NettyClient.java
@@ -33,23 +33,11 @@ import org.apache.giraph.comm.requests.WritableRequest;
import org.apache.giraph.conf.GiraphConstants;
import org.apache.giraph.conf.ImmutableClassesGiraphConfiguration;
import org.apache.giraph.graph.TaskInfo;
+import org.apache.giraph.utils.PipelineUtils;
import org.apache.giraph.utils.ProgressableUtils;
import org.apache.giraph.utils.TimedLogger;
import org.apache.hadoop.mapreduce.Mapper;
import org.apache.log4j.Logger;
-import org.jboss.netty.bootstrap.ClientBootstrap;
-import org.jboss.netty.channel.Channel;
-import org.jboss.netty.channel.ChannelFuture;
-import org.jboss.netty.channel.ChannelFutureListener;
-import org.jboss.netty.channel.ChannelLocal;
-import org.jboss.netty.channel.ChannelPipeline;
-import org.jboss.netty.channel.ChannelPipelineFactory;
-import org.jboss.netty.channel.Channels;
-import org.jboss.netty.channel.socket.nio.NioClientSocketChannelFactory;
-import org.jboss.netty.handler.codec.frame.FixedLengthFrameDecoder;
-import org.jboss.netty.handler.codec.frame.LengthFieldBasedFrameDecoder;
-import org.jboss.netty.handler.execution.ExecutionHandler;
-import org.jboss.netty.handler.execution.MemoryAwareThreadPoolExecutor;
import com.google.common.collect.Lists;
import com.google.common.collect.MapMaker;
@@ -64,12 +52,25 @@ import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentMap;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
-import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicLong;
+import io.netty.bootstrap.Bootstrap;
+import io.netty.channel.Channel;
+import io.netty.channel.ChannelFuture;
+import io.netty.channel.ChannelFutureListener;
+import io.netty.channel.ChannelInitializer;
+import io.netty.channel.ChannelOption;
+import io.netty.channel.EventLoopGroup;
+import io.netty.channel.nio.NioEventLoopGroup;
+import io.netty.channel.socket.SocketChannel;
+import io.netty.channel.socket.nio.NioSocketChannel;
+import io.netty.handler.codec.FixedLengthFrameDecoder;
+import io.netty.handler.codec.LengthFieldBasedFrameDecoder;
+import io.netty.util.AttributeKey;
+import io.netty.util.concurrent.DefaultEventExecutorGroup;
+import io.netty.util.concurrent.EventExecutorGroup;
+
import static org.apache.giraph.conf.GiraphConstants.CLIENT_RECEIVE_BUFFER_SIZE;
import static org.apache.giraph.conf.GiraphConstants.CLIENT_SEND_BUFFER_SIZE;
import static org.apache.giraph.conf.GiraphConstants.MAX_REQUEST_MILLISECONDS;
@@ -79,7 +80,6 @@ import static org.apache.giraph.conf.GiraphConstants.NETTY_CLIENT_EXECUTION_THRE
import static org.apache.giraph.conf.GiraphConstants.NETTY_CLIENT_USE_EXECUTION_HANDLER;
import static org.apache.giraph.conf.GiraphConstants.NETTY_MAX_CONNECTION_FAILURES;
import static org.apache.giraph.conf.GiraphConstants.WAITING_REQUEST_MSECS;
-import static org.jboss.netty.channel.Channels.pipeline;
/**
* Netty client for sending requests. Thread-safe.
@@ -106,15 +106,15 @@ public class NettyClient {
public static final int MAX_CONNECTION_MILLISECONDS_DEFAULT = 30 * 1000;
/*if_not[HADOOP_NON_SECURE]*/
/** Used to authenticate with other workers acting as servers */
- public static final ChannelLocal<SaslNettyClient> SASL =
- new ChannelLocal<SaslNettyClient>();
+ public static final AttributeKey<SaslNettyClient> SASL =
+ AttributeKey.valueOf("saslNettyClient");
/*end[HADOOP_NON_SECURE]*/
/** Class logger */
private static final Logger LOG = Logger.getLogger(NettyClient.class);
/** Context used to report progress */
private final Mapper<?, ?, ?, ?>.Context context;
/** Client bootstrap */
- private final ClientBootstrap bootstrap;
+ private final Bootstrap bootstrap;
/**
* Map of the peer connections, mapping from remote socket address to client
* meta data
@@ -133,8 +133,12 @@ public class NettyClient {
clientRequestIdRequestInfoMap;
/** Number of channels per server */
private final int channelsPerServer;
- /** Byte counter for this client */
- private final ByteCounter byteCounter = new ByteCounter();
+ /** Inbound byte counter for this client */
+ private final InboundByteCounter inboundByteCounter = new
+ InboundByteCounter();
+ /** Outbound byte counter for this client */
+ private final OutboundByteCounter outboundByteCounter = new
+ OutboundByteCounter();
/** Send buffer size */
private final int sendBufferSize;
/** Receive buffer size */
@@ -151,10 +155,8 @@ public class NettyClient {
private final int waitingRequestMsecs;
/** Timed logger for printing request debugging */
private final TimedLogger requestLogger = new TimedLogger(15 * 1000, LOG);
- /** Boss factory service */
- private final ExecutorService bossExecutorService;
- /** Worker factory service */
- private final ExecutorService workerExecutorService;
+ /** Worker executor group */
+ private final EventLoopGroup workerGroup;
/** Address request id generator */
private final AddressRequestIdGenerator addressRequestIdGenerator =
new AddressRequestIdGenerator();
@@ -165,11 +167,11 @@ public class NettyClient {
/** Maximum number of attempts to resolve an address*/
private final int maxResolveAddressAttempts;
/** Use execution handler? */
- private final boolean useExecutionHandler;
- /** Execution handler (if used) */
- private final ExecutionHandler executionHandler;
- /** Name of the handler before the execution handler (if used) */
- private final String handlerBeforeExecutionHandler;
+ private final boolean useExecutionGroup;
+ /** EventExecutor Group (if used) */
+ private final EventExecutorGroup executionGroup;
+ /** Name of the handler to use execution group for (if used) */
+ private final String handlerToUseExecutionGroup;
/** When was the last time we checked if we should resend some requests */
private final AtomicLong lastTimeCheckedRequestsForProblems =
new AtomicLong(0);
@@ -218,99 +220,110 @@ public class NettyClient {
clientRequestIdRequestInfoMap =
new MapMaker().concurrencyLevel(maxPoolSize).makeMap();
- handlerBeforeExecutionHandler =
+ handlerToUseExecutionGroup =
NETTY_CLIENT_EXECUTION_AFTER_HANDLER.get(conf);
- useExecutionHandler = NETTY_CLIENT_USE_EXECUTION_HANDLER.get(conf);
- if (useExecutionHandler) {
+ useExecutionGroup = NETTY_CLIENT_USE_EXECUTION_HANDLER.get(conf);
+ if (useExecutionGroup) {
int executionThreads = NETTY_CLIENT_EXECUTION_THREADS.get(conf);
- executionHandler = new ExecutionHandler(
- new MemoryAwareThreadPoolExecutor(
- executionThreads, 1048576, 1048576, 1, TimeUnit.HOURS,
- new ThreadFactoryBuilder().setNameFormat("netty-client-exec-%d")
- .build()));
+ executionGroup = new DefaultEventExecutorGroup(executionThreads,
+ new ThreadFactoryBuilder().setNameFormat("netty-client-exec-%d")
+ .build());
if (LOG.isInfoEnabled()) {
LOG.info("NettyClient: Using execution handler with " +
executionThreads + " threads after " +
- handlerBeforeExecutionHandler + ".");
+ handlerToUseExecutionGroup + ".");
}
} else {
- executionHandler = null;
+ executionGroup = null;
}
- bossExecutorService = Executors.newCachedThreadPool(
- new ThreadFactoryBuilder().setNameFormat(
- "netty-client-boss-%d").build());
- workerExecutorService = Executors.newCachedThreadPool(
+ workerGroup = new NioEventLoopGroup(maxPoolSize,
new ThreadFactoryBuilder().setNameFormat(
"netty-client-worker-%d").build());
- // Configure the client.
- bootstrap = new ClientBootstrap(
- new NioClientSocketChannelFactory(
- bossExecutorService,
- workerExecutorService,
- maxPoolSize));
- bootstrap.setOption("connectTimeoutMillis",
- MAX_CONNECTION_MILLISECONDS_DEFAULT);
- bootstrap.setOption("tcpNoDelay", true);
- bootstrap.setOption("keepAlive", true);
- bootstrap.setOption("sendBufferSize", sendBufferSize);
- bootstrap.setOption("receiveBufferSize", receiveBufferSize);
-
- // Set up the pipeline factory.
- bootstrap.setPipelineFactory(new ChannelPipelineFactory() {
- @Override
- public ChannelPipeline getPipeline() throws Exception {
-/*if_not[HADOOP_NON_SECURE]*/
- if (conf.authenticate()) {
- LOG.info("Using Netty with authentication.");
-
- // Our pipeline starts with just byteCounter, and then we use
- // addLast() to incrementally add pipeline elements, so that we can
- // name them for identification for removal or replacement after
- // client is authenticated by server.
- // After authentication is complete, the pipeline's SASL-specific
- // functionality is removed, restoring the pipeline to exactly the
- // same configuration as it would be without authentication.
- ChannelPipeline pipeline = Channels.pipeline(
- byteCounter);
- // The following pipeline component is needed to decode the server's
- // SASL tokens. It is replaced with a FixedLengthFrameDecoder (same
- // as used with the non-authenticated pipeline) after authentication
- // completes (as in non-auth pipeline below).
- pipeline.addLast("length-field-based-frame-decoder",
- new LengthFieldBasedFrameDecoder(1024, 0, 4, 0, 4));
- pipeline.addLast("request-encoder", new RequestEncoder(conf));
- // The following pipeline component responds to the server's SASL
- // tokens with its own responses. Both client and server share the
- // same Hadoop Job token, which is used to create the SASL tokens to
- // authenticate with each other.
- // After authentication finishes, this pipeline component is removed.
- pipeline.addLast("sasl-client-handler",
- new SaslClientHandler(conf));
- pipeline.addLast("response-handler",
- new ResponseClientHandler(clientRequestIdRequestInfoMap, conf));
- return pipeline;
- } else {
- LOG.info("Using Netty without authentication.");
+ bootstrap = new Bootstrap();
+ bootstrap.group(workerGroup)
+ .channel(NioSocketChannel.class)
+ .option(ChannelOption.CONNECT_TIMEOUT_MILLIS,
+ MAX_CONNECTION_MILLISECONDS_DEFAULT)
+ .option(ChannelOption.TCP_NODELAY, true)
+ .option(ChannelOption.SO_KEEPALIVE, true)
+ .option(ChannelOption.SO_SNDBUF, sendBufferSize)
+ .option(ChannelOption.SO_RCVBUF, receiveBufferSize)
+ .option(ChannelOption.ALLOCATOR, conf.getNettyAllocator())
+ .handler(new ChannelInitializer<SocketChannel>() {
+ @Override
+ protected void initChannel(SocketChannel ch) throws Exception {
+ /*if_not[HADOOP_NON_SECURE]*/
+ if (conf.authenticate()) {
+ LOG.info("Using Netty with authentication.");
+
+ // Our pipeline starts with just byteCounter, and then we use
+ // addLast() to incrementally add pipeline elements, so that we
+ // can name them for identification for removal or replacement
+ // after client is authenticated by server.
+ // After authentication is complete, the pipeline's SASL-specific
+ // functionality is removed, restoring the pipeline to exactly the
+ // same configuration as it would be without authentication.
+ PipelineUtils.addLastWithExecutorCheck("clientInboundByteCounter",
+ inboundByteCounter, handlerToUseExecutionGroup,
+ executionGroup, ch);
+ PipelineUtils.addLastWithExecutorCheck(
+ "clientOutboundByteCounter",
+ outboundByteCounter, handlerToUseExecutionGroup,
+ executionGroup, ch);
+
+ // The following pipeline component is needed to decode the
+ // server's SASL tokens. It is replaced with a
+ // FixedLengthFrameDecoder (same as used with the
+ // non-authenticated pipeline) after authentication
+ // completes (as in non-auth pipeline below).
+ PipelineUtils.addLastWithExecutorCheck(
+ "length-field-based-frame-decoder",
+ new LengthFieldBasedFrameDecoder(1024, 0, 4, 0, 4),
+ handlerToUseExecutionGroup, executionGroup, ch);
+ PipelineUtils.addLastWithExecutorCheck("request-encoder",
+ new RequestEncoder(conf), handlerToUseExecutionGroup,
+ executionGroup, ch);
+ // The following pipeline component responds to the server's SASL
+ // tokens with its own responses. Both client and server share the
+ // same Hadoop Job token, which is used to create the SASL
+ // tokens to authenticate with each other.
+ // After authentication finishes, this pipeline component
+ // is removed.
+ PipelineUtils.addLastWithExecutorCheck("sasl-client-handler",
+ new SaslClientHandler(conf), handlerToUseExecutionGroup,
+ executionGroup, ch);
+ PipelineUtils.addLastWithExecutorCheck("response-handler",
+ new ResponseClientHandler(clientRequestIdRequestInfoMap,
+ conf), handlerToUseExecutionGroup, executionGroup, ch);
+ } else {
+ LOG.info("Using Netty without authentication.");
/*end[HADOOP_NON_SECURE]*/
- ChannelPipeline pipeline = pipeline();
- pipeline.addLast("clientByteCounter", byteCounter);
- pipeline.addLast("responseFrameDecoder",
- new FixedLengthFrameDecoder(RequestServerHandler.RESPONSE_BYTES));
- pipeline.addLast("requestEncoder", new RequestEncoder(conf));
- pipeline.addLast("responseClientHandler",
- new ResponseClientHandler(clientRequestIdRequestInfoMap, conf));
- if (executionHandler != null) {
- pipeline.addAfter(handlerBeforeExecutionHandler,
- "executionHandler", executionHandler);
- }
- return pipeline;
+ PipelineUtils.addLastWithExecutorCheck("clientInboundByteCounter",
+ inboundByteCounter, handlerToUseExecutionGroup,
+ executionGroup, ch);
+ PipelineUtils.addLastWithExecutorCheck(
+ "clientOutboundByteCounter",
+ outboundByteCounter, handlerToUseExecutionGroup,
+ executionGroup, ch);
+ PipelineUtils.addLastWithExecutorCheck(
+ "fixed-length-frame-decoder",
+ new FixedLengthFrameDecoder(
+ RequestServerHandler.RESPONSE_BYTES),
+ handlerToUseExecutionGroup, executionGroup, ch);
+ PipelineUtils.addLastWithExecutorCheck("request-encoder",
+ new RequestEncoder(conf), handlerToUseExecutionGroup,
+ executionGroup, ch);
+ PipelineUtils.addLastWithExecutorCheck("response-handler",
+ new ResponseClientHandler(clientRequestIdRequestInfoMap,
+ conf), handlerToUseExecutionGroup, executionGroup, ch);
+
/*if_not[HADOOP_NON_SECURE]*/
- }
+ }
/*end[HADOOP_NON_SECURE]*/
- }
- });
+ }
+ });
}
/**
@@ -399,7 +412,7 @@ public class NettyClient {
if (!future.isSuccess()) {
LOG.warn("connectAllAddresses: Future failed " +
"to connect with " + waitingConnection.address + " with " +
- failures + " failures because of " + future.getCause());
+ failures + " failures because of " + future.cause());
ChannelFuture connectionFuture =
bootstrap.connect(waitingConnection.address);
@@ -407,13 +420,13 @@ public class NettyClient {
waitingConnection.address, waitingConnection.taskId));
++failures;
} else {
- Channel channel = future.getChannel();
+ Channel channel = future.channel();
if (LOG.isDebugEnabled()) {
LOG.debug("connectAllAddresses: Connected to " +
- channel.getRemoteAddress() + ", open = " + channel.isOpen());
+ channel.remoteAddress() + ", open = " + channel.isOpen());
}
- if (channel.getRemoteAddress() == null) {
+ if (channel.remoteAddress() == null) {
throw new IllegalStateException(
"connectAllAddresses: Null remote address!");
}
@@ -429,7 +442,7 @@ public class NettyClient {
rotater = newRotater;
}
}
- rotater.addChannel(future.getChannel());
+ rotater.addChannel(future.channel());
++connected;
}
}
@@ -485,14 +498,14 @@ public class NettyClient {
*/
private void authenticateOnChannel(Integer taskId, Channel channel) {
try {
- SaslNettyClient saslNettyClient = SASL.get(channel);
- if (SASL.get(channel) == null) {
+ SaslNettyClient saslNettyClient = channel.attr(SASL).get();
+ if (channel.attr(SASL).get() == null) {
if (LOG.isDebugEnabled()) {
LOG.debug("authenticateOnChannel: Creating saslNettyClient now " +
"for channel: " + channel);
}
saslNettyClient = new SaslNettyClient();
- SASL.set(channel, saslNettyClient);
+ channel.attr(SASL).set(saslNettyClient);
}
if (!saslNettyClient.isComplete()) {
if (LOG.isDebugEnabled()) {
@@ -550,11 +563,11 @@ public class NettyClient {
done + " connections closed, releasing " +
"NettyClient.bootstrap resources now.");
}
- bossExecutorService.shutdownNow();
- workerExecutorService.shutdownNow();
- bootstrap.releaseExternalResources();
- if (useExecutionHandler) {
- executionHandler.releaseExternalResources();
+ workerGroup.shutdownGracefully();
+ ProgressableUtils.awaitTerminationFuture(executionGroup, context);
+ if (executionGroup != null) {
+ executionGroup.shutdownGracefully();
+ ProgressableUtils.awaitTerminationFuture(executionGroup, context);
}
}
}
@@ -576,7 +589,7 @@ public class NettyClient {
}
// Return this channel if it is connected
- if (channel.isConnected()) {
+ if (channel.isActive()) {
return channel;
}
@@ -588,7 +601,7 @@ public class NettyClient {
if (LOG.isInfoEnabled()) {
LOG.info("getNextChannel: Fixing disconnected channel to " +
remoteServer + ", open = " + channel.isOpen() + ", " +
- "bound = " + channel.isBound());
+ "bound = " + channel.isRegistered());
}
int reconnectFailures = 0;
while (reconnectFailures < maxConnectionFailures) {
@@ -599,14 +612,14 @@ public class NettyClient {
LOG.info("getNextChannel: Connected to " + remoteServer + "!");
}
addressChannelMap.get(remoteServer).addChannel(
- connectionFuture.getChannel());
- return connectionFuture.getChannel();
+ connectionFuture.channel());
+ return connectionFuture.channel();
}
++reconnectFailures;
LOG.warn("getNextChannel: Failed to reconnect to " + remoteServer +
" on attempt " + reconnectFailures + " out of " +
maxConnectionFailures + " max attempts, sleeping for 5 secs",
- connectionFuture.getCause());
+ connectionFuture.cause());
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
@@ -628,7 +641,8 @@ public class NettyClient {
WritableRequest request) {
InetSocketAddress remoteServer = taskIdAddressMap.get(destTaskId);
if (clientRequestIdRequestInfoMap.isEmpty()) {
- byteCounter.resetAll();
+ inboundByteCounter.resetAll();
+ outboundByteCounter.resetAll();
}
boolean registerRequest = true;
/*if_not[HADOOP_NON_SECURE]*/
@@ -671,7 +685,8 @@ public class NettyClient {
waitSomeRequests(0);
if (LOG.isInfoEnabled()) {
LOG.info("waitAllRequests: Finished all requests. " +
- byteCounter.getMetrics());
+ inboundByteCounter.getMetrics() + "\n" + outboundByteCounter
+ .getMetrics());
}
}
@@ -715,7 +730,8 @@ public class NettyClient {
waitingRequestMsecs + " msecs, " +
clientRequestIdRequestInfoMap.size() +
" open requests, waiting for it to be <= " + maxOpenRequests +
- ", " + byteCounter.getMetrics());
+ ", " + inboundByteCounter.getMetrics() + "\n" +
+ outboundByteCounter.getMetrics());
if (clientRequestIdRequestInfoMap.size() < MAX_REQUESTS_TO_LIST) {
for (Map.Entry<ClientRequestId, RequestInfo> entry :
@@ -789,17 +805,17 @@ public class NettyClient {
}
// If not connected anymore, request failed, or the request is taking
// too long, re-establish and resend
- if (!writeFuture.getChannel().isConnected() ||
+ if (!writeFuture.channel().isActive() ||
(writeFuture.isDone() && !writeFuture.isSuccess()) ||
(requestInfo.getElapsedMsecs() > maxRequestMilliseconds)) {
LOG.warn("checkRequestsForProblems: Problem with request id " +
entry.getKey() + " connected = " +
- writeFuture.getChannel().isConnected() +
+ writeFuture.channel().isActive() +
", future done = " + writeFuture.isDone() + ", " +
"success = " + writeFuture.isSuccess() + ", " +
- "cause = " + writeFuture.getCause() + ", " +
+ "cause = " + writeFuture.cause() + ", " +
"elapsed time = " + requestInfo.getElapsedMsecs() + ", " +
- "destination = " + writeFuture.getChannel().getRemoteAddress() +
+ "destination = " + writeFuture.channel().remoteAddress() +
" " + requestInfo);
addedRequestIds.add(entry.getKey());
addedRequestInfos.add(new RequestInfo(
http://git-wip-us.apache.org/repos/asf/giraph/blob/62f9fd3f/giraph-core/src/main/java/org/apache/giraph/comm/netty/NettyServer.java
----------------------------------------------------------------------
diff --git a/giraph-core/src/main/java/org/apache/giraph/comm/netty/NettyServer.java b/giraph-core/src/main/java/org/apache/giraph/comm/netty/NettyServer.java
index 9d4afa9..14d4ea8 100644
--- a/giraph-core/src/main/java/org/apache/giraph/comm/netty/NettyServer.java
+++ b/giraph-core/src/main/java/org/apache/giraph/comm/netty/NettyServer.java
@@ -31,37 +31,35 @@ import org.apache.giraph.comm.netty.handler.WorkerRequestReservedMap;
import org.apache.giraph.conf.GiraphConstants;
import org.apache.giraph.conf.ImmutableClassesGiraphConfiguration;
import org.apache.giraph.graph.TaskInfo;
+import org.apache.giraph.utils.PipelineUtils;
import org.apache.giraph.utils.ProgressableUtils;
import org.apache.hadoop.util.Progressable;
import org.apache.log4j.Logger;
-import org.jboss.netty.bootstrap.ServerBootstrap;
-import org.jboss.netty.channel.Channel;
-import org.jboss.netty.channel.ChannelException;
-import org.jboss.netty.channel.ChannelFactory;
-import org.jboss.netty.channel.ChannelHandlerContext;
-import org.jboss.netty.channel.ChannelLocal;
-import org.jboss.netty.channel.ChannelPipeline;
-import org.jboss.netty.channel.ChannelPipelineFactory;
-import org.jboss.netty.channel.ChannelStateEvent;
-import org.jboss.netty.channel.Channels;
-import org.jboss.netty.channel.SimpleChannelUpstreamHandler;
-import org.jboss.netty.channel.group.ChannelGroup;
-import org.jboss.netty.channel.group.DefaultChannelGroup;
-import org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory;
-import org.jboss.netty.handler.codec.frame.LengthFieldBasedFrameDecoder;
-import org.jboss.netty.handler.execution.ExecutionHandler;
-import org.jboss.netty.handler.execution.MemoryAwareThreadPoolExecutor;
+import io.netty.bootstrap.ServerBootstrap;
+import io.netty.channel.group.ChannelGroup;
+import io.netty.channel.group.DefaultChannelGroup;
+import io.netty.channel.nio.NioEventLoopGroup;
+import io.netty.channel.socket.SocketChannel;
+import io.netty.channel.ChannelHandlerContext;
+import io.netty.channel.EventLoopGroup;
+import io.netty.channel.ChannelOption;
+import io.netty.channel.ChannelInitializer;
+import io.netty.channel.ChannelInboundHandlerAdapter;
+import io.netty.channel.ChannelFuture;
+import io.netty.channel.socket.nio.NioServerSocketChannel;
+import io.netty.handler.codec.LengthFieldBasedFrameDecoder;
+import io.netty.util.AttributeKey;
+import io.netty.util.concurrent.DefaultEventExecutorGroup;
+import io.netty.util.concurrent.EventExecutorGroup;
+import io.netty.util.concurrent.ImmediateEventExecutor;
+import io.netty.channel.AdaptiveRecvByteBufAllocator;
import com.google.common.util.concurrent.ThreadFactoryBuilder;
import java.net.InetSocketAddress;
import java.net.UnknownHostException;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
-import java.util.concurrent.TimeUnit;
import static org.apache.giraph.conf.GiraphConstants.MAX_IPC_PORT_BIND_ATTEMPTS;
-import static org.jboss.netty.channel.Channels.pipeline;
/**
* This server uses Netty and will implement all Giraph communication
@@ -73,9 +71,8 @@ public class NettyServer {
/*if_not[HADOOP_NON_SECURE]*/
/** Used to authenticate with netty clients */
- public static final ChannelLocal<SaslNettyServer>
- CHANNEL_SASL_NETTY_SERVERS =
- new ChannelLocal<SaslNettyServer>();
+ public static final AttributeKey<SaslNettyServer>
+ CHANNEL_SASL_NETTY_SERVERS = AttributeKey.valueOf("channelSaslServers");
/*end[HADOOP_NON_SECURE]*/
/** Class logger */
@@ -84,10 +81,9 @@ public class NettyServer {
private final ImmutableClassesGiraphConfiguration conf;
/** Progressable for reporting progress */
private final Progressable progressable;
- /** Factory of channels */
- private ChannelFactory channelFactory;
/** Accepted channels */
- private final ChannelGroup accepted = new DefaultChannelGroup();
+ private final ChannelGroup accepted = new DefaultChannelGroup(
+ ImmediateEventExecutor.INSTANCE);
/** Local hostname */
private final String localHostname;
/** Address of the server */
@@ -106,24 +102,26 @@ public class NettyServer {
/*end[HADOOP_NON_SECURE]*/
/** Server bootstrap */
private ServerBootstrap bootstrap;
- /** Byte counter for this client */
- private final ByteCounter byteCounter = new ByteCounter();
+ /** Inbound byte counter for this client */
+ private final InboundByteCounter inByteCounter = new InboundByteCounter();
+ /** Outbound byte counter for this client */
+ private final OutboundByteCounter outByteCounter = new OutboundByteCounter();
/** Send buffer size */
private final int sendBufferSize;
/** Receive buffer size */
private final int receiveBufferSize;
- /** Boss factory service */
- private final ExecutorService bossExecutorService;
- /** Worker factory service */
- private final ExecutorService workerExecutorService;
+ /** Boss eventloop group */
+ private final EventLoopGroup bossGroup;
+ /** Worker eventloop group */
+ private final EventLoopGroup workerGroup;
/** Request completed map per worker */
private final WorkerRequestReservedMap workerRequestReservedMap;
- /** Use execution handler? */
- private final boolean useExecutionHandler;
+ /** Use execution group? */
+ private final boolean useExecutionGroup;
/** Execution handler (if used) */
- private final ExecutionHandler executionHandler;
+ private final EventExecutorGroup executionGroup;
/** Name of the handler before the execution handler (if used) */
- private final String handlerBeforeExecutionHandler;
+ private final String handlerToUseExecutionGroup;
/**
* Constructor for creating the server
@@ -148,12 +146,15 @@ public class NettyServer {
workerRequestReservedMap = new WorkerRequestReservedMap(conf);
- bossExecutorService = Executors.newCachedThreadPool(
+ maxPoolSize = GiraphConstants.NETTY_SERVER_THREADS.get(conf);
+
+ bossGroup = new NioEventLoopGroup(4,
new ThreadFactoryBuilder().setNameFormat(
- "netty-server-boss-%d").build());
- workerExecutorService = Executors.newCachedThreadPool(
+ "netty-server-boss-%d").build());
+
+ workerGroup = new NioEventLoopGroup(maxPoolSize,
new ThreadFactoryBuilder().setNameFormat(
- "netty-server-worker-%d").build());
+ "netty-server-worker-%d").build());
try {
this.localHostname = conf.getLocalHostname();
@@ -161,35 +162,26 @@ public class NettyServer {
throw new IllegalStateException("NettyServer: unable to get hostname");
}
- maxPoolSize = GiraphConstants.NETTY_SERVER_THREADS.get(conf);
-
tcpBacklog = conf.getInt(GiraphConstants.TCP_BACKLOG.getKey(),
conf.getInt(GiraphConstants.MAX_WORKERS,
GiraphConstants.TCP_BACKLOG.getDefaultValue()));
- channelFactory = new NioServerSocketChannelFactory(
- bossExecutorService,
- workerExecutorService,
- maxPoolSize);
-
- handlerBeforeExecutionHandler =
+ handlerToUseExecutionGroup =
GiraphConstants.NETTY_SERVER_EXECUTION_AFTER_HANDLER.get(conf);
- useExecutionHandler =
+ useExecutionGroup =
GiraphConstants.NETTY_SERVER_USE_EXECUTION_HANDLER.get(conf);
- if (useExecutionHandler) {
+ if (useExecutionGroup) {
int executionThreads = conf.getNettyServerExecutionThreads();
- executionHandler = new ExecutionHandler(
- new MemoryAwareThreadPoolExecutor(
- executionThreads, 1048576, 1048576, 1, TimeUnit.HOURS,
- new ThreadFactoryBuilder().setNameFormat("netty-server-exec-%d").
- build()));
+ executionGroup = new DefaultEventExecutorGroup(executionThreads,
+ new ThreadFactoryBuilder().setNameFormat("netty-server-exec-%d").
+ build());
if (LOG.isInfoEnabled()) {
- LOG.info("NettyServer: Using execution handler with " +
- executionThreads + " threads after " +
- handlerBeforeExecutionHandler + ".");
+ LOG.info("NettyServer: Using execution group with " +
+ executionThreads + " threads for " +
+ handlerToUseExecutionGroup + ".");
}
} else {
- executionHandler = null;
+ executionGroup = null;
}
}
@@ -217,26 +209,27 @@ public class NettyServer {
* Start the server with the appropriate port
*/
public void start() {
- bootstrap = new ServerBootstrap(channelFactory);
- // Set up the pipeline factory.
- bootstrap.setOption("child.keepAlive", true);
- bootstrap.setOption("child.tcpNoDelay", true);
- bootstrap.setOption("child.sendBufferSize", sendBufferSize);
- bootstrap.setOption("child.receiveBufferSize", receiveBufferSize);
- bootstrap.setOption("backlog", tcpBacklog);
- bootstrap.setOption("child.receiveBufferSizePredictorFactory",
- new WrappedAdaptiveReceiveBufferSizePredictorFactory(
- receiveBufferSize / 4,
- receiveBufferSize,
- receiveBufferSize));
+ bootstrap = new ServerBootstrap();
+ bootstrap.group(bossGroup, workerGroup)
+ .channel(NioServerSocketChannel.class)
+ .option(ChannelOption.SO_BACKLOG, tcpBacklog)
+ .option(ChannelOption.ALLOCATOR, conf.getNettyAllocator())
+ .childOption(ChannelOption.SO_KEEPALIVE, true)
+ .childOption(ChannelOption.TCP_NODELAY, true)
+ .childOption(ChannelOption.SO_SNDBUF, sendBufferSize)
+ .childOption(ChannelOption.SO_RCVBUF, receiveBufferSize)
+ .childOption(ChannelOption.ALLOCATOR, conf.getNettyAllocator())
+ .childOption(ChannelOption.RCVBUF_ALLOCATOR,
+ new AdaptiveRecvByteBufAllocator(receiveBufferSize / 4,
+ receiveBufferSize, receiveBufferSize));
/**
* Pipeline setup: depends on whether configured to use authentication
* or not.
*/
- bootstrap.setPipelineFactory(new ChannelPipelineFactory() {
+ bootstrap.childHandler(new ChannelInitializer<SocketChannel>() {
@Override
- public ChannelPipeline getPipeline() throws Exception {
+ protected void initChannel(SocketChannel ch) throws Exception {
/*if_not[HADOOP_NON_SECURE]*/
if (conf.authenticate()) {
LOG.info("start: Will use Netty pipeline with " +
@@ -245,48 +238,60 @@ public class NettyServer {
// pipeline components SaslServerHandler and ResponseEncoder are
// removed, leaving the pipeline the same as in the non-authenticated
// configuration except for the presence of the Authorize component.
- return Channels.pipeline(
- byteCounter,
+ PipelineUtils.addLastWithExecutorCheck("serverInboundByteCounter",
+ inByteCounter, handlerToUseExecutionGroup, executionGroup, ch);
+ PipelineUtils.addLastWithExecutorCheck("serverOutboundByteCounter",
+ outByteCounter, handlerToUseExecutionGroup, executionGroup, ch);
+ PipelineUtils.addLastWithExecutorCheck("requestFrameDecoder",
new LengthFieldBasedFrameDecoder(1024 * 1024 * 1024, 0, 4, 0, 4),
- new RequestDecoder(conf, byteCounter),
- // Removed after authentication completes:
+ handlerToUseExecutionGroup, executionGroup, ch);
+ PipelineUtils.addLastWithExecutorCheck("requestDecoder",
+ new RequestDecoder(conf, inByteCounter),
+ handlerToUseExecutionGroup, executionGroup, ch);
+ // Removed after authentication completes:
+ PipelineUtils.addLastWithExecutorCheck("saslServerHandler",
saslServerHandlerFactory.newHandler(conf),
- new AuthorizeServerHandler(),
+ handlerToUseExecutionGroup, executionGroup, ch);
+ PipelineUtils.addLastWithExecutorCheck("authorizeServerHandler",
+ new AuthorizeServerHandler(), handlerToUseExecutionGroup,
+ executionGroup, ch);
+ PipelineUtils.addLastWithExecutorCheck("requestServerHandler",
requestServerHandlerFactory.newHandler(workerRequestReservedMap,
- conf, myTaskInfo),
- // Removed after authentication completes:
- new ResponseEncoder());
+ conf, myTaskInfo), handlerToUseExecutionGroup,
+ executionGroup, ch);
+ // Removed after authentication completes:
+ PipelineUtils.addLastWithExecutorCheck("responseEncoder",
+ new ResponseEncoder(), handlerToUseExecutionGroup,
+ executionGroup, ch);
} else {
LOG.info("start: Using Netty without authentication.");
/*end[HADOOP_NON_SECURE]*/
- ChannelPipeline pipeline = pipeline();
-
// Store all connected channels in order to ensure that we can close
// them on stop(), or else stop() may hang waiting for the
// connections to close on their own
- pipeline.addLast("connectedChannels",
- new SimpleChannelUpstreamHandler() {
+ ch.pipeline().addLast("connectedChannels",
+ new ChannelInboundHandlerAdapter() {
@Override
- public void channelConnected(ChannelHandlerContext ctx,
- ChannelStateEvent e) throws Exception {
- super.channelConnected(ctx, e);
- accepted.add(e.getChannel());
+ public void channelActive(ChannelHandlerContext ctx)
+ throws Exception {
+ accepted.add(ctx.channel());
+ ctx.fireChannelActive();
}
});
- pipeline.addLast("serverByteCounter", byteCounter);
- pipeline.addLast("requestFrameDecoder",
- new LengthFieldBasedFrameDecoder(
- 1024 * 1024 * 1024, 0, 4, 0, 4));
- pipeline.addLast("requestDecoder",
- new RequestDecoder(conf, byteCounter));
- pipeline.addLast("requestProcessor",
+ PipelineUtils.addLastWithExecutorCheck("serverInboundByteCounter",
+ inByteCounter, handlerToUseExecutionGroup, executionGroup, ch);
+ PipelineUtils.addLastWithExecutorCheck("serverOutboundByteCounter",
+ outByteCounter, handlerToUseExecutionGroup, executionGroup, ch);
+ PipelineUtils.addLastWithExecutorCheck("requestFrameDecoder",
+ new LengthFieldBasedFrameDecoder(1024 * 1024 * 1024, 0, 4, 0, 4),
+ handlerToUseExecutionGroup, executionGroup, ch);
+ PipelineUtils.addLastWithExecutorCheck("requestDecoder",
+ new RequestDecoder(conf, inByteCounter),
+ handlerToUseExecutionGroup, executionGroup, ch);
+ PipelineUtils.addLastWithExecutorCheck("requestServerHandler",
requestServerHandlerFactory.newHandler(
- workerRequestReservedMap, conf, myTaskInfo));
- if (executionHandler != null) {
- pipeline.addAfter(handlerBeforeExecutionHandler,
- "executionHandler", executionHandler);
- }
- return pipeline;
+ workerRequestReservedMap, conf, myTaskInfo),
+ handlerToUseExecutionGroup, executionGroup, ch);
/*if_not[HADOOP_NON_SECURE]*/
}
/*end[HADOOP_NON_SECURE]*/
@@ -323,13 +328,16 @@ public class NettyServer {
}
try {
- Channel ch = bootstrap.bind(myAddress);
- accepted.add(ch);
-
+ ChannelFuture f = bootstrap.bind(myAddress).sync();
+ accepted.add(f.channel());
break;
- } catch (ChannelException e) {
+ } catch (InterruptedException e) {
+ throw new IllegalStateException(e);
+ // CHECKSTYLE: stop IllegalCatchCheck
+ } catch (Exception e) {
+ // CHECKSTYLE: resume IllegalCatchCheck
LOG.warn("start: Likely failed to bind on attempt " +
- bindAttempts + " to port " + bindPort, e);
+ bindAttempts + " to port " + bindPort, e.getCause());
++bindAttempts;
bindPort += portIncrementConstant;
}
@@ -345,8 +353,7 @@ public class NettyServer {
"communication server: " + myAddress + " with up to " +
maxPoolSize + " threads on bind attempt " + bindAttempts +
" with sendBufferSize = " + sendBufferSize +
- " receiveBufferSize = " + receiveBufferSize + " backlog = " +
- bootstrap.getOption("backlog"));
+ " receiveBufferSize = " + receiveBufferSize);
}
}
@@ -358,19 +365,16 @@ public class NettyServer {
LOG.info("stop: Halting netty server");
}
ProgressableUtils.awaitChannelGroupFuture(accepted.close(), progressable);
- bossExecutorService.shutdownNow();
- ProgressableUtils.awaitExecutorTermination(bossExecutorService,
- progressable);
- workerExecutorService.shutdownNow();
- ProgressableUtils.awaitExecutorTermination(workerExecutorService,
- progressable);
if (LOG.isInfoEnabled()) {
LOG.info("stop: Start releasing resources");
}
- bootstrap.releaseExternalResources();
- channelFactory.releaseExternalResources();
- if (useExecutionHandler) {
- executionHandler.releaseExternalResources();
+ bossGroup.shutdownGracefully();
+ workerGroup.shutdownGracefully();
+ ProgressableUtils.awaitTerminationFuture(bossGroup, progressable);
+ ProgressableUtils.awaitTerminationFuture(workerGroup, progressable);
+ if (useExecutionGroup) {
+ executionGroup.shutdownGracefully();
+ ProgressableUtils.awaitTerminationFuture(executionGroup, progressable);
}
if (LOG.isInfoEnabled()) {
LOG.info("stop: Netty server halted");
http://git-wip-us.apache.org/repos/asf/giraph/blob/62f9fd3f/giraph-core/src/main/java/org/apache/giraph/comm/netty/OutboundByteCounter.java
----------------------------------------------------------------------
diff --git a/giraph-core/src/main/java/org/apache/giraph/comm/netty/OutboundByteCounter.java b/giraph-core/src/main/java/org/apache/giraph/comm/netty/OutboundByteCounter.java
new file mode 100644
index 0000000..c4027be
--- /dev/null
+++ b/giraph-core/src/main/java/org/apache/giraph/comm/netty/OutboundByteCounter.java
@@ -0,0 +1,97 @@
+/*
+ * 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.giraph.comm.netty;
+
+import org.apache.giraph.metrics.GiraphMetrics;
+import org.apache.giraph.metrics.ResetSuperstepMetricsObserver;
+import org.apache.giraph.metrics.SuperstepMetricsRegistry;
+import org.apache.log4j.Logger;
+
+import io.netty.buffer.ByteBuf;
+import io.netty.channel.ChannelHandlerContext;
+import io.netty.channel.ChannelOutboundHandlerAdapter;
+import io.netty.channel.ChannelPromise;
+import io.netty.channel.ChannelHandler.Sharable;
+
+/**
+ * Keep track of the bytes sent and provide some metrics when
+ * desired as part of the Netty Channel stack.
+ */
+@Sharable
+public class OutboundByteCounter extends ChannelOutboundHandlerAdapter
+ implements ByteCounter, ResetSuperstepMetricsObserver {
+ /** Class logger */
+ private static final Logger LOG =
+ Logger.getLogger(OutboundByteCounter.class);
+ /** ByteCounter delegate object */
+ private final ByteCounterDelegate delegate = new ByteCounterDelegate(false);
+
+ /** Constructor */
+ public OutboundByteCounter() {
+ // Initialize Metrics
+ GiraphMetrics.get().addSuperstepResetObserver(this);
+ }
+
+ public long getBytesSent() {
+ return delegate.getBytesProcessed();
+ }
+
+ /**
+ * @return Mbytes sent / sec in the current interval
+ */
+ public double getMbytesPerSecSent() {
+ return delegate.getMbytesPerSecProcessed();
+ }
+
+ @Override
+ public void write(ChannelHandlerContext ctx, Object msg,
+ ChannelPromise promise) throws Exception {
+ if (msg instanceof ByteBuf) {
+ ByteBuf buf = (ByteBuf) msg;
+ int sentBytes = delegate.byteBookkeeper(buf);
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("write: " + ctx.channel().toString() +
+ " buffer size = " + sentBytes + ", total bytes = " + getBytesSent()
+ );
+ }
+ }
+ ctx.writeAndFlush(msg, promise);
+ }
+
+ @Override
+ public void newSuperstep(SuperstepMetricsRegistry superstepMetrics) {
+ delegate.newSuperstep(superstepMetrics);
+ }
+
+ @Override
+ public void resetAll() {
+ delegate.resetAll();
+ }
+
+ @Override
+ public String getMetrics() {
+ return delegate.getMetrics();
+ }
+
+ @Override
+ public String getMetricsWindow(int minMsecsWindow) {
+ return delegate.getMetricsWindow(minMsecsWindow);
+ }
+}
+
http://git-wip-us.apache.org/repos/asf/giraph/blob/62f9fd3f/giraph-core/src/main/java/org/apache/giraph/comm/netty/WrappedAdaptiveReceiveBufferSizePredictorFactory.java
----------------------------------------------------------------------
diff --git a/giraph-core/src/main/java/org/apache/giraph/comm/netty/WrappedAdaptiveReceiveBufferSizePredictorFactory.java b/giraph-core/src/main/java/org/apache/giraph/comm/netty/WrappedAdaptiveReceiveBufferSizePredictorFactory.java
deleted file mode 100644
index be92dde..0000000
--- a/giraph-core/src/main/java/org/apache/giraph/comm/netty/WrappedAdaptiveReceiveBufferSizePredictorFactory.java
+++ /dev/null
@@ -1,133 +0,0 @@
-/*
- * 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.giraph.comm.netty;
-
-import org.apache.log4j.Logger;
-import org.jboss.netty.channel.AdaptiveReceiveBufferSizePredictor;
-import org.jboss.netty.channel.ReceiveBufferSizePredictor;
-import org.jboss.netty.channel.ReceiveBufferSizePredictorFactory;
-
-/**
- * Uses composition to learn more about what
- * AdaptiveReceiveBufferSizePredictor has determined what the actual
- * sizes are.
- */
-public class WrappedAdaptiveReceiveBufferSizePredictorFactory implements
- ReceiveBufferSizePredictorFactory {
- /** Internal predictor */
- private final ReceiveBufferSizePredictor receiveBufferSizePredictor;
-
- /**
- * Constructor with defaults.
- */
- public WrappedAdaptiveReceiveBufferSizePredictorFactory() {
- receiveBufferSizePredictor =
- new WrappedAdaptiveReceiveBufferSizePredictor();
- }
-
- /**
- * Creates a new predictor with the specified parameters.
- *
- * @param minimum The inclusive lower bound of the expected buffer size
- * @param initial The initial buffer size when no feed back was received
- * @param maximum The inclusive upper bound of the expected buffer size
- */
- public WrappedAdaptiveReceiveBufferSizePredictorFactory(int minimum,
- int initial,
- int maximum) {
- receiveBufferSizePredictor = new WrappedAdaptiveReceiveBufferSizePredictor(
- minimum, initial, maximum);
- }
-
- @Override
- public ReceiveBufferSizePredictor getPredictor() throws Exception {
- return receiveBufferSizePredictor;
- }
-
- /**
- * Uses composition to expose
- * details of AdaptiveReceiveBufferSizePredictor.
- */
- private static class WrappedAdaptiveReceiveBufferSizePredictor implements
- ReceiveBufferSizePredictor {
- /** Class logger */
- private static final Logger LOG = Logger.getLogger(
- WrappedAdaptiveReceiveBufferSizePredictor.class);
- /** Internally delegated predictor */
- private final AdaptiveReceiveBufferSizePredictor
- adaptiveReceiveBufferSizePredictor;
- /** Number of calls to nextReceiveBufferSize() */
- private long nextReceiveBufferSizeCount = 0;
- /** Number of calls to previousReceiveBufferSize() */
- private long previousReceiveBufferSizeCount = 0;
-
- /**
- * Creates a new predictor with the default parameters. With the default
- * parameters, the expected buffer size starts from {@code 1024}, does not
- * go down below {@code 64}, and does not go up above {@code 65536}.
- */
- public WrappedAdaptiveReceiveBufferSizePredictor() {
- adaptiveReceiveBufferSizePredictor =
- new AdaptiveReceiveBufferSizePredictor();
- }
-
- /**
- * Creates a new predictor with the specified parameters.
- *
- * @param minimum the inclusive lower bound of the expected buffer size
- * @param initial the initial buffer size when no feed back was received
- * @param maximum the inclusive upper bound of the expected buffer size
- */
- public WrappedAdaptiveReceiveBufferSizePredictor(int minimum,
- int initial,
- int maximum) {
- adaptiveReceiveBufferSizePredictor =
- new AdaptiveReceiveBufferSizePredictor(minimum, initial, maximum);
- }
-
- @Override
- public int nextReceiveBufferSize() {
- int nextReceiveBufferSize =
- adaptiveReceiveBufferSizePredictor.nextReceiveBufferSize();
- if (LOG.isDebugEnabled()) {
- if (nextReceiveBufferSizeCount % 1000 == 0) {
- LOG.debug("nextReceiveBufferSize: size " +
- nextReceiveBufferSize + " " +
- "count " + nextReceiveBufferSizeCount);
- }
- ++nextReceiveBufferSizeCount;
- }
- return nextReceiveBufferSize;
- }
-
- @Override
- public void previousReceiveBufferSize(int previousReceiveBufferSize) {
- if (LOG.isDebugEnabled()) {
- if (previousReceiveBufferSizeCount % 1000 == 0) {
- LOG.debug("previousReceiveBufferSize: size " +
- previousReceiveBufferSize +
- ", count " + previousReceiveBufferSizeCount);
- }
- ++previousReceiveBufferSizeCount;
- }
- adaptiveReceiveBufferSizePredictor.previousReceiveBufferSize(
- previousReceiveBufferSize);
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/giraph/blob/62f9fd3f/giraph-core/src/main/java/org/apache/giraph/comm/netty/handler/AuthorizeServerHandler.java
----------------------------------------------------------------------
diff --git a/giraph-core/src/main/java/org/apache/giraph/comm/netty/handler/AuthorizeServerHandler.java b/giraph-core/src/main/java/org/apache/giraph/comm/netty/handler/AuthorizeServerHandler.java
index 274e61c..564ee68 100644
--- a/giraph-core/src/main/java/org/apache/giraph/comm/netty/handler/AuthorizeServerHandler.java
+++ b/giraph-core/src/main/java/org/apache/giraph/comm/netty/handler/AuthorizeServerHandler.java
@@ -21,16 +21,15 @@ package org.apache.giraph.comm.netty.handler;
import org.apache.giraph.comm.netty.NettyServer;
import org.apache.giraph.comm.netty.SaslNettyServer;
import org.apache.log4j.Logger;
-import org.jboss.netty.channel.ChannelHandlerContext;
-import org.jboss.netty.channel.MessageEvent;
-import org.jboss.netty.channel.SimpleChannelUpstreamHandler;
+import io.netty.channel.ChannelInboundHandlerAdapter;
+import io.netty.channel.ChannelHandlerContext;
/**
* Authorize or deny client requests based on existence and completeness
* of client's SASL authentication.
*/
public class AuthorizeServerHandler extends
- SimpleChannelUpstreamHandler {
+ ChannelInboundHandlerAdapter {
/** Class logger */
private static final Logger LOG =
Logger.getLogger(AuthorizeServerHandler.class);
@@ -42,27 +41,27 @@ public class AuthorizeServerHandler extends
}
@Override
- public void messageReceived(
- ChannelHandlerContext ctx, MessageEvent e) {
+ public void channelRead(ChannelHandlerContext ctx, Object msg)
+ throws Exception {
if (LOG.isDebugEnabled()) {
- LOG.debug("messageReceived: Got " + e.getMessage().getClass());
+ LOG.debug("messageReceived: Got " + msg.getClass());
}
// Authorize: client is allowed to doRequest() if and only if the client
// has successfully authenticated with this server.
SaslNettyServer saslNettyServer =
- NettyServer.CHANNEL_SASL_NETTY_SERVERS.get(ctx.getChannel());
+ ctx.attr(NettyServer.CHANNEL_SASL_NETTY_SERVERS).get();
if (saslNettyServer == null) {
LOG.warn("messageReceived: This client is *NOT* authorized to perform " +
"this action since there's no saslNettyServer to " +
"authenticate the client: " +
- "refusing to perform requested action: " + e.getMessage());
+ "refusing to perform requested action: " + msg);
return;
}
if (!saslNettyServer.isComplete()) {
LOG.warn("messageReceived: This client is *NOT* authorized to perform " +
"this action because SASL authentication did not complete: " +
- "refusing to perform requested action: " + e.getMessage());
+ "refusing to perform requested action: " + msg);
// Return now *WITHOUT* sending upstream here, since client
// not authorized.
return;
@@ -72,9 +71,9 @@ public class AuthorizeServerHandler extends
saslNettyServer.getUserName() + " is authorized to do request " +
"on server.");
}
- // We call sendUpstream() since the client is allowed to perform this
+ // We call fireChannelRead since the client is allowed to perform this
// request. The client's request will now proceed to the next
// pipeline component, namely, RequestServerHandler.
- ctx.sendUpstream(e);
+ ctx.fireChannelRead(msg);
}
}
http://git-wip-us.apache.org/repos/asf/giraph/blob/62f9fd3f/giraph-core/src/main/java/org/apache/giraph/comm/netty/handler/RequestDecoder.java
----------------------------------------------------------------------
diff --git a/giraph-core/src/main/java/org/apache/giraph/comm/netty/handler/RequestDecoder.java b/giraph-core/src/main/java/org/apache/giraph/comm/netty/handler/RequestDecoder.java
index 6eb6549..98a61e6 100644
--- a/giraph-core/src/main/java/org/apache/giraph/comm/netty/handler/RequestDecoder.java
+++ b/giraph-core/src/main/java/org/apache/giraph/comm/netty/handler/RequestDecoder.java
@@ -19,7 +19,7 @@
package org.apache.giraph.comm.netty.handler;
import org.apache.giraph.conf.ImmutableClassesGiraphConfiguration;
-import org.apache.giraph.comm.netty.ByteCounter;
+import org.apache.giraph.comm.netty.InboundByteCounter;
import org.apache.giraph.comm.requests.RequestType;
import org.apache.giraph.comm.requests.WritableRequest;
import org.apache.giraph.utils.ReflectionUtils;
@@ -27,16 +27,17 @@ import org.apache.giraph.time.SystemTime;
import org.apache.giraph.time.Time;
import org.apache.giraph.time.Times;
import org.apache.log4j.Logger;
-import org.jboss.netty.buffer.ChannelBuffer;
-import org.jboss.netty.buffer.ChannelBufferInputStream;
-import org.jboss.netty.channel.Channel;
-import org.jboss.netty.channel.ChannelHandlerContext;
-import org.jboss.netty.handler.codec.oneone.OneToOneDecoder;
+
+import io.netty.buffer.ByteBuf;
+import io.netty.buffer.ByteBufInputStream;
+import io.netty.channel.ChannelHandlerContext;
+import io.netty.channel.ChannelInboundHandlerAdapter;
+import io.netty.util.ReferenceCountUtil;
/**
* Decodes encoded requests from the client.
*/
-public class RequestDecoder extends OneToOneDecoder {
+public class RequestDecoder extends ChannelInboundHandlerAdapter {
/** Class logger */
private static final Logger LOG =
Logger.getLogger(RequestDecoder.class);
@@ -44,8 +45,8 @@ public class RequestDecoder extends OneToOneDecoder {
private static final Time TIME = SystemTime.get();
/** Configuration */
private final ImmutableClassesGiraphConfiguration conf;
- /** Byte counter to output */
- private final ByteCounter byteCounter;
+ /** In bound byte counter to output */
+ private final InboundByteCounter byteCounter;
/** Start nanoseconds for the decoding time */
private long startDecodingNanoseconds = -1;
/**
@@ -55,18 +56,17 @@ public class RequestDecoder extends OneToOneDecoder {
* @param byteCounter Keeps track of the decoded bytes
*/
public RequestDecoder(ImmutableClassesGiraphConfiguration conf,
- ByteCounter byteCounter) {
+ InboundByteCounter byteCounter) {
this.conf = conf;
this.byteCounter = byteCounter;
}
@Override
- protected Object decode(ChannelHandlerContext ctx,
- Channel channel, Object msg) throws Exception {
- if (!(msg instanceof ChannelBuffer)) {
+ public void channelRead(ChannelHandlerContext ctx, Object msg)
+ throws Exception {
+ if (!(msg instanceof ByteBuf)) {
throw new IllegalStateException("decode: Got illegal message " + msg);
}
-
// Output metrics every 1/2 minute
String metrics = byteCounter.getMetricsWindow(30000);
if (metrics != null) {
@@ -80,8 +80,8 @@ public class RequestDecoder extends OneToOneDecoder {
}
// Decode the request
- ChannelBuffer buffer = (ChannelBuffer) msg;
- ChannelBufferInputStream inputStream = new ChannelBufferInputStream(buffer);
+ ByteBuf buffer = (ByteBuf) msg;
+ ByteBufInputStream inputStream = new ByteBufInputStream(buffer);
int enumValue = inputStream.readByte();
RequestType type = RequestType.values()[enumValue];
Class<? extends WritableRequest> writableRequestClass =
@@ -97,7 +97,9 @@ public class RequestDecoder extends OneToOneDecoder {
buffer.array().length + " took " +
Times.getNanosSince(TIME, startDecodingNanoseconds) + " ns");
}
-
- return writableRequest;
+ // release bytebuf
+ ReferenceCountUtil.release(buffer);
+ // fire writableRequest object to upstream handlers
+ ctx.fireChannelRead(writableRequest);
}
}
http://git-wip-us.apache.org/repos/asf/giraph/blob/62f9fd3f/giraph-core/src/main/java/org/apache/giraph/comm/netty/handler/RequestEncoder.java
----------------------------------------------------------------------
diff --git a/giraph-core/src/main/java/org/apache/giraph/comm/netty/handler/RequestEncoder.java b/giraph-core/src/main/java/org/apache/giraph/comm/netty/handler/RequestEncoder.java
index f49a2b4..d379eda 100644
--- a/giraph-core/src/main/java/org/apache/giraph/comm/netty/handler/RequestEncoder.java
+++ b/giraph-core/src/main/java/org/apache/giraph/comm/netty/handler/RequestEncoder.java
@@ -25,17 +25,17 @@ import org.apache.giraph.time.SystemTime;
import org.apache.giraph.time.Time;
import org.apache.giraph.time.Times;
import org.apache.log4j.Logger;
-import org.jboss.netty.buffer.ChannelBuffer;
-import org.jboss.netty.buffer.ChannelBufferOutputStream;
-import org.jboss.netty.buffer.ChannelBuffers;
-import org.jboss.netty.channel.Channel;
-import org.jboss.netty.channel.ChannelHandlerContext;
-import org.jboss.netty.handler.codec.oneone.OneToOneEncoder;
+
+import io.netty.buffer.ByteBuf;
+import io.netty.buffer.ByteBufOutputStream;
+import io.netty.channel.ChannelHandlerContext;
+import io.netty.channel.ChannelOutboundHandlerAdapter;
+import io.netty.channel.ChannelPromise;
/**
* Requests have a request type and an encoded request.
*/
-public class RequestEncoder extends OneToOneEncoder {
+public class RequestEncoder extends ChannelOutboundHandlerAdapter {
/** Time class to use */
private static final Time TIME = SystemTime.get();
/** Class logger */
@@ -62,8 +62,9 @@ public class RequestEncoder extends OneToOneEncoder {
}
@Override
- protected Object encode(ChannelHandlerContext ctx,
- Channel channel, Object msg) throws Exception {
+ public void write(ChannelHandlerContext ctx, Object msg,
+ ChannelPromise promise)
+ throws Exception {
if (!(msg instanceof WritableRequest)) {
throw new IllegalArgumentException(
"encode: Got a message of type " + msg.getClass());
@@ -73,21 +74,18 @@ public class RequestEncoder extends OneToOneEncoder {
if (LOG.isDebugEnabled()) {
startEncodingNanoseconds = TIME.getNanoseconds();
}
+ ByteBuf buf;
WritableRequest writableRequest = (WritableRequest) msg;
int requestSize = writableRequest.getSerializedSize();
- ChannelBuffer channelBuffer;
if (requestSize == WritableRequest.UNKNOWN_SIZE) {
- channelBuffer = ChannelBuffers.dynamicBuffer(
- bufferStartingSize,
- ctx.getChannel().getConfig().getBufferFactory());
+ buf = ctx.alloc().buffer(bufferStartingSize);
} else {
requestSize += LENGTH_PLACEHOLDER.length + 1;
- channelBuffer = useDirectBuffers ?
- ChannelBuffers.directBuffer(requestSize) :
- ChannelBuffers.buffer(requestSize);
+ buf = useDirectBuffers ? ctx.alloc().directBuffer(requestSize) :
+ ctx.alloc().buffer(requestSize);
}
- ChannelBufferOutputStream outputStream =
- new ChannelBufferOutputStream(channelBuffer);
+ ByteBufOutputStream outputStream =
+ new ByteBufOutputStream(buf);
outputStream.write(LENGTH_PLACEHOLDER);
outputStream.writeByte(writableRequest.getType().ordinal());
try {
@@ -102,15 +100,14 @@ public class RequestEncoder extends OneToOneEncoder {
outputStream.close();
// Set the correct size at the end
- ChannelBuffer encodedBuffer = outputStream.buffer();
- encodedBuffer.setInt(0, encodedBuffer.writerIndex() - 4);
+ buf.setInt(0, buf.writerIndex() - 4);
if (LOG.isDebugEnabled()) {
LOG.debug("encode: Client " + writableRequest.getClientId() + ", " +
"requestId " + writableRequest.getRequestId() +
- ", size = " + encodedBuffer.writerIndex() + ", " +
+ ", size = " + buf.readableBytes() + ", " +
writableRequest.getType() + " took " +
Times.getNanosSince(TIME, startEncodingNanoseconds) + " ns");
}
- return encodedBuffer;
+ ctx.writeAndFlush(buf, promise);
}
}
http://git-wip-us.apache.org/repos/asf/giraph/blob/62f9fd3f/giraph-core/src/main/java/org/apache/giraph/comm/netty/handler/RequestInfo.java
----------------------------------------------------------------------
diff --git a/giraph-core/src/main/java/org/apache/giraph/comm/netty/handler/RequestInfo.java b/giraph-core/src/main/java/org/apache/giraph/comm/netty/handler/RequestInfo.java
index 1fa7c00..5071aa5 100644
--- a/giraph-core/src/main/java/org/apache/giraph/comm/netty/handler/RequestInfo.java
+++ b/giraph-core/src/main/java/org/apache/giraph/comm/netty/handler/RequestInfo.java
@@ -21,7 +21,7 @@ package org.apache.giraph.comm.netty.handler;
import org.apache.giraph.comm.requests.WritableRequest;
import org.apache.giraph.time.SystemTime;
import org.apache.giraph.time.Time;
-import org.jboss.netty.channel.ChannelFuture;
+import io.netty.channel.ChannelFuture;
import java.net.InetSocketAddress;
import java.util.Date;