Skip to content

Commit

Permalink
submission cleanup #8
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrei-Pozolotin committed Jan 7, 2013
1 parent ec2644f commit 033edc0
Show file tree
Hide file tree
Showing 25 changed files with 686 additions and 143 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.socket.nio.NioEventLoopGroup;
import io.netty.example.udt.util.ConsoleReporterUDT;
import io.netty.example.udt.util.ThreadFactoryUDT;
import io.netty.example.udt.util.UtilConsoleReporter;
import io.netty.example.udt.util.UtilThreadFactory;
import io.netty.handler.logging.LogLevel;
import io.netty.handler.logging.LoggingHandler;
import io.netty.transport.udt.UdtChannel;
Expand Down Expand Up @@ -60,7 +60,7 @@ public ByteEchoClient(final String host, final int port,
public void run() throws Exception {
// Configure the client.
final Bootstrap boot = new Bootstrap();
final ThreadFactory connectFactory = new ThreadFactoryUDT("connect");
final ThreadFactory connectFactory = new UtilThreadFactory("connect");
final NioEventLoopGroup connectGroup = new NioEventLoopGroup(1,
connectFactory, NioUdtProvider.BYTE_PROVIDER);
try {
Expand Down Expand Up @@ -91,7 +91,7 @@ public static void main(final String[] args) throws Exception {
log.info("init");

// client is reporting metrics
ConsoleReporterUDT.enable(3, TimeUnit.SECONDS);
UtilConsoleReporter.enable(3, TimeUnit.SECONDS);

final String host = "localhost";
final int port = 1234;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelOption;
import io.netty.channel.socket.nio.NioEventLoopGroup;
import io.netty.example.udt.util.ThreadFactoryUDT;
import io.netty.example.udt.util.UtilThreadFactory;
import io.netty.handler.logging.LogLevel;
import io.netty.handler.logging.LoggingHandler;
import io.netty.transport.udt.UdtChannel;
Expand Down Expand Up @@ -48,8 +48,8 @@ public ByteEchoServer(final int port) {
}

public void run() throws Exception {
final ThreadFactory acceptFactory = new ThreadFactoryUDT("accept");
final ThreadFactory connectFactory = new ThreadFactoryUDT("connect");
final ThreadFactory acceptFactory = new UtilThreadFactory("accept");
final ThreadFactory connectFactory = new UtilThreadFactory("connect");
final NioEventLoopGroup acceptGroup = new NioEventLoopGroup(1,
acceptFactory, NioUdtProvider.BYTE_PROVIDER);
final NioEventLoopGroup connectGroup = new NioEventLoopGroup(1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.socket.nio.NioEventLoopGroup;
import io.netty.example.udt.util.ConsoleReporterUDT;
import io.netty.example.udt.util.ThreadFactoryUDT;
import io.netty.example.udt.util.UtilConsoleReporter;
import io.netty.example.udt.util.UtilThreadFactory;
import io.netty.handler.logging.LogLevel;
import io.netty.handler.logging.LoggingHandler;
import io.netty.transport.udt.UdtChannel;
Expand Down Expand Up @@ -60,7 +60,7 @@ public MsgEchoClient(final String host, final int port,
public void run() throws Exception {
// Configure the client.
final Bootstrap boot = new Bootstrap();
final ThreadFactory connectFactory = new ThreadFactoryUDT("connect");
final ThreadFactory connectFactory = new UtilThreadFactory("connect");
final NioEventLoopGroup connectGroup = new NioEventLoopGroup(1,
connectFactory, NioUdtProvider.MESSAGE_PROVIDER);
try {
Expand Down Expand Up @@ -91,7 +91,7 @@ public static void main(final String[] args) throws Exception {
log.info("init");

// client is reporting metrics
ConsoleReporterUDT.enable(3, TimeUnit.SECONDS);
UtilConsoleReporter.enable(3, TimeUnit.SECONDS);

final String host = "localhost";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelOption;
import io.netty.channel.socket.nio.NioEventLoopGroup;
import io.netty.example.udt.util.ThreadFactoryUDT;
import io.netty.example.udt.util.UtilThreadFactory;
import io.netty.handler.logging.LogLevel;
import io.netty.handler.logging.LoggingHandler;
import io.netty.transport.udt.UdtChannel;
Expand Down Expand Up @@ -48,8 +48,8 @@ public MsgEchoServer(final int port) {
}

public void run() throws Exception {
final ThreadFactory acceptFactory = new ThreadFactoryUDT("accept");
final ThreadFactory connectFactory = new ThreadFactoryUDT("connect");
final ThreadFactory acceptFactory = new UtilThreadFactory("accept");
final ThreadFactory connectFactory = new UtilThreadFactory("connect");
final NioEventLoopGroup acceptGroup = new NioEventLoopGroup(1,
acceptFactory, NioUdtProvider.MESSAGE_PROVIDER);
final NioEventLoopGroup connectGroup = new NioEventLoopGroup(1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.socket.nio.NioEventLoopGroup;
import io.netty.example.udt.util.ThreadFactoryUDT;
import io.netty.example.udt.util.UtilThreadFactory;
import io.netty.handler.logging.LogLevel;
import io.netty.handler.logging.LoggingHandler;
import io.netty.transport.udt.UdtChannel;
Expand Down Expand Up @@ -56,7 +56,7 @@ public MsgEchoPeerBase(final InetSocketAddress self,
public void run() throws Exception {
// Configure the peer.
final Bootstrap boot = new Bootstrap();
final ThreadFactory connectFactory = new ThreadFactoryUDT("rendezvous");
final ThreadFactory connectFactory = new UtilThreadFactory("rendezvous");
final NioEventLoopGroup connectGroup = new NioEventLoopGroup(1,
connectFactory, NioUdtProvider.MESSAGE_PROVIDER);
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/
package io.netty.example.udt.echo.rendevous;

import io.netty.example.udt.util.ConsoleReporterUDT;
import io.netty.example.udt.util.UtilConsoleReporter;

import java.net.InetSocketAddress;
import java.util.concurrent.TimeUnit;
Expand All @@ -37,7 +37,7 @@ public static void main(final String[] args) throws Exception {
log.info("init");

// peer two is reporting metrics
ConsoleReporterUDT.enable(3, TimeUnit.SECONDS);
UtilConsoleReporter.enable(3, TimeUnit.SECONDS);

final int messageSize = 64 * 1024;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
* A simple reporters which prints out application metrics to a
* {@link PrintStream} periodically.
*/
public class ConsoleReporterUDT extends AbstractPollingReporter implements
public class UtilConsoleReporter extends AbstractPollingReporter implements
MetricProcessor<PrintStream> {
private static final int CONSOLE_WIDTH = 80;

Expand All @@ -62,7 +62,7 @@ public static void enable(final long period, final TimeUnit unit) {
*/
public static void enable(final MetricsRegistry metricsRegistry,
final long period, final TimeUnit unit) {
final ConsoleReporterUDT reporter = new ConsoleReporterUDT(
final UtilConsoleReporter reporter = new UtilConsoleReporter(
metricsRegistry, System.out, MetricPredicate.ALL);
reporter.start(period, unit);
}
Expand All @@ -74,36 +74,36 @@ public static void enable(final MetricsRegistry metricsRegistry,
private final Locale locale;

/**
* Creates a new {@link ConsoleReporterUDT} for the default metrics
* Creates a new {@link UtilConsoleReporter} for the default metrics
* registry, with unrestricted output.
*/
public ConsoleReporterUDT(final PrintStream out) {
public UtilConsoleReporter(final PrintStream out) {
this(Metrics.defaultRegistry(), out, MetricPredicate.ALL);
}

/**
* Creates a new {@link ConsoleReporterUDT} for a given metrics registry.
* Creates a new {@link UtilConsoleReporter} for a given metrics registry.
*/
public ConsoleReporterUDT(final MetricsRegistry metricsRegistry,
public UtilConsoleReporter(final MetricsRegistry metricsRegistry,
final PrintStream out, final MetricPredicate predicate) {
this(metricsRegistry, out, predicate, Clock.defaultClock(), TimeZone
.getDefault());
}

/**
* Creates a new {@link ConsoleReporterUDT} for a given metrics registry.
* Creates a new {@link UtilConsoleReporter} for a given metrics registry.
*/
public ConsoleReporterUDT(final MetricsRegistry metricsRegistry,
public UtilConsoleReporter(final MetricsRegistry metricsRegistry,
final PrintStream out, final MetricPredicate predicate,
final Clock clock, final TimeZone timeZone) {
this(metricsRegistry, out, predicate, clock, timeZone, Locale
.getDefault());
}

/**
* Creates a new {@link ConsoleReporterUDT} for a given metrics registry.
* Creates a new {@link UtilConsoleReporter} for a given metrics registry.
*/
public ConsoleReporterUDT(final MetricsRegistry metricsRegistry,
public UtilConsoleReporter(final MetricsRegistry metricsRegistry,
final PrintStream out, final MetricPredicate predicate,
final Clock clock, final TimeZone timeZone, final Locale locale) {
super(metricsRegistry, "console-reporter");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,19 @@
/**
* Custom thread factory to use with examples.
*/
public class ThreadFactoryUDT implements ThreadFactory {
public class UtilThreadFactory implements ThreadFactory {

private static final AtomicInteger counter = new AtomicInteger();

private final String name;

public ThreadFactoryUDT(final String name) {
public UtilThreadFactory(final String name) {
this.name = name;
}

@Override
public Thread newThread(final Runnable runnable) {
return new Thread(runnable, "udt-" + name + "-"
+ counter.getAndIncrement());
return new Thread(runnable, name + "-" + counter.getAndIncrement());
};

}
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public abstract class NioUdtAcceptorChannel extends AbstractNioMessageChannel
protected static final InternalLogger logger = InternalLoggerFactory
.getInstance(NioUdtAcceptorChannel.class);

protected final UdtChannelConfig config;
private final UdtChannelConfig config;

protected NioUdtAcceptorChannel(final ServerSocketChannelUDT channelUDT) {
super(null, channelUDT.socketUDT().id(), channelUDT, OP_ACCEPT);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,11 @@ public NioUdtByteConnectorChannel(final Channel parent, final Integer id,
}
}

protected NioUdtByteConnectorChannel(final SocketChannelUDT channelUDT) {
public NioUdtByteConnectorChannel(final SocketChannelUDT channelUDT) {
this(null, channelUDT.socketUDT().id(), channelUDT);
}

protected NioUdtByteConnectorChannel(final TypeUDT type) {
public NioUdtByteConnectorChannel(final TypeUDT type) {
this(NioUdtProvider.newConnectorChannelUDT(type));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public class NioUdtMessageAcceptorChannel extends NioUdtAcceptorChannel {
private static final ChannelMetadata METADATA = new ChannelMetadata(
BufType.MESSAGE, false);

protected NioUdtMessageAcceptorChannel() {
public NioUdtMessageAcceptorChannel() {
super(TypeUDT.DATAGRAM);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,10 +213,10 @@ protected int doWriteMessages(final MessageBuf<Object> messageQueue,
}
}

message.free();

messageQueue.remove();

message.free();

return 1;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ private NioUdtProvider(final TypeUDT type, final KindUDT kind) {
*/
public KindUDT kind() {
return kind;
};
}

/**
* Produce new {@link UdtChannel} based on factory {@link #kind()} and
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* Copyright 2012 The Netty Project
*
* The Netty Project 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 io.netty.transport.udt.bench;

import io.netty.transport.udt.util.CaliperBench;
import io.netty.transport.udt.util.CaliperRunner;
import io.netty.transport.udt.util.TrafficControl;

import java.util.List;

/**
* perform two way native udt socket send/recv
*/
public abstract class BenchXfer extends CaliperBench {

/** introduce network latency */
protected static List<String> latencyList() {
if (TrafficControl.isAvailable()) {
return CaliperRunner.valueList("0,10,30");
} else {
return CaliperRunner.valueList("0");
}
}

/** verify different message sizes */
protected static List<String> messageList() {
return CaliperRunner
.valueList("500,1500,3000,5000,10000,20000,50000,100000");
}

/** benchmark run time per each configuration */
protected static List<String> durationList() {
return CaliperRunner.valueList("30000");
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*
* Copyright 2012 The Netty Project
*
* The Netty Project 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 io.netty.transport.udt.bench.xfer;

import io.netty.transport.udt.bench.BenchXfer;
import io.netty.transport.udt.util.CaliperRunner;
import io.netty.transport.udt.util.TrafficControl;

import java.util.List;

import com.google.caliper.Param;

/**
* perform two way native TCP socket send/recv
*/
public class TcpNative extends BenchXfer {

@Param
private volatile int latency;

protected static List<String> latencyValues() {
return BenchXfer.latencyList();
}

@Param
private volatile int message;

protected static List<String> messageValues() {
return BenchXfer.messageList();
}

@Param
private volatile int duration;

protected static List<String> durationValues() {
return BenchXfer.durationList();
}

public void timeRun(final int reps) throws Exception {
log.info("init");

TrafficControl.delay(latency);

TrafficControl.delay(0);

log.info("done");
}

public static void main(final String[] args) throws Exception {
CaliperRunner.execute(TcpNative.class);
}
}
Loading

0 comments on commit 033edc0

Please sign in to comment.