Hi,

On Tue, May 20, 2025 at 12:57 PM Rose Mary P T
<rose.mary...@ibm.com.invalid> wrote:
>
> HI Mark,
>
>
> Just a gentle reminder regarding my previous message. I’m following up to see 
> if there’s any update on this as its pending for long.
>
> As per your previous suggestion ,I was able to fetch the connectioncount. But 
> the KeepAliveCount was always showing as zero. Given this behavior, I’m 
> curious to know whether the formula: (connectionCount – keepAliveCount)
>
> Can we consider using ProtocolHandler.connectionCount to fetch the virtual 
> threads created instead.
>
> Please let me know if you need any further information from my side.

I investigated following your emails. Here are my comments:
- As Mark said, using an Executor for virtual threads is pointless.
Executor elements are used to share a single thread pool between
multiple NIO connectors, and since there's no pool, then there's no
point in using it.
- There was a missing flag in JMX for useVirtualThreads. The flag was
added recently, and was not added to the mbean. This is now fixed and
it will allow easily identifying a connector that uses virtual
threads.
- The keepAliveCount returned the wrong value for NIO. This is fixed.

Let us know if you find other problems.

Rémy

> Looking forward to your response
>
> Regards,
> Rose Mary
>
> From: Rose Mary P T <rose.mary...@ibm.com.INVALID>
> Date: Tuesday, 20 May 2025 at 4:07 PM
> To: Tomcat Users List <users@tomcat.apache.org>
> Subject: [EXTERNAL] RE: Monitoring Virtual Threads via JMX / MBeans in Tomcat
> HI Mark,
>
>
> Just a gentle reminder regarding my previous message. I’m following up to see 
> if there’s any update on this. Please let me know if you need any further 
> information from my side.
>
> Looking forward to your response.
>
>
>
> Regards,
>
> Rose Mary
>
>
> From: Rose Mary P T <rose.mary...@ibm.com.INVALID>
> Date: Friday, 11 April 2025 at 7:08 PM
> To: Tomcat Users List <users@tomcat.apache.org>, ma...@apache.org 
> <ma...@apache.org>
> Subject: [EXTERNAL] RE: Monitoring Virtual Threads via JMX / MBeans in Tomcat
> Dear Tomcat Users/Mark,
> I was finally able to retrieve the thread name from the workerThreadName 
> attribute in RequestProcessor.tomcatExecutor for a request. In order to 
> observe this, the request had to be long-running, which allowed JMX to 
> capture the thread’s active state before it completed.
> However, I’ve observed that the keepAliveCount remains zero in this setup as 
> well. Additionally, the connectionCount appears to reflect the number of 
> incoming requests at that moment, but resets to 1 once the request has 
> completed processing.
> Given this behavior, I’m curious to know whether the formula: 
> (connectionCount – keepAliveCount)
> is still considered a reliable way to determine the number of virtual threads 
> that are created or active at any point in time when using 
> useVirtualThreads="true".
> I would appreciate any insights or clarifications on this.
> Thanks,
> Rose Mary
>
>
> From: Mark Thomas <ma...@apache.org>
> Date: Wednesday, 9 April 2025 at 4:12 PM
> To: users@tomcat.apache.org <users@tomcat.apache.org>
> Subject: [EXTERNAL] Re: Monitoring Virtual Threads via JMX / MBeans in Tomcat
>
>
> On 03/04/2025 13:05, Rose Mary P T wrote:
> > HI Mark,
> >
> > Thanks for your response.
> >
> > I would like to seek your guidance regarding an issue I am encountering
> > with my current Tomcat setup. Specifically, your recent suggestions
> > appear to contradict my existing configuration. Could you kindly confirm
> > whether the following executor and connector setup in Tomcat 10.1.36 is
> > correct?
> >
> > <Executor name="tomcatExecutor" namePrefix ="test"
> > className="org.apache.catalina.core.StandardVirtualThreadExecutor"/>
> >
> > <Connector port="8080" protocol="org.apache.coyote.http11.Http11NioProtocol"
> >
> > connectionTimeout="18000" redirectPort="8443"
> >
> > executor="tomcatExecutor"
> >
> > useVirtualThreads="true"/>
>
> That should work. Although I do wonder on why you have configured an
> executor here. There isn't really any point with virtual threads.
>
> > In my setup, I am using *Http11NioProtocol* exclusively. However, I am
> > noticing the following:
> >
> >   * *keepAliveCount* remains zero.
> >   * *connectionCount* is consistently reported as 1.
>
> That suggests that the Tomcat instance isn't processing any requests.
>
> >   * There is no visible value for |RequestProcessor#workerThreadName|.
> >     Please see the screenshot :
>
> Screenshots don't work on the mailing list. Post it somewhere we can
> look at it.
>
> Mark
>
> > *
> >
> > I would greatly appreciate your insight into this matter, especially if
> > the configuration provided requires any adjustments or if there are
> > specific conditions I need to be aware of for the virtual threads to
> > function as expected.
> >
> > To clarify your previous question on the deployed application in
> > tomcat : This is a simple spring boot application which prints current
> > date in a loop of 100
> >
> > Thank you for your time and assistance. I look forward to your response.
> >
> > Regards,
> >
> > Rose Mary
> >
> > *From: *Mark Thomas <ma...@apache.org>
> > *Date: *Thursday, 3 April 2025 at 2:49 PM
> > *To: *users@tomcat.apache.org <users@tomcat.apache.org>
> > *Subject: *[EXTERNAL] Re: Monitoring Virtual Threads via JMX / MBeans in
> > Tomcat
> >
> > On 28/03/2025 09:08, Rose Mary P T wrote:
> >> Hi Mark,
> >> Thank you for the confirmation.
> >> As per your suggestion, I have modified the deployed application so that 
> >> it no longer spawns any threads but instead executes a few calls.
> >
> > Please clarify what you mean by "executes a few calls".
> >
> >> Additionally, I kept the previous executor and connection configurations 
> >> for Tomcat. However, I still do not see any noticeable changes in the 
> >> keepAliveCount attribute. The connectionCount currently shows a value of 1.
> >> At this point, I'm unsure of the next troubleshooting steps or what 
> >> specific aspects to investigate further. Any guidance on what to focus on 
> >> next would be greatly appreciated.
> >> Additionally, could you suggest if there is any MBean attribute that can 
> >> help identify whether the threads being used are virtual threads or 
> >> platform threads?
> >
> > For Tomcat requests, the current thread name includes "virt" if it is a
> > virtual thread. Look at RequestProcessor#workerThreadName for one place
> > to see the thread names used for requests
> >
> > With NIO2, keepAliveCount will always be -1 as it isn't tracked.
> > Switching to NIO would make keepAliveCount available.
> >
> > connectionCount will always be 1 more than the current connections. i.e.
> > a value of 1 means there are no current requests.
> >
> > Mark
> >
> >
> >> Thank you for your continued support.
> >>
> >> Best Regards,
> >> Rose Mary
> >>
> >>
> >> From: Mark Thomas <ma...@apache.org>
> >> Date: Thursday, 27 March 2025 at 9:25 PM
> >> To: users@tomcat.apache.org <users@tomcat.apache.org>
> >> Subject: [EXTERNAL] Re: Monitoring Virtual Threads via JMX / MBeans in 
> >> Tomcat
> >> On 26/03/2025 10:38, Rose Mary P T wrote:
> >>> Dear Tomcat Users,
> >>> I hope this message finds you well.
> >>> As per your previous email, we attempted to fetch the virtual thread 
> >>> count from the keepAliveCount attribute in the Catalina.ThreadPool MBean.
> >>> For context, here is the setup we used:
> >>>
> >>>     *   We created a sample Spring Boot application that continuously 
> >>> creates virtual threads in a loop.
> >>
> >> If the application is creating the threads then this won't work. The
> >> (connectionCount - keepAliveCount) approach only works for virtual
> >> threads created by Tomcat for processing requests.
> >>
> >> If the application is creating the virtual threads then I'd suggest
> >> adding tracking for the current number of virtual threads to the
> >> application.
> >>
> >> Mark
> >>
> >>>     *   The application was deployed in the TOMCAT_LOCATION/webapps 
> >>> directory and started on localhost.
> >>> In Apache Tomcat 10.1.36, we added the following configuration to the 
> >>> server.xml file to enable virtual threads:
> >>> <Executor name="tomcatExecutor" 
> >>> className="org.apache.catalina.core.StandardVirtualThreadExecutor"/>
> >>> <Connector port="8080" 
> >>> protocol="org.apache.coyote.http11.Http11NioProtocol"
> >>>               connectionTimeout="18000" redirectPort="8443"
> >>>               executor="tomcatExecutor"
> >>>               useVirtualThreads="true"/>
> >>>
> >>> Its observed in the logs that virtual threads were being created as 
> >>> expected. However, we noticed that the keepAliveCount attribute in the 
> >>> Catalina.ThreadPool MBean is showing a value of 0, even though virtual 
> >>> threads are being spawned.
> >>> It seems that the keepAliveCount attribute does not provide a valid value 
> >>> for counting the virtual threads. We were wondering if this is expected 
> >>> behavior, or if there is a different way to monitor the virtual threads 
> >>> created in Tomcat.
> >>> We would also like to know if there's a way to differentiate between 
> >>> platform threads and virtual threads using any MBean attribute in the 
> >>> Catalina service or elsewhere in Tomcat's MBean architecture.
> >>> We would greatly appreciate any guidance or insights you can provide 
> >>> regarding this issue.
> >>> Best Regards,
> >>> Rose Mary
> >>>
> >>>
> >>>
> >>> From: Joash Jose <joash.j...@ibm.com>
> >>> Date: Wednesday, 26 March 2025 at 12:48 PM
> >>> To: Rose Mary P T <rose.mary...@ibm.com>
> >>> Subject: <no subject>
> >>>
> >>>
> >>>
> >>> Begin forwarded message:
> >>>
> >>> From: Mark Thomas <ma...@apache.org>
> >>> Subject: [EXTERNAL] Re: Monitoring Virtual Threads via JMX / MBeans in 
> >>> Tomcat
> >>> Date: 6 March 2025 at 2:08:43 PM IST
> >>> To: <users@tomcat.apache.org>
> >>> Reply-To: "Tomcat Users List" <users@tomcat.apache.org>
> >>>
> >>> On 06/03/2025 06:29, Joash Jose wrote:
> >>>
> >>> Dear Apache Tomcat Support Team,
> >>> I hope this message finds you well.
> >>> I am writing to inquire whether Apache Tomcat (tomacat version is 10.1.33 
> >>> running on Java 21)  exposes virtual thread metrics through JMX / MBeans. 
> >>> Specifically:
> >>> Virtual Thread Visibility:
> >>> Does Tomcat provide MBeans (e.g., under Catalina:type=Executor) to 
> >>> monitor virtual thread usage, such as active virtual thread counts, 
> >>> creation rate, or parking states?
> >>>
> >>> No with a few caveats - see below).
> >>>
> >>>
> >>> If not, are there plans to add such metrics in future releases?
> >>>
> >>> No.
> >>>
> >>>
> >>> Or any alternate ways with which we can monitor this from tomcat side.?
> >>>
> >>> (connectionCount - keepAliveCount) should be a reasonable estimate of the 
> >>> virtual threads currently being used.
> >>>
> >>> If the requests are synchronous (and there is little point using virtual 
> >>> threads with async requests) then the creation rate is derivable from the 
> >>> requestCount in the GlobalRequestProcessor.
> >>>
> >>> There is no information on parking states.
> >>>
> >>>
> >>> Configuration Clarification:
> >>> We have configured Tomcat 10.1.33 with,
> >>> <Executor name="tomcatThreadPool" 
> >>> className="org.apache.catalina.core.StandardVirtualThreadExecutor"/>
> >>> <Connector port="8080" 
> >>> protocol="org.apache.coyote.http11.Http11Nio2Protocol" 
> >>> connectionTimeout="18000" socket.soTimeout="18000" redirectPort="8443" 
> >>> enableLookups="false" URIEncoding="UTF-8" compression="on" 
> >>> useVirtualThreads="true" server="ARandomServer"/>
> >>>
> >>> The <Executor .../> element isn't being used. Why configure it?
> >>>
> >>>
> >>> While this works, the existing ThreadPool MBeans show 
> >>> currentThreadsBusy=-1 and maxThreads=200 (incorrect in case of virtual 
> >>> threads). Is this expected behavior?
> >>>
> >>> Yes.
> >>>
> >>>
> >>> JVM vs. Tomcat Metrics:
> >>> We observe that the JVM’s java.lang.management.ThreadMXBean includes 
> >>> virtual threads, but this aggregates data across all applications on the 
> >>> JVM. Does Tomcat offer a way to isolate virtual thread metrics specific 
> >>> to Tomcat?
> >>>
> >>> No, because the JVM doesn't provide a mechanism to have multiple 
> >>> pools/groups/anything of virtual threads.
> >>>
> >>> Mark
> >>>
> >>>
> >>> ---------------------------------------------------------------------
> >>> To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
> >>> For additional commands, e-mail: users-h...@tomcat.apache.org
> >>> Begin forwarded message:
> >>>
> >>> From: Joash Jose <joash.j...@ibm.com>
> >>> Subject: Monitoring Virtual Threads via JMX / MBeans in Tomcat
> >>> Date: 6 March 2025 at 11:59:29 AM IST
> >>> To: <d...@tomcat.apache.org>, <users@tomcat.apache.org>
> >>>
> >>> Dear Apache Tomcat Support Team,
> >>>
> >>> I hope this message finds you well.
> >>>
> >>> I am writing to inquire whether Apache Tomcat (tomacat version is 10.1.33 
> >>> running on Java 21)  exposes virtual thread metrics through JMX / MBeans. 
> >>> Specifically:
> >>>
> >>> Virtual Thread Visibility:
> >>>
> >>> Does Tomcat provide MBeans (e.g., under Catalina:type=Executor) to 
> >>> monitor virtual thread usage, such as active virtual thread counts, 
> >>> creation rate, or parking states?
> >>> If not, are there plans to add such metrics in future releases?
> >>> Or any alternate ways with which we can monitor this from tomcat side.?
> >>>
> >>> Configuration Clarification:
> >>> We have configured Tomcat 10.1.33 with,
> >>> <Executor name="tomcatThreadPool" 
> >>> className="org.apache.catalina.core.StandardVirtualThreadExecutor"/>
> >>> <Connector port="8080" 
> >>> protocol="org.apache.coyote.http11.Http11Nio2Protocol" 
> >>> connectionTimeout="18000" socket.soTimeout="18000" redirectPort="8443" 
> >>> enableLookups="false" URIEncoding="UTF-8" compression="on" 
> >>> useVirtualThreads="true" server="ARandomServer"/>
> >>> While this works, the existing ThreadPool MBeans show 
> >>> currentThreadsBusy=-1 and maxThreads=200 (incorrect in case of virtual 
> >>> threads). Is this expected behavior?
> >>>
> >>> JVM vs. Tomcat Metrics:
> >>> We observe that the JVM’s java.lang.management.ThreadMXBean includes 
> >>> virtual threads, but this aggregates data across all applications on the 
> >>> JVM. Does Tomcat offer a way to isolate virtual thread metrics specific 
> >>> to Tomcat?
> >>>
> >>> Regards,
> >>> Joash
> >>> Begin forwarded message:
> >>>
> >>> From: Joash Jose <joash.j...@ibm.com.INVALID>
> >>> Subject: [EXTERNAL] Monitoring Virtual Threads via JMX / MBeans in Tomcat
> >>> Date: 6 March 2025 at 11:59:40 AM IST
> >>> To: "d...@tomcat.apache.org" <d...@tomcat.apache.org>, 
> >>> "users@tomcat.apache.org" <users@tomcat.apache.org>
> >>> Reply-To: "Tomcat Users List" <users@tomcat.apache.org>
> >>>
> >>> Dear Apache Tomcat Support Team,
> >>>
> >>> I hope this message finds you well.
> >>>
> >>> I am writing to inquire whether Apache Tomcat (tomacat version is 10.1.33 
> >>> running on Java 21)  exposes virtual thread metrics through JMX / MBeans. 
> >>> Specifically:
> >>>
> >>> Virtual Thread Visibility:
> >>>
> >>> Does Tomcat provide MBeans (e.g., under Catalina:type=Executor) to 
> >>> monitor virtual thread usage, such as active virtual thread counts, 
> >>> creation rate, or parking states?
> >>> If not, are there plans to add such metrics in future releases?
> >>> Or any alternate ways with which we can monitor this from tomcat side.?
> >>>
> >>> Configuration Clarification:
> >>> We have configured Tomcat 10.1.33 with,
> >>> <Executor name="tomcatThreadPool" 
> >>> className="org.apache.catalina.core.StandardVirtualThreadExecutor"/>
> >>> <Connector port="8080" 
> >>> protocol="org.apache.coyote.http11.Http11Nio2Protocol" 
> >>> connectionTimeout="18000" socket.soTimeout="18000" redirectPort="8443" 
> >>> enableLookups="false" URIEncoding="UTF-8" compression="on" 
> >>> useVirtualThreads="true" server="ARandomServer"/>
> >>> While this works, the existing ThreadPool MBeans show 
> >>> currentThreadsBusy=-1 and maxThreads=200 (incorrect in case of virtual 
> >>> threads). Is this expected behavior?
> >>>
> >>> JVM vs. Tomcat Metrics:
> >>> We observe that the JVM’s java.lang.management.ThreadMXBean includes 
> >>> virtual threads, but this aggregates data across all applications on the 
> >>> JVM. Does Tomcat offer a way to isolate virtual thread metrics specific 
> >>> to Tomcat?
> >>>
> >>> Regards,
> >>> Joash
> >>> ---------------------------------------------------------------------
> >>> To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
> >>> For additional commands, e-mail: users-h...@tomcat.apache.org
> >>>
> >>
> >>
> >> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
> >> For additional commands, e-mail: users-h...@tomcat.apache.org
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
> > For additional commands, e-mail: users-h...@tomcat.apache.org
> >
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
> For additional commands, e-mail: users-h...@tomcat.apache.org

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org

Reply via email to