When considering Timeout settings and sources of problematic bottlenecks in ColdFusion applications, a widely held misconception is that all active database connections do not obey timeouts. Discussions surrounding slowness or unresponsiveness in ColdFusion applications often boil down to isolating unusual database activity as the culprit. The explanation provided is often that while the general Timeout in the ColdFusion Administrator, as well as the page level CFSETTING timeout attribute, will be enforced for all page requests except those actively waiting on a response from the database server after a SQL statement has been sent. While this is true, its sometines overlooked that the CFQUERY tag itself has a timeout attribute that is worth considering in some cases. In fact, this particular timeout is something that I've often forgotten, too.

One reason for the confusion over the CFQUERY tag timeout is that not all drivers support it. Of the databases drivers that ship with ColdFusion MX, only the Oracle and SQL Server drivers will enforce the CFQUERY attribute for timeout if it is supplied.

From the ColdFusion documentation for CFQUERY, the timeout attribute is described as:

CFQUERY timeout attribute

Maximum number of seconds that each action of a query is permitted to execute before returning an error. The cumulative time may exceed this value.

For JDBC statements, ColdFusion sets this attribute. For other drivers, check driver documentation.

If you've taken thread dumps to examine what the ColdFusion server was doing at the time of the unresponsiveness or hang, you might find some stacks in the thread dumps that appear to be in a JDBC driver in a socketRead state. These stacks correspond to web requests where the JDBC driver is waiting to receive information back from the database. Its quite normal for web requests to enter this state, so a snapshot taken by a single thread dump is almost meaningless, but if the same thread id appears in the same socketRead state over multiple consecutive thread dumps then you have reason to suspect a slow query or database problem.

In these cases where bottlenecks are present and can be attributed to database queries, then you may want to consider using the timeout attribute of CFQUERY to reduce the risk of completely backing up or hanging the server due to an accumulation of such page requests. The next step would be to consider alternatives to improve query performance such as building faster queries, using views, using cached queries via cachedwithin or a shared scope, or CFQUERYPARAM to cache statements.

So far this blog entry has referred primarily to the CFQUERY tag timeout, which will timeout prolonged, active queries after a database connection has been made. For control over connection timeouts see the CF Admin datasource detail page for the Login Timeout:

Datasource Login Timeout

The number of seconds before ColdFusion MX times out the data source connection login attempt.

The other timeout setting in the CF Admin datasource detail page is just labeled as Timeout, with a paired setting for Interval. This timeout value is how long a connection should be idle before it is removed. So if a connection goes unused for this period of time, then the next time ColdFusion checks that connection it will be removed from the pool. The frequency that ColdFusion checks the connection idle time is set by the Interval setting. The default for the Timeout setting is 20 minutes and the Interval is 7 minutes, so every 7 minutes ColdFusion will check connections for that datasource and remove connections that have been idle for 20 minutes or more. The number of connections idle connections removed from the pool at each interval is hardcoded in ColdFusion to just five. Say you have 20 idle connections hanging around in a pool, this would require at least 28 minutes to be cleaned up.

Timeout (min)
The number of minutes that ColdFusion MX maintains an unused connection before destroying it.

Interval (min)
The time (in minutes) that the server waits between cycles to check for expired data source connections to close.

Getting back to the CFQUERY Timeout attribute, here are some examples of some stacks that you might see in a ColdFusion thread dump where the stack shows a web request waiting on a response from the database:

Oracle (supports timeout)
view plain print about
1"jrpp-749" prio=5 tid=0x010ba3b0 nid=0x24b3 runnable
2 at java.net.SocketInputStream.socketRead0(Native Method)
3 at java.net.SocketInputStream.read(SocketInputStream.java:129)
4 at macromedia.jdbc.oracle.net8.OracleDataProvider.ProcessPacketStartFromSocket(Unknown Source)
5 at macromedia.jdbc.oracle.net8.OracleDataProvider.receive(Unknown Source)
6 at macromedia.jdbc.oracle.net8.OracleDataProvider.getArrayOfBytes(Unknown Source)
7...<br/><br/>"jrpp-21" prio=5 tid=0x2b676af8 nid=0xd5c runnable [0x378ef000..0x378efdb8]
8 at java.net.SocketInputStream.socketRead(Native Method)
9 at java.net.SocketInputStream.read(Unknown Source)
10 at macromedia.util.UtilSocketDataProvider.getArrayOfBytes(Unknown Source)
11 at macromedia.util.UtilBufferedDataProvider.cacheNextBlock(Unknown Source)
12 at macromedia.util.UtilBufferedDataProvider.getArrayOfBytes(Unknown Source)
13 at macromedia.jdbc.oracle.OracleDepacketizingDataProvider.receive(Unknown Source)
14 at macromedia.util.UtilByteArrayDataProvider.receive(Unknown Source)
15 at macromedia.util.UtilByteOrderedDataReader.receive(Unknown Source)
16 at macromedia.jdbc.oracle.net8.OracleNet8NSPTDAPacket.sendRequest(Unknown Source)
17 at macromedia.jdbc.oracle.OracleImplStatement.fetchNext(Unknown Source)
18 at macromedia.jdbc.oracle.OracleImplStatement.execute(Unknown Source)
19 at macromedia.jdbc.base.BaseStatement.commonExecute(Unknown Source)
20 at macromedia.jdbc.base.BaseStatement.executeInternal(Unknown Source)
21 at macromedia.jdbc.base.BasePreparedStatement.execute(Unknown Source)
22 at jrun.sql.JRunPreparedStatement.execute(JRunPreparedStatement.java:142)
23 at coldfusion.sql.Executive.executeQuery(Unknown Source)
24 at coldfusion.sql.Executive.executeQuery(Unknown Source)
25 at coldfusion.sql.SqlImpl.execute(Unknown Source)
26 at coldfusion.tagext.sql.QueryTag.doEndTag(Unknown Source)

SQL Server (supports timeout)
view plain print about
1"jrpp-56" prio=5 tid=0x39b25e68 nid=0x564 runnable [49a1f000..49a1fdb8]
2 at java.net.SocketInputStream.socketRead0(Native Method)
3 at java.net.SocketInputStream.read(SocketInputStream.java:129)
4 at macromedia.jdbc.sqlserver.SQLServerByteOrderedDataReader
5 .readPacketIntoPrimaryBuffer(Unknown Source)
6 at macromedia.jdbc.sqlserver.SQLServerByteOrderedDataReader.receive(Unknown Source)
7 at macromedia.jdbc.sqlserver.tds.TDSRPCRequest.submitRequest(Unknown Source)
8 at macromedia.jdbc.sqlserver.SQLServerImplStatement.execute(Unknown Source)
9 at macromedia.jdbc.base.BaseStatement.commonExecute(Unknown Source)
10 at macromedia.jdbc.base.BaseStatement.executeInternal(Unknown Source)
11 at macromedia.jdbc.base.BasePreparedStatement.execute(Unknown Source)
12 - locked <0x13f0e100> (a macromedia.jdbc.sqlserver.SQLServerConnection)
13 at macromedia.jdbc.base.BasePreparedStatementPoolable.execute(Unknown Source)
14 at coldfusion.server.j2ee.sql.JRunPreparedStatement.execute(JRunPreparedStatement.java:87)
15 at coldfusion.sql.Executive.executeCall(Executive.java:814)
16 at coldfusion.sql.Executive.executeCall(Executive.java:749)
17 at coldfusion.sql.SqlImpl.executeCall(SqlImpl.java:320)
18...<br/><br/>"jrpp-25" prio=5 tid=0x2579ac90 nid=0xc08 runnable [0x2b83e000..0x2b83fdbc]
19 at java.net.SocketInputStream.socketRead(Native Method)
20 at java.net.SocketInputStream.read(Unknown Source)
21 at macromedia.util.UtilSocketDataProvider.getArrayOfBytes(Unknown Source)
22 at macromedia.util.UtilBufferedDataProvider.cacheNextBlock(Unknown Source)
23 at macromedia.util.UtilBufferedDataProvider.getArrayOfBytes(Unknown Source)
24 at macromedia.jdbc.sqlserver.SQLServerDepacketizingDataProvider.signalStartOfPacket(Unknown Source)
25 at macromedia.util.UtilDepacketizingDataProvider.getByte(Unknown Source)
26 at macromedia.util.UtilByteOrderedDataReader.readInt8(Unknown Source)
27 at macromedia.jdbc.sqlserver.tds.TDSRequest.processReply(Unknown Source)
28 at macromedia.jdbc.sqlserver.SQLServerImplStatement.getNextResultType(Unknown Source)
29 at macromedia.jdbc.base.BaseStatement.commonTransitionToState(Unknown Source)
30 at macromedia.jdbc.base.BaseStatement.postImplExecute(Unknown Source)
31 at macromedia.jdbc.base.BaseStatement.commonExecute(Unknown Source)
32 at macromedia.jdbc.base.BaseStatement.executeInternal(Unknown Source)
33 at macromedia.jdbc.base.BaseStatement.execute(Unknown Source)
34 at jrun.sql.JRunStatement.execute(JRunStatement.java:304)
35 at coldfusion.sql.Executive.executeQuery(Unknown Source)
36 at coldfusion.sql.Executive.executeQuery(Unknown Source)
37 at coldfusion.sql.SqlImpl.execute(Unknown Source)

Sybase (does not support timeout)
view plain print about
1"jrpp-79" prio=5 tid=0x858b80 nid=0xdb runnable
2 at java.net.SocketInputStream.socketRead(Native Method)
3 at java.net.SocketInputStream.read(SocketInputStream.java:86)
4 at com.sybase.jdbc2.timedio.RawDbio.reallyRead(RawDbio.java:202)
5 at com.sybase.jdbc2.timedio.Dbio.doRead(Dbio.java:243)
6 at com.sybase.jdbc2.timedio.InStreamMgr.readIfOwner(InStreamMgr.java:512)
7 at com.sybase.jdbc2.timedio.InStreamMgr.doRead(InStreamMgr.java:273)
8 at com.sybase.jdbc2.tds.TdsProtocolContext.getChunk(TdsProtocolContext.java:561)
9 at com.sybase.jdbc2.tds.PduInputFormatter.readPacket(PduInputFormatter.java:229)
10 at com.sybase.jdbc2.tds.PduInputFormatter.read(PduInputFormatter.java:62)
11 at com.sybase.jdbc2.tds.TdsInputStream.read(TdsInputStream.java:81)
12 at com.sybase.jdbc2.tds.TdsInputStream.readUnsignedByte(TdsInputStream.java:114)
13 at com.sybase.jdbc2.tds.Tds.nextResult(Tds.java:1850)

SequeLink ODBC (does not support timeout)
view plain print about
1"jrpp-392" prio=5 tid=0x2C103A78 nid=0xac8 runnable
2 at java.net.SocketInputStream.socketRead0(Native Method)
3 at java.net.SocketInputStream.read(Unknown Source)
4 at java.io.DataInputStream.readFully(Unknown Source)
5 at com.merant.sequelink.net.TrEndPoint.recv(Unknown Source)
6 at com.merant.sequelink.net.Session.channelRecv(Unknown Source)
7 at com.merant.sequelink.net.Session.recv(Unknown Source)
8 at com.merant.sequelink.net.Session.recvIIOPHeader(Unknown Source)
9 at com.merant.sequelink.net.Session.recv(Unknown Source)
10 at com.merant.sequelink.net.Session.recv(Unknown Source)
11 at com.merant.sequelink.net.Session.connect(Unknown Source)
12 at com.merant.sequelink.net.Session.attach(Unknown Source)
13 at com.merant.sequelink.ssp.SspFactory.GetSsp(Unknown Source)
14 at com.merant.sequelink.ctxt.conn.ConnectionContext.doConnect(Unknown Source)
15 at com.merant.sequelink.ctxt.conn.ConnectionContext.connect(Unknown Source)
16 at com.merant.sequelink.jdbc.SequeLinkConnection.<init>(Unknown Source)
17 at com.merant.sequelink.jdbc.SequeLinkDriver.connect(Unknown Source)
18 at macromedia.jdbc.MacromediaDriver.connect(Unknown Source)
19 at jrun.sql.pool.JDBCPool.createPhysicalConnection(JDBCPool.java:599)
20 at jrun.sql.pool.JDBCPool.create(JDBCPool.java:550)
21 at jrun.sql.pool.JDBCPool.checkOut(JDBCPool.java:491)