Search in sources :

Example 1 with EmbeddedChannelWriteReleaseHandlerContext

use of io.netty.microbench.channel.EmbeddedChannelWriteReleaseHandlerContext in project netty by netty.

the class Http2FrameWriterBenchmark method boostrapEmbeddedEnv.

private static Environment boostrapEmbeddedEnv(final EnvironmentType environmentType) {
    final ByteBufAllocator alloc = environmentType.params().clientAllocator();
    final EmbeddedEnvironment env = new EmbeddedEnvironment(new DefaultHttp2FrameWriter());
    final Http2Connection connection = new DefaultHttp2Connection(false);
    Http2ConnectionEncoder encoder = new DefaultHttp2ConnectionEncoder(connection, env.writer());
    Http2ConnectionDecoder decoder = new DefaultHttp2ConnectionDecoder(connection, encoder, new DefaultHttp2FrameReader());
    Http2ConnectionHandler connectionHandler = new Http2ConnectionHandlerBuilder().encoderEnforceMaxConcurrentStreams(false).frameListener(new Http2FrameAdapter()).codec(decoder, encoder).build();
    env.context(new EmbeddedChannelWriteReleaseHandlerContext(alloc, connectionHandler) {

        @Override
        protected void handleException(Throwable t) {
            handleUnexpectedException(t);
        }
    });
    return env;
}
Also used : ByteBufAllocator(io.netty.buffer.ByteBufAllocator) PooledByteBufAllocator(io.netty.buffer.PooledByteBufAllocator) UnpooledByteBufAllocator(io.netty.buffer.UnpooledByteBufAllocator) DefaultHttp2Connection(io.netty.handler.codec.http2.DefaultHttp2Connection) Http2FrameAdapter(io.netty.handler.codec.http2.Http2FrameAdapter) DefaultHttp2Connection(io.netty.handler.codec.http2.DefaultHttp2Connection) Http2Connection(io.netty.handler.codec.http2.Http2Connection) DefaultHttp2ConnectionDecoder(io.netty.handler.codec.http2.DefaultHttp2ConnectionDecoder) Http2ConnectionHandler(io.netty.handler.codec.http2.Http2ConnectionHandler) DefaultHttp2FrameWriter(io.netty.handler.codec.http2.DefaultHttp2FrameWriter) DefaultHttp2ConnectionEncoder(io.netty.handler.codec.http2.DefaultHttp2ConnectionEncoder) Http2ConnectionDecoder(io.netty.handler.codec.http2.Http2ConnectionDecoder) DefaultHttp2ConnectionDecoder(io.netty.handler.codec.http2.DefaultHttp2ConnectionDecoder) Http2ConnectionHandlerBuilder(io.netty.handler.codec.http2.Http2ConnectionHandlerBuilder) EmbeddedChannelWriteReleaseHandlerContext(io.netty.microbench.channel.EmbeddedChannelWriteReleaseHandlerContext) Http2ConnectionEncoder(io.netty.handler.codec.http2.Http2ConnectionEncoder) DefaultHttp2ConnectionEncoder(io.netty.handler.codec.http2.DefaultHttp2ConnectionEncoder) DefaultHttp2FrameReader(io.netty.handler.codec.http2.DefaultHttp2FrameReader)

Example 2 with EmbeddedChannelWriteReleaseHandlerContext

use of io.netty.microbench.channel.EmbeddedChannelWriteReleaseHandlerContext in project netty by netty.

the class RedisEncoderBenchmark method setup.

@Setup(Level.Trial)
public void setup() {
    byte[] bytes = new byte[256];
    content = Unpooled.buffer(bytes.length);
    content.writeBytes(bytes);
    ByteBuf testContent = Unpooled.unreleasableBuffer(content.asReadOnly());
    List<RedisMessage> rList = new ArrayList<RedisMessage>(arraySize);
    for (int i = 0; i < arraySize; ++i) {
        rList.add(new FullBulkStringRedisMessage(testContent));
    }
    redisArray = new ArrayRedisMessage(rList);
    encoder = new RedisEncoder();
    context = new EmbeddedChannelWriteReleaseHandlerContext(pooledAllocator ? PooledByteBufAllocator.DEFAULT : UnpooledByteBufAllocator.DEFAULT, encoder) {

        @Override
        protected void handleException(Throwable t) {
            handleUnexpectedException(t);
        }
    };
}
Also used : FullBulkStringRedisMessage(io.netty.handler.codec.redis.FullBulkStringRedisMessage) ArrayRedisMessage(io.netty.handler.codec.redis.ArrayRedisMessage) RedisMessage(io.netty.handler.codec.redis.RedisMessage) FullBulkStringRedisMessage(io.netty.handler.codec.redis.FullBulkStringRedisMessage) ArrayRedisMessage(io.netty.handler.codec.redis.ArrayRedisMessage) RedisEncoder(io.netty.handler.codec.redis.RedisEncoder) ArrayList(java.util.ArrayList) EmbeddedChannelWriteReleaseHandlerContext(io.netty.microbench.channel.EmbeddedChannelWriteReleaseHandlerContext) ByteBuf(io.netty.buffer.ByteBuf) Setup(org.openjdk.jmh.annotations.Setup)

Example 3 with EmbeddedChannelWriteReleaseHandlerContext

use of io.netty.microbench.channel.EmbeddedChannelWriteReleaseHandlerContext in project netty by netty.

the class Http2FrameWriterDataBenchmark method setup.

@Setup(Level.Trial)
public void setup() {
    writer = new DefaultHttp2FrameWriter();
    oldWriter = new OldDefaultHttp2FrameWriter();
    payload = pooled ? PooledByteBufAllocator.DEFAULT.buffer(payloadSize) : Unpooled.buffer(payloadSize);
    payload.writeZero(payloadSize);
    ctx = new EmbeddedChannelWriteReleaseHandlerContext(pooled ? PooledByteBufAllocator.DEFAULT : UnpooledByteBufAllocator.DEFAULT, new ChannelInboundHandlerAdapter()) {

        @Override
        protected void handleException(Throwable t) {
            handleUnexpectedException(t);
        }
    };
}
Also used : EmbeddedChannelWriteReleaseHandlerContext(io.netty.microbench.channel.EmbeddedChannelWriteReleaseHandlerContext) ChannelInboundHandlerAdapter(io.netty.channel.ChannelInboundHandlerAdapter) Setup(org.openjdk.jmh.annotations.Setup)

Example 4 with EmbeddedChannelWriteReleaseHandlerContext

use of io.netty.microbench.channel.EmbeddedChannelWriteReleaseHandlerContext in project netty by netty.

the class NoPriorityByteDistributionBenchmark method setupTrial.

@Setup(Level.Trial)
public void setupTrial() throws Exception {
    connection = new DefaultHttp2Connection(false);
    dataRefresherKey = connection.newKey();
    // Create the flow controller
    switch(algorithm) {
        case WFQ:
            distributor = new WeightedFairQueueByteDistributor(connection, 0);
            break;
        case UNIFORM:
            distributor = new UniformStreamByteDistributor(connection);
            break;
    }
    controller = new DefaultHttp2RemoteFlowController(connection, new ByteCounter(distributor));
    connection.remote().flowController(controller);
    Http2ConnectionHandler handler = new Http2ConnectionHandlerBuilder().encoderEnforceMaxConcurrentStreams(false).validateHeaders(false).frameListener(new Http2FrameAdapter()).connection(connection).build();
    ctx = new EmbeddedChannelWriteReleaseHandlerContext(PooledByteBufAllocator.DEFAULT, handler) {

        @Override
        protected void handleException(Throwable t) {
            handleUnexpectedException(t);
        }
    };
    handler.handlerAdded(ctx);
    handler.channelActive(ctx);
    // Create the streams, each initialized with MAX_INT bytes.
    for (int i = 0; i < numStreams; ++i) {
        Http2Stream stream = connection.local().createStream(toStreamId(i), false);
        addData(stream, Integer.MAX_VALUE);
        stream.setProperty(dataRefresherKey, new DataRefresher(stream));
    }
}
Also used : DefaultHttp2Connection(io.netty.handler.codec.http2.DefaultHttp2Connection) Http2FrameAdapter(io.netty.handler.codec.http2.Http2FrameAdapter) Http2ConnectionHandler(io.netty.handler.codec.http2.Http2ConnectionHandler) WeightedFairQueueByteDistributor(io.netty.handler.codec.http2.WeightedFairQueueByteDistributor) Http2ConnectionHandlerBuilder(io.netty.handler.codec.http2.Http2ConnectionHandlerBuilder) EmbeddedChannelWriteReleaseHandlerContext(io.netty.microbench.channel.EmbeddedChannelWriteReleaseHandlerContext) DefaultHttp2RemoteFlowController(io.netty.handler.codec.http2.DefaultHttp2RemoteFlowController) Http2Stream(io.netty.handler.codec.http2.Http2Stream) UniformStreamByteDistributor(io.netty.handler.codec.http2.UniformStreamByteDistributor) Setup(org.openjdk.jmh.annotations.Setup)

Example 5 with EmbeddedChannelWriteReleaseHandlerContext

use of io.netty.microbench.channel.EmbeddedChannelWriteReleaseHandlerContext in project netty by netty.

the class HttpObjectEncoderBenchmark method setup.

@Setup(Level.Trial)
public void setup() {
    byte[] bytes = new byte[256];
    content = Unpooled.buffer(bytes.length);
    content.writeBytes(bytes);
    ByteBuf testContent = Unpooled.unreleasableBuffer(content.asReadOnly());
    HttpHeaders headersWithChunked = new DefaultHttpHeaders(false);
    headersWithChunked.add(HttpHeaderNames.TRANSFER_ENCODING, HttpHeaderValues.CHUNKED);
    HttpHeaders headersWithContentLength = new DefaultHttpHeaders(false);
    headersWithContentLength.add(HttpHeaderNames.CONTENT_LENGTH, testContent.readableBytes());
    fullRequest = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.POST, "/index", testContent, headersWithContentLength, EmptyHttpHeaders.INSTANCE);
    contentLengthRequest = new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.POST, "/index", headersWithContentLength);
    chunkedRequest = new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.POST, "/index", headersWithChunked);
    lastContent = new DefaultLastHttpContent(testContent, false);
    encoder = new HttpRequestEncoder();
    context = new EmbeddedChannelWriteReleaseHandlerContext(pooledAllocator ? PooledByteBufAllocator.DEFAULT : UnpooledByteBufAllocator.DEFAULT, encoder) {

        @Override
        protected void handleException(Throwable t) {
            handleUnexpectedException(t);
        }
    };
}
Also used : HttpHeaders(io.netty.handler.codec.http.HttpHeaders) EmptyHttpHeaders(io.netty.handler.codec.http.EmptyHttpHeaders) DefaultHttpHeaders(io.netty.handler.codec.http.DefaultHttpHeaders) DefaultFullHttpRequest(io.netty.handler.codec.http.DefaultFullHttpRequest) DefaultLastHttpContent(io.netty.handler.codec.http.DefaultLastHttpContent) DefaultHttpHeaders(io.netty.handler.codec.http.DefaultHttpHeaders) DefaultHttpRequest(io.netty.handler.codec.http.DefaultHttpRequest) HttpRequestEncoder(io.netty.handler.codec.http.HttpRequestEncoder) EmbeddedChannelWriteReleaseHandlerContext(io.netty.microbench.channel.EmbeddedChannelWriteReleaseHandlerContext) ByteBuf(io.netty.buffer.ByteBuf) Setup(org.openjdk.jmh.annotations.Setup)

Aggregations

EmbeddedChannelWriteReleaseHandlerContext (io.netty.microbench.channel.EmbeddedChannelWriteReleaseHandlerContext)6 Setup (org.openjdk.jmh.annotations.Setup)5 ByteBuf (io.netty.buffer.ByteBuf)3 DefaultHttp2Connection (io.netty.handler.codec.http2.DefaultHttp2Connection)2 Http2ConnectionHandler (io.netty.handler.codec.http2.Http2ConnectionHandler)2 Http2ConnectionHandlerBuilder (io.netty.handler.codec.http2.Http2ConnectionHandlerBuilder)2 Http2FrameAdapter (io.netty.handler.codec.http2.Http2FrameAdapter)2 ByteBufAllocator (io.netty.buffer.ByteBufAllocator)1 PooledByteBufAllocator (io.netty.buffer.PooledByteBufAllocator)1 UnpooledByteBufAllocator (io.netty.buffer.UnpooledByteBufAllocator)1 ChannelInboundHandlerAdapter (io.netty.channel.ChannelInboundHandlerAdapter)1 DefaultFullHttpRequest (io.netty.handler.codec.http.DefaultFullHttpRequest)1 DefaultHttpHeaders (io.netty.handler.codec.http.DefaultHttpHeaders)1 DefaultHttpRequest (io.netty.handler.codec.http.DefaultHttpRequest)1 DefaultLastHttpContent (io.netty.handler.codec.http.DefaultLastHttpContent)1 EmptyHttpHeaders (io.netty.handler.codec.http.EmptyHttpHeaders)1 HttpHeaders (io.netty.handler.codec.http.HttpHeaders)1 HttpRequestEncoder (io.netty.handler.codec.http.HttpRequestEncoder)1 DefaultHttp2ConnectionDecoder (io.netty.handler.codec.http2.DefaultHttp2ConnectionDecoder)1 DefaultHttp2ConnectionEncoder (io.netty.handler.codec.http2.DefaultHttp2ConnectionEncoder)1