Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

tomcat - thread pool

 
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Could you please explain me this sentence?

"With a monitoring tool, you can calculate the number of idle threads by comparing the current thread count to the number of busy threads."

What is the current thread?  
What is the busy thread?
 
Saloon Keeper
Posts: 12165
258
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The sentence doesn't refer to a current thread. It refers to a current number of threads. It also doesn't refer to any particular busy thread, just the number of all busy threads.

If you subtract the number of busy threads from the total number of threads, you get the number of idle threads.
 
Bronislav Bronek
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
the total number of threads = 200  by default in tomcat ?

200  -  the number of busy threads =  the number of idle threads.


Tell me please the difference between   the current thread and   the busy thread?
 
Marshal
Posts: 25682
69
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A "busy" thread is one which is doing something. An "idle" thread is one which is doing nothing. Naturally all threads are either busy or idle, but not both.

The term "current thread" doesn't mean anything. The word "current" -- at least this version of the word -- means "at the present time". So I suppose the "current thread" might mean the one you're looking at now, or something like that. But you just made that up by picking words out of the quote you posted.
 
Bronislav Bronek
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So, thread in tomcat can be either busy or idle.

default value of threads pool is 200

is this relation correct ?

( 200 - total number of idle threads) = total number of busy threads
 
Saloon Keeper
Posts: 6531
160
Android Mac OS X Firefox Browser VI Editor Tomcat Server Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't know about 200 - threads are configured in conf/server.xml, you can check what your installation uses. Either an Executor like "tomcatThreadPool", or via a maxThreads setting for each Connector.

One monitoring tool you can use to investigate is VisualVM and its Threads tab. Its MBeans plugin allows you to look at both Tomcat's settings and the underlying JVM settings. The relevant JMX objects are java.lang:type=Threading and Catalina:name=ajp-nio-127.0.0.1-9589,type=ThreadPool (or something like it).
 
Bronislav Bronek
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
here is

maxThreads  = (int) The max number of active threads in this pool, default is 200

http://tomcat.apache.org/tomcat-7.0-doc/config/executor.html
 
Tim Moores
Saloon Keeper
Posts: 6531
160
Android Mac OS X Firefox Browser VI Editor Tomcat Server Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That goes goes back to what I said about the server.xml file - that's what counts. By default, no Executor (which is what that page talks about) is active. And the maxThreads setting of the Connector is by default set to 150; see https://github.com/apache/tomcat/blob/master/conf/server.xml

By the way, I hope you're not really using Tomcat 7. Unless there's a pressing reason for it, upgrade to 8.5 or 9, which implement newer versions of the Servlet and JSP APIs. See https://tomcat.apache.org/whichversion.html to help you decide.
 
Bronislav Bronek
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tell me please this -

I have a webSocket server which is runnnig on Tomcat.
Tomcat works in NIO – non-blocking I/O (many more connections than threads) mode.

maxConnections = 1000
maxThreads = 200

Assuming 300 connections for example , all 300 users can be serve by Tomcat ??

I mean, one thred from pool can switch between 2 connections because of 300 > 200 ?
 
Saloon Keeper
Posts: 22289
151
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tomcat has 2 thread pools. One pool services incoming connection requests, one runs the application services (servlets and JSPs).

Tomcat adheres to standard TCP/IP server architecture. It has a Listener for the incoming HTTP port (also for its other ports such as HTTPS, command, and AJP).

When a client sends a request to Tomcat, the Listener dispatches one of the connection threads to handle it. The connection thread is responsible for accepting the request and distilling it into Tomcat internal objects (including the HTTPRequest object). If more connection requests come in than there are connection threads in the pool, the connection request "bounces" and the client is informed that a connection cannot be made. An incoming request may also bounce if the queue of requests received and awaiting processing is full.

Once a request has been distilled and queued internally, the service dispatcher attempts to obtain a Thread for the request service pool. It then passes the request to that thread and initiates the chain of processing calls that ultimately lead into the actual application code itself. Once the application code has finished with the request and returned, the Thread is returned to the request processing pool where it can be handed over to the next waiting request or, if no requests are waiting, the Thread will be placed in the pool's idle queue.
 
Bronislav Bronek
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have maxThreadPool = 200

When I create 250 users and run in the same time I see that all 250 are handled.

Could you explain me how it is posiible. You wrote that where there is not more threads in pool -  the connection request "bounces"
 
Tim Holloway
Saloon Keeper
Posts: 22289
151
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Almost all of the time you spend on a webapp is what in time-sharing days was known as "think" time. In other words, the computer is so much faster than you are that it can do its work and go back to waiting and spend nearly 100% of wall-clock time waiting on the user to think what they'll do next.

HTTP connections are not persistent. You could have 10,000 concurrent users, but odds are good that maybe only 200 of them are actively using the server simultaneously. The rest are in "think" time, and since, as I said, HTTP is not persistent, that means that they are not only not running threads, they're not even connected to the server. Then a user clicks a button and a request needs a thread. And sends a response which requires resources so there's maybe a dozen or more requests for images, CSS, javascript and other page decorations, but those are all very small requests (we hope!) and so they get handled quickly. To truly max out a thread pool, you'd generally need a lot of bots making frequent requests. So for example, web services. Or a DDOS attack.
 
Bronislav Bronek
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What about the situation when I have 250 web socket connections ?

I see that 250 connections are opened
 
Tim Holloway
Saloon Keeper
Posts: 22289
151
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Connections are not the same thing as threads. A single thread may open 1000 connections, if the OS network stack can spare them.

However, please note that all 1000 of them MUST be closed before the thread is returned to the pool!
 
Space seems cool in the movies, but once you get out there, it is super boring. Now for a fascinating tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic