Bug 1203510

Summary: [GSS](6.4.z) Http11NioProtocol connector does not count currentThreadCount and currentThreadsBusy
Product: [JBoss] JBoss Enterprise Application Platform 6 Reporter: Osamu Nagano <onagano>
Component: WebAssignee: Enrique Gonzalez Martinez <egonzale>
Status: CLOSED CURRENTRELEASE QA Contact: Radim Hatlapatka <rhatlapa>
Severity: unspecified Docs Contact:
Priority: unspecified    
Version: 6.3.1CC: bmaxwell, egonzale, ihradek, jtruhlar, msochure, rmaucher
Target Milestone: CR1   
Target Release: EAP 6.4.11   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2017-01-17 13:10:51 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Bug Depends On:    
Bug Blocks: 1316573, 1361648    
Attachments:
Description Flags
sample.war
none
patch jboss 7.5.x egonzale: review? (rmaucher)

Description Osamu Nagano 2015-03-19 03:05:24 UTC
Description of problem:
When you use WebSocket, either Http11NioProtocol or Http11AprProtocol should be configured as http connector in web subsystem.  But if Http11NioProtocol is used, currentThreadCount and currentThreadsBusy of MBean "jboss.web:type=ThreadPool,name=http--0.0.0.0-8080" are always zeros and a user cannot monitor those important metrics.
It seems src/main/java/org/apache/tomcat/util/net/NioEndpoint.java is not incrementing those statistics.


Version-Release number of selected component (if applicable):
jbossweb-7.4.8.Final-redhat-4.jar


How reproducible:
Always.


Steps to Reproduce:
1. Start a standalone server with the following configuration.
~~~
    <system-properties>
        <property name="org.apache.tomcat.util.ENABLE_MODELER" value="true"/>
    </system-properties>
    ...
        <subsystem xmlns="urn:jboss:domain:web:2.1" default-virtual-server="default-host" native="false">
            <connector name="http" protocol="org.apache.coyote.http11.Http11NioProtocol" scheme="http" socket-binding="http"/>
            ...
        </subsystem>
~~~

2. Deploy a web app with a servlet that just sleeps.
Attached sample.war which just sleeps for 3 mins when you access "http://hostname:8080/sample/sample".

3. Monitor MBean attributes for "jboss.web:type=ThreadPool,name=http--0.0.0.0-8080" using jconsole.sh.


Actual results:
  jboss.web:type=ThreadPool,name=http--0.0.0.0-8080
    currentThreadCount: 0
    currentThreadsBusy: 0


Expected results:
Non-zero values should be observed.


Additional info:
Http11AprProtocol doesn't have this bug and can be a workaround.  Install Native Components of your platform and enable <subsystem xmlns="urn:jboss:domain:web:2.1" native="true">.

Comment 1 Osamu Nagano 2015-03-19 03:06:38 UTC
Created attachment 1003572 [details]
sample.war

Comment 2 Rémy Maucherat 2015-03-19 08:57:45 UTC
I cannot implement this, so dev-. NIO2 has to use an executor rather than the old internal pool, which won't provide statistics.

Instead, if an executor is configured in AS and set on the connector, then its statistics should be available.

Comment 3 Osamu Nagano 2015-03-25 01:57:50 UTC
Custom executor can be configured as follows:

~~~
/subsystem=threads/blocking-bounded-queue-thread-pool=nio2-connector:add(core-threads=10,max-threads=20,queue-length=10)
/subsystem=web/connector=http:write-attribute(name=executor,value=nio2-connector)
~~~

But threads subsystem has another bug, Bug 1021911, where active-count is missing.

~~~
[standalone@localhost:9999 /] ls -l /subsystem=threads/blocking-bounded-queue-thread-pool=nio2-connector
ATTRIBUTE            VALUE          TYPE    
allow-core-timeout   false          BOOLEAN 
core-threads         10             INT     
current-thread-count 2              INT     
keepalive-time       undefined      OBJECT  
largest-thread-count 2              INT     
max-threads          20             INT     
name                 nio2-connector STRING  
queue-length         10             INT     
queue-size           0              INT     
rejected-count       0              INT     
thread-factory       undefined      STRING  
~~~

According to JBTHR-25, it will be not fixed because WFLY-462 is going to eliminate threads subsystem.  So workaround of APR connector should be adopted.

Comment 6 Enrique Gonzalez Martinez 2015-05-07 09:06:23 UTC
Hi @Remy

I think it's possible to provide the stats with the default case. There is a workaround based on two different calls in the ThreadPoolExecutor getActiveCount and getPoolSize. By default NioEndpoint creates a ThreadPoolExecutor during init call so if the executor is an instance of ThreadPoolExecutor, at least we can provide the stats.

i.e (NioEndpoint): 

public int getCurrentThreadCount() {
   return (this.executor instanceof ThreadPoolExecutor) ? ((ThreadPoolExecutor) this.executor).getPoolSize() : getCurThreads();
}

public int getCurrentThreadsBusy() {
   return (this.executor instanceof ThreadPoolExecutor) ? ((ThreadPoolExecutor) this.executor).getActiveCount() : getCurThreadsBusy();
}

Could this be ok Remy ?

Comment 7 Rémy Maucherat 2015-05-07 14:37:17 UTC
I suppose it doesn't hurt.

Comment 8 Enrique Gonzalez Martinez 2015-05-07 15:15:03 UTC
Created attachment 1023190 [details]
patch jboss 7.5.x

PR sent

Comment 13 Enrique Gonzalez Martinez 2016-09-01 11:12:24 UTC
patch is up. This should be on POST.

Comment 18 Ivo Hradek 2016-10-04 06:49:24 UTC
Verified with EAP 6.4.11.CP.CR1;

Comment 19 Petr Penicka 2017-01-17 13:10:51 UTC
Retroactively bulk-closing issues from released EAP 6.4 cummulative patches.