How many threads are there for the Internet connection that Tirus uses?

I am trying to understand the streaming model for Tyrus web connection. Is Tyrus a single thread to connect to the network? Is there some kind of thread pooling mechanism?

I tried to find a doc describing the internals of the Tyrus implementation, or any websocket implementation for Java, on how the thread model works, but I couldn't find it.

Any information on how the flow model works to maintain network connections is helpful.

I am trying to optimize my server to support thousands of network connections. Right now with 1000 network connections. The JVM uses ~ 1800 threads!

Update 1:

I am using Tyrus 1.9 on Tomcat 8.

The server completes about 500 network connections and also initiates 500 server connections on another server. Thus, we now have about 1000 web connections on the server.

One thing I noticed is the TYRUS-275 issue which I think is related to my case. It looks like the Tyrus client creates 3 threads by default to connect to the network. In my case, I have about 500 connections, so I should have about 1500 threads just for outgoing network connections.

It also looks like this, if I enable the shared container in Tyrus then I can take advantage of the SELECTOR and WORKER thread pools.

client.getProperties().put(ClientProperties.SHARED_CONTAINER, true);
client.getProperties().put(GrizzlyClientProperties.SELECTOR_THREAD_POOL_CONFIG, ThreadPoolConfig.defaultConfig().setMaxPoolSize(3));
client.getProperties().put(GrizzlyClientProperties.WORKER_THREAD_POOL_CONFIG, ThreadPoolConfig.defaultConfig().setMaxPoolSize(10));

      

I am wondering how to optimize thread pools? How many SELECTOR and WORKER slots do you need for 500 website connections? Is there a formula?

Update 2:

When I connect to the JVM I see the following topics (with listing only):

- 24   x WebSocketServer-localhost-ROOT-xxxx [mostly parked]
- 1    x WebSocket background processing [mostly asleep]
- 10   x tyrus-1-thread-xx [mostly parked]
- 10   x tyrus-2-thread-xx [mostly parked]
- 1    x Tomcat JDBC Pool Cleaner [waiting]
- 1    x Signal Dispatcher [all running]
- 9    x nioEventLoopGroup-x-x [all running]
- 1    x main [all running]
- 177  x Keep-Alive-Timer [sleeping]
- 1    x java-sdk-htttp-connection-reaper [sleeping]
- 1    x http-apr-8080-Sendfile [waiting]
- 1    x http-apr-8080-Poller [running]
- 200  x http-apr-8080-exec-xxx [mostly parked with running slices]
- 1    x http-apr-8080-AsyncTimeout [sleeping]
- 1    x http-apr-8080-Acceptor-0 [running]
- ~630 x Grizzly(1) [mostly parked]
- ~634 x Grizzly(1) SelectorRunner [mostly running]
- ~635 x Grizzly(2) [moslty parked]

      

I think the Grizzly themes are the ones the Tyrus client creates for each website (BTW, I think I didn't count the Grizzly themes carefully. I think the score should be the same for all three). One selector of two workers, right?

I think http-apr-8080-exec-xxx are tomcat generated threads. Are these streams related to incoming connections on the network? I am more interested in reading about the following streams:

  • WebSocketServer-localhost-ROOT-xxxx
  • Dash-x-thread-xx
  • nioEventLoopGroup-xx
  • Keep-Alive-Timer
  • http-apr-8080-exec-xxx

Does anyone know what each set of threads does? Any document that explains this?

It also looks like my Tomcat is configured to use the APR connector. I was wondering if using NIO or NIO2 might be a better idea in this situation ?!

+3


source to share


1 answer


It depends on your environment. Tyrus itself (server!) Doesn't have to create new threads, it just uses those containers (Glassfish, WebLogic, ... (Grizzly when running offline server)).

Also, it depends on what you are doing at the endpoints. If you are constantly receiving / sending messages on every connection, there must be a stream for that. Otherwise, if you just plug in and don't do anything, Tyrus itself shouldn't do anything unless you are using heartbeat or something similar.



So, I can't tell you why your JVM uses a lot of threads (by the way, are they all active?) I doubt it ..) you need to provide a lot more information if you want to solve such problems. You can start by providing the code (the executable will be the best) for us to be able to reproduce what you see; feel free to move this to users@tyrus.java.net , it will probably end up in a conversation that doesn't fit into the Q / A model.

+3


source







All Articles