Home / Class/ IsKeepAliveBenchmark Class — netty Architecture

IsKeepAliveBenchmark Class — netty Architecture

Architecture documentation for the IsKeepAliveBenchmark class in IsKeepAliveBenchmark.java from the netty codebase.

Entity Profile

Dependency Diagram

graph TD
  4326e7e2_fab3_dec2_fce8_32dffea2c089["IsKeepAliveBenchmark"]
  72cc1d90_e700_838b_2292_d485f17a3a62["IsKeepAliveBenchmark.java"]
  4326e7e2_fab3_dec2_fce8_32dffea2c089 -->|defined in| 72cc1d90_e700_838b_2292_d485f17a3a62
  5d4e8a23_ec4d_912b_b2ee_9ef5647c8df5["setup()"]
  4326e7e2_fab3_dec2_fce8_32dffea2c089 -->|method| 5d4e8a23_ec4d_912b_b2ee_9ef5647c8df5
  be08850d_2c75_2ebc_cbd6_16faa4a19961["setConnectionClose()"]
  4326e7e2_fab3_dec2_fce8_32dffea2c089 -->|method| be08850d_2c75_2ebc_cbd6_16faa4a19961
  6bb029a1_c25a_6063_83d3_4f183003dbac["isKeepAlive()"]
  4326e7e2_fab3_dec2_fce8_32dffea2c089 -->|method| 6bb029a1_c25a_6063_83d3_4f183003dbac
  2c38c2ba_8047_a338_ce76_ee976952e665["isKeepAliveWithGarbage()"]
  4326e7e2_fab3_dec2_fce8_32dffea2c089 -->|method| 2c38c2ba_8047_a338_ce76_ee976952e665

Relationship Graph

Source Code

microbench/src/main/java/io/netty/microbench/headers/IsKeepAliveBenchmark.java lines 43–134

@State(Scope.Benchmark)
@Fork(2)
@Warmup(iterations = 10, time = 200, timeUnit = TimeUnit.MILLISECONDS)
@Measurement(iterations = 10, time = 200, timeUnit = TimeUnit.MILLISECONDS)
@BenchmarkMode(Mode.AverageTime)
@OutputTimeUnit(TimeUnit.NANOSECONDS)
public class IsKeepAliveBenchmark extends AbstractMicrobenchmark {

    public enum ConnectionClose {
        KeepAlive,
        Close,
        None
    }

    @Param
    public ConnectionClose close;
    // this is distributing equally branching for warmup purposes, although in the real world it likely
    // happens to be skewed towards one of the options!
    @Param({"false", "true"})
    public boolean warmup;

    FullHttpRequest request;

    @Setup
    public void setup(Blackhole bh) {
        request = new DefaultFullHttpRequest(
                HttpVersion.HTTP_1_1,
                HttpMethod.GET,
                "/index.html");
        HttpHeaders headers = request.headers();
        // values are usually strings decoded out of network buffers
        headers.set(HttpHeaderNames.HOST, "localhost");
        headers.set(HttpHeaderNames.USER_AGENT,
                "Mozilla/5.0 (Windows NT 10.0; Win64; x64) "
                        + "AppleWebKit/537.36 (KHTML, like Gecko) "
                        + "Chrome/131.0.0.0 Safari/537.36");
        headers.set(HttpHeaderNames.ACCEPT,
                "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8");
        headers.set(HttpHeaderNames.ACCEPT_LANGUAGE, "en-US,en;q=0.9");
        headers.set(HttpHeaderNames.ACCEPT_ENCODING, "gzip, deflate");
        headers.set(HttpHeaderNames.UPGRADE_INSECURE_REQUESTS, "1");
        headers.set(HttpHeaderNames.CACHE_CONTROL, "max-age=0");

        if (warmup) {
            // create 3 request variations for warmup based on the ConnectionClose values
            ConnectionClose[] cases = ConnectionClose.values();
            FullHttpRequest[] requests = new FullHttpRequest[cases.length];
            for (int i = 0; i < requests.length; i++) {
                requests[i] = request.copy();
                setConnectionClose(requests[i].headers(), cases[i]);
            }
            // warmup with mixed requests
            for (int i = 0; i < 100_000; i++) {
                for (FullHttpRequest httpRequest : requests) {
                    bh.consume(isKeepAlive(httpRequest));
                }
            }
        }
        // set the actual test case
        setConnectionClose(headers, close);
    }

    private static void setConnectionClose(HttpHeaders headers, ConnectionClose close) {
        switch (close) {
            case KeepAlive:
                headers.set(HttpHeaderNames.CONNECTION, "keep-alive");
                break;
            case Close:
                headers.set(HttpHeaderNames.CONNECTION, "close");
                break;
            case None:
                // omit header
                break;
        }
    }

    @Benchmark
    public boolean isKeepAlive() {
        return isKeepAlive(request);
    }

Frequently Asked Questions

What is the IsKeepAliveBenchmark class?
IsKeepAliveBenchmark is a class in the netty codebase, defined in microbench/src/main/java/io/netty/microbench/headers/IsKeepAliveBenchmark.java.
Where is IsKeepAliveBenchmark defined?
IsKeepAliveBenchmark is defined in microbench/src/main/java/io/netty/microbench/headers/IsKeepAliveBenchmark.java at line 43.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free