Steven Erat's Blog Steven Erat Photography
 
 
Viewing By Entry
 
 

TalkingTree  JRun Closed Connection

 

If you've noticed an increase in the frequency of "JRun Closed Connection" errors since having migrated to ColdFusion MX 6.1, then you may want to know one factor that is very likely contributing to that increase.

Speaking generally, web requests from the client browser are recieved by the web server and passed to the JRun webserver connector stub. The webserver connector stub communicates with the JRun server on the JNDI port over TCP/IP, typically port 51010. The web request is sent from the connector to the JRun server, and the JRun server will either assign the request to a JVM thread in the running request pool for immediate execution or JRun will assign the request to a thread in queued request pool if the running pool is full.

The time that a thread is permitted to actively run is governed by the general timeout value in the ColdFusion Administrator on the Settings page, or it can be governed at the page level by the CFSETTING tag attribute 'requesttimeout'. Note that while a running thread is actively waiting on a third party resource such as when waiting for a database result set after having submitted the sql statement, the thread will not timeout. However, if in this example the database does return the query result after the timeout period has expired, the ColdFusion server will throw a timeout exception at that point. Finding error messages in the logs for CFQUERY timeouts is misleading because the thread already waited for some indefinite and lengthy period of time and finally recieved the result, but a timeout exception wouldn't have occurred until after that query completed. If the db result never comes back the thread will remain active in the running request pool indefinitely.

Should a request be assigned to a thread in the queued pool, the thread will wait for an opportunity to run up to some maximum time limit. If the request remains in the queued pool for that maximum period it will be timed out according to the setting threadWaitTimeout in jrun.xml. The timeout will cause JRun server to end the connection to connector for that queued thread, and the connector will report back to the webserver with the error JRun Closed Connection. The browser would show the following unhandled error:

Server Error
The server encountered an internal error and was unable to complete your request.
JRun closed connection.

The other side of the coin is in the default-error.log for that server where the JRun server reports an error based on its perspective:

Request timed out waiting for an available thread to run

In CFMX 6.0 to CFMX 6.0 Updater 3, the threadWaitTimeout value was set to 300 (seconds). This means that a queued request would wait 5 minutes for before timing out if it didn't get a chance to run. In CFMX 6.1, this value was changed to just 20 seconds as a default, and so an application that frequently maintained a large queue while experiencing low throughput would start reporting the connection error with a much higher frequency.

There are several approaches to resolve this.

  • The Simultaneous Requests value could be increased

  • The "slow" pages could be reviewed to determine when, how often, and why they run so long.

  • The queue timeout could be increased

To increase the queue wait timeout:

  1. Find {cfusionmx}/runtime/servers/default/SERVER-INF/jrun.xml

  2. Find the xml node in that file for "jrun.servlet.jrpp.JRunProxyService"

  3. In that node, find <attribute name="threadWaitTimeout">20</attribute>

  4. Edit the value 20 to the desired value in seconds (previously 300)

  5. Restart the CFMX server

While there are other ways to get the 'JRun Closed Connection' error, the unique characteristic to identify the shortened queue timeout problem is to match it up with 'Request timed out waiting for an available thread to run' errors in default-error.log. If you can correlate both errors together, then this is the problem you're having.

Related Links:

Related Blogs:

 


Comments

Thanks. That information is helpfull. My understanding is that the Simultaneous Requests options only works when 6.1 is installed as a standalone app. There is no simulatneous requests option when 6.1 is deployed as a J2EE app on JRun. Any idea on if the threadWaitTimeout also works in a J2EE configuration?


Each J2EE server type (WebSphere, Weblogic, Tomcat, JRun, etc) has its own setting for "Simultaneous Requests", a.k.a. the running thread pool. Very likely they each also have a separate setting for the running thread timeout, the queued thread pool size, and the queued thread timeout.


In CFMX Enterprise and Standard/Pro (which come with an embedded, scaled down version of JRun) this "Simultaneous Request" and (Sim Req) Timeout settings are exposed in the CF Administrator because this is typically a setting users will want to modify to best fit the cpu/hardware/app-type combination. But other values that users don't typically want to modify are not exposed in the CF Admin including queued thread pool size and queued thread timeout. Even though only 2 of the 4 settings described are in the CF Admin, all 4 of the settings are available in the jrun.xml file, usually found in {cfroot}/runtime/servers/default/SERVER-INF/. Near the bottom of the file there is an xml node for jrun.servlet.jrpp.JRunProxyService, and this is the part you want to look for if you're using an external webserver like Apache or IIS.


In CFMX J2EE on JRun, the Simultaneous Request setting is available by modifying the activeHandlerThreads setting in that server instance's jrun.xml file. Similarly, the (Sim Req) Timeout is set in the 'timeout' element, the queue size is set in the maxHandlerThreads, and the queue timeout is the threadWaitTimeout. Each JRun instance has its own jrun.xml, found in {JRunroot}/servers/{servername}/SERVER-INF/.


I can't recall where to configure this the running thread pool size or queued thread pool size in other J2EE servers, and it may be exposed through the J2EE Adminstrator console or only through a config file, but it is there somewhere.



> "Note the changes in: activeHandlerThreads -> from 20 to 400"


That may not be a good thing. The setting activeHandlerThreads is the 'Simultaneous Requests' setting in the CFAdmin. That setting is generally recommended to be 3-5 per cpu, and 400 sounds way out there. Its much better to keep that setting low, while increasing threadWaitTimeout to 300 to permit the queue time to get run.



In JRun4, the jrunx.scheduler.SchedulerService class is responsible for handling all threads related to JDBC Connection pooling. This service is defined in the jrun.xml as a service called SchedulerService. The default settings for this service (I got from decompiling the class since there are no settings in the jrun.xml) are MaxHandlerThreads = 20, MinHandlerThreads = 1, ActiveHandlerThreads = 10, ThreadWaitTimeout = 20. When a JSP page makes use of a db connection from the connection pool, the SchedulerService is responsible for getting the connection and spawning a thread for its use. But if all the threads are currently being used, then the request goes into the queued pool and waits for a thread to become available. If none are available within the ThreadWaitTimeout timeframe, then the "Request timed out waiting for an available thread to run" error is generated.


My question for you is this: since the MaxHandlerThreads is set to 20, then there can be only 20 active database connections (from the pool) being used at the same time (since each connection needs a new thread). All other requests for a pooled connection get stuck in the thread queue and wait for a free SchedulerService thread. Is this a design flaw for JRun? What is the point of the DB Connection pool settings if the rules for those connections in the end are governed by the settings for the SchedulerService? Other then increasing the number of available treads for the SchedulerService, is there anything else that I can do?


The reason I ask this question is because at my company, we recently went live with an application that runs on JRun4 and Oracle. We have been getting the "no threads" issues almost daily. This can mostly be attributed to issues we were having with our database. Once the database has problems, the db connections start to hang, then all of the SchedulerService threads get used up and requests for new connections start to time out. The only way we can recover from this is to restart the JRun server (since our users still try to access the application, which never lets the thread pool recover). Granted, our main issue was the result of the database, but my researching of the issues brought this "design flaw" of JRun to my attention.


Based on your experience, can you verify what I said is fact? I am still new to JRun, so I want to be sure that my conclusions are correct.



I'm following Ted around the internet today (saw his post on MMs forums as well) seeing if anyone has an answer for his question as I am seeing the same issues.



-Adam



This conversation was carried out via email for anyone wondering where the discussion went. I wasn't really sure how Ted's or Adam's questions were relevant to this blog entry, but they seemed to be inquiring about the relationship between running web request thread pool and the datasource connection pool. I offered this explanation about that relationship:


First a little background that might be relevant...


A connection pool is unique according to the database server, database, username/password. A second ColdFusion datasource to the same database server for the same database (or schema/catalog) but having a different username/password will have a separate connection pool from the first.


If the activeHandlerThreads (Simultaneous Request) setting is 10, for example, then for any given datasource connection pool you can expect that a maximum number of 10 database connections from that pool *could* be made if all 10 threads were all using the datasource at the same time and the query was sufficiently long to be noticeable.


When the query tag finishes and there are no more queries for that datasource on that page, then the db connection will be released and the ColdFusion request could continue on to run other queries or other code in that page until the page end. The point here is that ColdFusion runs queries from a single request in series, not in parallel. A single ColdFusion request will have at maximum one database connection at a time.


If there are 3 datasources to the same database server and database, but each with a different username/password, then there will be 3 connection pools for that. If there the Simultaneous Requests setting is 10 and a given page has three queries, one to each datasource, and each query was sufficiently long to be noticeable, then you might see a total of 30 connections from the ColdFusion server on the database server side.


Now to your question as I understand it...


The ColdFusion JRunProxyService thread pool (the actual jrpp threads that handle web requests) is not the same as the threads in a database connection pool. The *expected* upper limit on the number of connections in a single connection pool would be equal to the upper limit of activeHandlerThreads (Simultaneous Requests). Although, there are abnormal situations in which the *actual* number of connections may exceed that expected limit. There may be reasons why you would want to explicitly set a connection pool size limit, say you had two CF servers each with 10 requests but you were working with a limited version of SQL Server where you license limited you to a total of 10 connections. In that case you might exceed the database license and you'd want to limit the number of connections in CF to 5 connections on each of the two CF servers.


Finally, I don't know what this has to do with the JRun Closed Connection error message described in the blog entry you replied to. How is this question related to that blog?


Steve



"Finally, I don't know what this has to do with the JRun Closed Connection error message described in the blog entry you replied to. How is this question related to that blog?"


If you have hung threads or very long processes that are not getting timed out you will get this error here is some more info on how to config the Jrun Scheduler service to make sure this does not happen as often http://www.robisen.com/index.cfm?mode=entry&entry=FD4BE2FC-55DC-F2B1-FED0717CC1C7E0AF.



I was not aware of it either until someone asked me to blog that. Interestingly enough when I was looking at this MM basically just told my client it was their code even though they had paid support. I spent a lot of time looking into it and actually found information pointing to this on an ibm websphere site. Its nice to see now that MM recognizes this is a issue and it would be nice to see something like there proxy server recommendations for jrun. Funnily enough if you look at the blackstone jrun.xml they have not corrected it their either. Unfortunately allot of people are having issues with this and it really makes CF look bad especially since its so easy to deal with if you just have long running requests.



I was not aware of it either until someone asked me to blog that. Interestingly enough when I was looking at this MM basically just told my client it was their code even though they had paid support. I spent a lot of time looking into it and actually found information pointing to this on an ibm websphere site. Its nice to see now that MM recognizes this is a issue and it would be nice to see something like there proxy server recommendations for jrun. Funnily enough if you look at the blackstone jrun.xml they have not corrected it their either. Unfortunately allot of people are having issues with this and it really makes CF look bad especially since its so easy to deal with if you just have long running requests.



Has this issue received any further attention? I also decompiled the class (in this case the class was ThreadPoolService which SchedulerService extends). Here's the constructor:

public ThreadPoolService()

threadPool = new ThreadPool(getMetricsPrefix())
setMaxHandlerThreads(20)
setMinHandlerThreads(1)
setActiveHandlerThreads(10)
setThreadWaitTimeout(20)


As you can see, the values are *hard coded*. So how does setting any parameters for SchedulerService in hava.xml do anything?


JB,

As you know its common to pass values in the constructor to make valid object. As for seeing how it effects things its very easy to see the effect in a demonstable fashion. Use a load testing tool to create a base line for your applications performance.
Gather your stats.
Then change your settings and try again. See if performance changes or issue changes.


Hi Steven,

I'm using coldfusion MX 7. I think like many i am getting the following error.

Server Error
The server encountered an internal error and was unable to complete your request.
JRun closed connection.


I have googled the problem and brought up hundreds of pages none that are able to solve my specific problem. I think i might be the victim of a hack or exploit (or call me paranoid). I am running cold fusion on 2 seperate servers. These servers are on 2 seperate networks. However sometime 2 days ago, both servers started repeatedly throwing this error. at first i thought it was an isolated incident, and then again and again. then the other server... now, i am at the point where the servers will run for 5 minutes or so and then completely stop, i'll wait for them to timeout (the standard 300 seconds) and the Jrun Closed Connection error throws as above. I've changed the timeout to seconds, but all that did was make it timeout faster, still got the error.

I'm normally now only able to successfully open a few requests to jrun before throwing this error. I'm running windows 2K3 standard edition. I'm using SQL server 2000 (on a seperate server) and connecting via Microsoft SQL server ODBC connection through CF Admin. both boxes have a gig of ram and are on dedicated 10 meg connections running single p4 processors.

Any thoughts, comments, suggestions on what i can do to prevent this from happening?

Regards,

Alex


Alex,

Don't troubleshoot the queue. Do troubleshoot what's running. The server is probably experiencing some bottlenecks in the application causing the server to back up. Use thread dumps to figure out what's causing the problem.

About Thread Dumps here on this blog:

http://www.talkingtree.com/blog/index.cfm?mode=sea...


Interested in reading this last posted link- but it fails...

About Thread Dumps here on this blog:
http://www.talkingtree.com/blog/index.cfm?mode=sea...

Thanks - Jordan Gray


Alex, did you get ever get this figured out? I'm having the same problem, and I'd love to hear how you resolved this.


 

 

Calendar

 
Sun Mon Tue Wed Thu Fri Sat
  1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 31      

Search This Site

 
This is an exact search only

About This Site

 
I live west of Boston and work as a Software Engineer with ColdFusion and Flex, specializing in Linux. Recently I graduated in Professional Digital Photography from CDIA.
More about me

Recent Entries

 
A ColdFusion Trick for Lost D..
Starting ColdFusion9 Solr: Us..
Adobe LiveCycle DataServices ..

Recent Comments

 
Posted By Aaron Longnion:
Thanks Steven, I just ran into this problem, remembered your tweet about it, and found your blog on it. :)

Posted By srinyvas:
Hai, This information is very useful and i like your excellent writing skill. Can i copy this Content to my website top management colleges ...

Posted By Steven Erat:
@Wade - Glad I could help! Thanks for letting me know it worked for you too.

recently played

 
The Candid Frame #70 - Greg Gorman
by Ibarionex R. Perello
on The Candid Frame: A Photography Podcast

now playing, a plug-in for itunes

Categories

 
RSS Adobe (34)
RSS Bicycling (9)
RSS Blogging (39)
RSS Books (13)
RSS Breeze (13)
RSS CFMX Podcasts (10)
RSS ColdFusion (427)
RSS Computer Technology (51)
RSS Events (26)
RSS Flex (20)
RSS Gadgets (10)
RSS HiTech Industry (16)
RSS Java (25)
RSS Learning (57)
RSS Linux (70)
RSS Mac OS X (22)
RSS Macromedia (27)
RSS Meetup (35)
RSS New England (62)
RSS Odds & Ends (25)
RSS Outdoors (32)
RSS Personal (29)
RSS Photography (111)
RSS Photoshop (29)
RSS Podcasts (18)
RSS Rants (19)
RSS Restaurants (8)
RSS Science (34)
RSS Spain (16)
RSS Travel (42)
RSS Twitter (10)
RSS Video (20)
RSS Webcam (3)
RSS Writing (10)

Blogs I Read

 
Terrence Ryan
Ben Forta
Ray Camden
Kinky Solutions
Dan Vega
Gary Gilbert
Simeon Bateman
Red Hat Blogs
O'Reilly Digital Media
O'Reilly Radar
John Nack
The Strobist
Scott Kelby
Matt Kloskowski
Joe McNally
Digital Photography School
Engadget
Science Blog

RSS

 


Add to Google
Add to My Yahoo!

Aggregated By

 


Consumed By Feed-Squirrel.com
Aggregated by ColdFusionBlogger.org

Credits and Stuff

 
BlogCFC - Free ColdFusion Powered Blog Software
CJM Group - ColdFusion Website Hosting


 
 
blog | photos | flickr | referers | webcam | stats | about | contact
 
Copyright © 2010 Steven Erat. All rights reserved.
This is a personal weblog. The opinions expressed here represent my own and not those of my employer