i trying understand threading model tyrus websocket connection. tyrus using 1 thread per websocket connection? there thread pooling mechanism involved?
i tried find document describe internals of tyrus implementation or websocket implementation java on how thread model works, couldn't find any.
any information on how thread model works maintain websocket connections helpful.
i trying optimize server able support thousands of websocket connections. right 1000 websocket connections jvm using ~1800 threads!
update 1:
i using tyrus 1.9 on tomcat 8.
server terminates 500 websocket connections , initiates 500 websocket connections different server. have 1000 websocket connections on server now.
one thing noticed tyrus-275 issue guess related case. looks tyrus client default creates 3 threads per websocket connection. in case have around 500 connections should end having around 1500 threads outgoing websocket connections.
it looks if enable shared container in tyrus can benefit using selector , 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 wondering how optimize thread pools? how many selector , worker threads need have 500 websocket connections? there formula?
update 2:
when connect jvm see following threads (listing interesting ones 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 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 guess grizzly threads ones tyrus client creating per websocket (btw, think did not count grizzly threads carefully. think count should same 3 of them). 1 selector 2 workers, correct?
i think http-apr-8080-exec-xxx threads created tomcat. these threads taking care of incoming websocket connections? more interested know following threads:
- websocketserver-localhost-root-xxxx
- tyrus-x-thread-xx
- nioeventloopgroup-x-x
- keep-alive-timer
- http-apr-8080-exec-xxx
does know each set of threads do? document out there explains this?
also looks tomcat set use apr connector wondering using nio or nio2 can better idea in situation?!
that depends on environment. tyrus (server!) should not create new threads, uses containers (glassfish, weblogic, ... (grizzly when running in standalone server mode)) provides.
also, depends on doing in endpoints. if receiving/sending messages in each connection, there must thread it. otherwise, if you'll connect , nothing, tyrus should not anything, unless using heartbeat feature or similar.
so, cannot tell why jvm using many threads (btw active? doubt it..) - need provide more info if want solve issues that. can start providing code (executable best) able reproduce see; feel free move users@tyrus.java.net, end in conversation, not fit "so question/answer" model.
Comments
Post a Comment