Skip to content

Instantly share code, notes, and snippets.

View normanmaurer's full-sized avatar
🤙

Norman Maurer normanmaurer

🤙
View GitHub Profile
public int pump(ByteBuf bytes)
{
int bytesRead = 0;
try
{
if (bytes.readableBytes() < 8)
{
return 0;
}
iff --git a/common/src/main/java/io/netty/util/Recycler.java b/common/src/main/java/io/netty/util/Recycler.java
index 971740f..170a0e5 100644
--- a/common/src/main/java/io/netty/util/Recycler.java
+++ b/common/src/main/java/io/netty/util/Recycler.java
@@ -35,7 +35,8 @@ import java.util.concurrent.atomic.AtomicInteger;
public abstract class Recycler<T> {
private static final InternalLogger logger = InternalLoggerFactory.getInstance(Recycler.class);
-
+ private static final AtomicInteger ID_GENERATOR = new AtomicInteger(Integer.MIN_VALUE);
# Run complete. Total time: 00:29:58
Benchmark (size) Mode Samples Score Score error Units
i.n.m.b.ByteBufAllocatorBenchmark.defaultPooledDirectAllocAndFree 00000 thrpt 20 9824.753 440.050 ops/ms
i.n.m.b.ByteBufAllocatorBenchmark.defaultPooledDirectAllocAndFree 00256 thrpt 20 10917.065 129.038 ops/ms
i.n.m.b.ByteBufAllocatorBenchmark.defaultPooledDirectAllocAndFree 01024 thrpt 20 10549.387 93.710 ops/ms
i.n.m.b.ByteBufAllocatorBenchmark.defaultPooledDirectAllocAndFree 04096 thrpt 20 10336.658 54.765 ops/ms
i.n.m.b.ByteBufAllocatorBenchmark.defaultPooledDirectAllocAndFree 16384 thrpt 20 11049.749 320.725 ops/ms
i.n.m.b.ByteBufAllocatorBenchmark.defaultPooledDirectAllocAndFree 65536 thrpt 20 10475.519 351.349 ops/ms
i.n.m.b.ByteBufAllocatorBenchmark.defaultPooledHeapAllocAndFree 00000 thrpt 20 10
# Run complete. Total time: 00:29:56
Benchmark (size) Mode Samples Score Score error Units
i.n.m.b.ByteBufAllocatorBenchmark.defaultPooledDirectAllocAndFree 00000 thrpt 20 10558.393 128.586 ops/ms
i.n.m.b.ByteBufAllocatorBenchmark.defaultPooledDirectAllocAndFree 00256 thrpt 20 10651.489 240.927 ops/ms
i.n.m.b.ByteBufAllocatorBenchmark.defaultPooledDirectAllocAndFree 01024 thrpt 20 10786.637 73.084 ops/ms
i.n.m.b.ByteBufAllocatorBenchmark.defaultPooledDirectAllocAndFree 04096 thrpt 20 10037.158 273.448 ops/ms
i.n.m.b.ByteBufAllocatorBenchmark.defaultPooledDirectAllocAndFree 16384 thrpt 20 9986.690 387.501 ops/ms
i.n.m.b.ByteBufAllocatorBenchmark.defaultPooledDirectAllocAndFree 65536 thrpt 20 10067.789 303.871 ops/ms
ByteBuf buffer = PooledByteBufAllocator.DEFAULT.heapBuffer(1024 * 1024);
try
{
synchronized (connection.getTrio().getLock())
{
int count;
//todo an optimisation here would be to only use the buffer if we need more that one recv
while ((count = receiver.recv(buffer.array(), buffer.arrayOffset() + buffer.writerIndex(), buffer.writableBytes())> 0)
{
// Increment the writer index by the number of bytes written into it while calling recv.
public class Channel {
private final Queue<Runnable> queue ...
private final ChannelExecutor executor;
....
public EventExecutor executor() {
return executor;
}
Executor executor = ...;
executor.execute(new Runnable() {
public void run() {
// Want to benchmark how long it took until this method was called.
}
}

master branch:

[nmaurer@xxx]~% wrk/wrk -H 'Host: localhost' -H 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8' -H 'Connection: keep-alive' -d 120 -c 256 -t 16 --pipeline 256  http://xxx:8080/plaintext
Running 2m test @ http://xxx:8080/plaintext
  16 threads and 256 connections
  Thread Stats   Avg      Stdev     Max   +/- Stdev
    Latency    22.98ms   18.87ms 376.38ms   91.26%
    Req/Sec   188.41k    39.74k  312.53k    70.52%
  359909247 requests in 2.00m, 48.60GB read
/**
* Created by crised on 6/15/14.
*/
public class Handler extends ChannelInboundHandlerAdapter{
@Override
public void channelActive(ChannelHandlerContext ctx) throws Exception {
InetSocketAddress ipSocketAddress = new InetSocketAddress("255.255.255.255", 7686);
4.0
# Run complete. Total time: 00:04:56
Benchmark (size) Mode Samples Score Score error Units
i.n.m.i.RecyclableArrayListBenchmark.recycleSameThread 00000 thrpt 80 30753.272 1113.449 ops/ms
i.n.m.i.RecyclableArrayListBenchmark.recycleSameThread 00256 thrpt 80 31506.991 791.776 ops/ms
i.n.m.i.RecyclableArrayListBenchmark.recycleSameThread 01024 thrpt 80 31871.752 726.351 ops/ms
i.n.m.i.RecyclableArrayListBenchmark.recycleSameThread 04096 thrpt 80 29383.672 975.254 ops/ms
i.n.m.i.RecyclableArrayListBenchmark.recycleSameThread 16384 thrpt 80 30394.323 837.736 ops/ms