jetty.project icon indicating copy to clipboard operation
jetty.project copied to clipboard

Jetty Client and Use Netty EventLoop

Open himanshumps opened this issue 3 years ago • 5 comments
trafficstars

Jetty-client version 11.0.11 Java version 17 Question Hi,

I want to use netty event loop for executor. This is what I have so far

    EventLoopGroup eventLoopGroup;
    if(KQueue.isAvailable()) {
      System.out.println("KQueue is available");
      eventLoopGroup = new KQueueEventLoopGroup(2, new ThreadFactory() {
        private AtomicInteger index = new AtomicInteger(0);
        @Override
        public Thread newThread(Runnable r) {
          return new Thread(r, "kqueue-" + index.getAndIncrement());
        }
      });
    } else if(Epoll.isAvailable()) {
      System.out.println("Epoll is available");
      eventLoopGroup = new EpollEventLoopGroup(2, new ThreadFactory() {
        private AtomicInteger index = new AtomicInteger(0);
        @Override
        public Thread newThread(Runnable r) {
          return new Thread(r, "epoll-" + index.getAndIncrement());
        }
      });
    } else {
      System.out.println("Nio is available");
      eventLoopGroup = new NioEventLoopGroup(2, new ThreadFactory() {
        private AtomicInteger index = new AtomicInteger(0);
        @Override
        public Thread newThread(Runnable r) {
          return new Thread(r, "nio-" + index.getAndIncrement());
        }
      });
    }
HttpClient client = new HttpClient(httpClientTransportOverHTTP2);
client.setExecutor(eventLoopGroup);

But it just hangs after sending one request.

Also if someone can explain/(point me to) the difference and uses of between setScheduler, setExecutor and setSelectors, it would be of great help.

Thanks, Himanshu

himanshumps avatar Aug 09 '22 06:08 himanshumps

You don't need Netty's event loops.

Jetty's HttpClient already uses its own event loops, whose number you can configure by configuring the number of selectors. Use a normal Executor.

sbordet avatar Aug 09 '22 07:08 sbordet

@sbordet I am trying to reach near to what h2load provides as the benchmark for http/2.

For my current setup, I was able to reach 20k/sec using 2 connection using jetty http2 client whereas h2load is giving 26k/sec. If I post my code, would you be able to provide some inputs?

himanshumps avatar Aug 09 '22 08:08 himanshumps

@sbordet Also, if you are aware and have some time, can you please explain/(point me to) the difference and uses of between setScheduler, setExecutor and setSelectors, it would be of great help.

himanshumps avatar Aug 09 '22 08:08 himanshumps

You can find some documentation about selectors here: https://www.eclipse.org/jetty/documentation/jetty-11/programming-guide/index.html#pg-client-io-arch-network

About scheduler and executor there is not much to say, one it's a scheduler, and the other is an executor, same concepts as the JDK ones.

About the h2load difference, IIRC h2load prepares a large number of HTTP/2 requests as a big byte array, and then shoves them all into a single connection. This is ok for a load tester, but less so for a generic HTTP/2 client like Jetty's, so I'd expect some performance penalty in exchange of more features.

sbordet avatar Aug 09 '22 14:08 sbordet

@sbordet I was able to get it to 22k/rps with some optimisation. I am sure if you look at it you can provide some valuable insights on further improvement. I will post the code on this thread in some time.

himanshumps avatar Aug 12 '22 12:08 himanshumps

This issue has been automatically marked as stale because it has been a full year without activity. It will be closed if no further activity occurs. Thank you for your contributions.

github-actions[bot] avatar Aug 13 '23 00:08 github-actions[bot]

This issue has been closed due to it having no activity.

github-actions[bot] avatar Sep 13 '23 00:09 github-actions[bot]