You are viewing a plain text version of this content. The canonical link for it is here.
Posted to derby-user@db.apache.org by Kristian Waagan <Kr...@Sun.COM> on 2006/11/10 11:30:26 UTC

Re: Derby causes appserver hang with "maxthreads"

(This question was asked in derby-dev, but I replied to derby-user).

Jagadish Prasath Ramu wrote:
> Hi,
> I am investigating an issue where Sun Application server hangs
> "temporarily"/"permanently" while talking to Derby Server.
> 
> I could not reproduce the temporary hang. However I could make the hang
> permanent.
> 
> Permanent Hang Steps :
> 
> derby.properties will have the following settings:
> derby.drda.maxThreads=32
> derby.drda.timeslice=2000
> 
> In appserver connection-pool, steady-pool-size is 34 (when the pool is
> initialized 34 connections will be created).

Hi Jagadish,

I can easily reproduce this with ij, for instance by setting 
derby.drda.maxThreads to two and then making three connections to the 
network server.

On the third connection, ij hangs. If I disconnect one of the other two, 
the third connection "unhangs".

To me it seems Derby will not handle more concurrent connections than 
specified by maxThreads.


 From the Admin guide:
"derby.drda.maxThreads

Use the derby.drda.maxThreads property to set a maximum number of 
connection threads that Network Server will allocate. If all of the 
connection threads are currently being used and the Network Server has 
already allocated the maximum number of threads, the threads will be 
shared by using the derby.drda.timeslice property to determine when 
sessions will be swapped.
Syntax

derby.drda.maxThreads=numthreads

Default
0"

After some brief investigation, I found out that the value of timeSlice 
is set to 0. This means the session owns the thread until it 
disconnects. When I tried to set the timeSlice (tried value 2000, used 
NetworkServerControl to set it), the third connection succeeded, but it 
failed when I issued a query on it (see error message below).

I would like to get some feedback from people knowing the state of this 
code/feature. To me this looks like a bug, but I do not know the 
severity/extent of it.



-- 
Kristian

[server (five first lines are my printlns)]
Timeslice: 2000
state: 1 > 2000
state: 3 > 2000
state: 9632 > 2000
Exited, state: 9636 > 2000
Execution failed because of Permanent Agent Error: SVRCOD = 40; RDBNAM = 
testDB;create=true; diagnostic msg = Session in invalid state:4
org.apache.derby.impl.drda.DRDAProtocolException: Execution failed 
because of Permanent Agent Error: SVRCOD = 40; RDBNAM = 
testDB;create=true; diagnostic msg = Session in invalid state:4
         at 
org.apache.derby.impl.drda.DRDAProtocolException.newAgentError(Unknown 
Source)
         at org.apache.derby.impl.drda.DRDAConnThread.agentError(Unknown 
Source)
         at org.apache.derby.impl.drda.DRDAConnThread.run(Unknown Source)
Execution failed because of Permanent Agent Error: SVRCOD = 40; RDBNAM = 
testDB;create=true; diagnostic msg = Session in invalid state:4
org.apache.derby.impl.drda.DRDAProtocolException: Execution failed 
because of Permanent Agent Error: SVRCOD = 40; RDBNAM = 
testDB;create=true; diagnostic msg = Session in invalid state:4
         at 
org.apache.derby.impl.drda.DRDAProtocolException.newAgentError(Unknown 
Source)
         at org.apache.derby.impl.drda.DRDAConnThread.agentError(Unknown 
Source)
         at org.apache.derby.impl.drda.DRDAConnThread.run(Unknown Source)

[client]
select * from sys.systables;
<the result is printed, seems to be correct>
ERROR 58015: The DDM object 0x1232 is not supported.  The connection has 
been terminated.





> When the pool is being initialized, derby.log prints that 31 or 32 or 33
> connections had been created and appserver is trying to make another
> connection. Appserver hangs waiting for the response from derby.
> 
> JStack output below :
> ------------------------------------------------------------------------------------------------
> 
> Thread 9782: (state = IN_NATIVE)
>  - java.net.SocketInputStream.socketRead0(java.io.FileDescriptor,
> byte[], int, int, int) @bci=0 (Interpreted frame)
>  - java.net.SocketInputStream.read(byte[], int, int) @bci=84, line=129
> (Interpreted frame)
>  - org.apache.derby.client.net.Reply.fill(int) @bci=34 (Interpreted
> frame)
>  - org.apache.derby.client.net.Reply.ensureALayerDataInBuffer(int)
> @bci=21 (Interpreted frame)
>  - org.apache.derby.client.net.Reply.readDssHeader() @bci=7 (Interpreted
> frame)
>  - org.apache.derby.client.net.Reply.startSameIdChainParse() @bci=1
> (Interpreted frame)
>  -
> org.apache.derby.client.net.NetConnectionReply.readExchangeServerAttributes(org.apache.derby.client.am.Connection) @bci=1 (Interpreted frame)
>  -
> org.apache.derby.client.net.NetConnection.readServerAttributesAndKeyExchange(int) @bci=8 (Interpreted frame)
>  -
> org.apache.derby.client.net.NetConnection.flowServerAttributesAndKeyExchange(int, byte[]) @bci=22 (Interpreted frame)
>  -
> org.apache.derby.client.net.NetConnection.flowUSRIDPWDconnect(java.lang.String) @bci=3 (Interpreted frame)
>  -
> org.apache.derby.client.net.NetConnection.flowConnect(java.lang.String,
> int) @bci=163 (Interpreted frame)
>  -
> org.apache.derby.client.net.NetConnection.initialize(java.lang.String,
> java.lang.String, org.apache.derby.jdbc.ClientDataSource, int, boolean)
> @bci=40 (Interpreted frame)
>  -
> org.apache.derby.client.net.NetConnection.<init>(org.apache.derby.client.net.NetLogWriter, java.lang.String, java.lang.String, org.apache.derby.jdbc.ClientDataSource, int, boolean) @bci=135 (Interpreted frame)
>  -
> org.apache.derby.jdbc.ClientDataSource.getConnection(java.lang.String,
> java.lang.String) @bci=32 (Interpreted frame)
>  -
> com.sun.gjc.spi.DSManagedConnectionFactory.createManagedConnection(javax.security.auth.Subject, javax.resource.spi.ConnectionRequestInfo) @bci=77, line=96 (Interpreted frame)
>  -
> com.sun.enterprise.resource.LocalTxConnectorAllocator.createResource()
> @bci=12, line=56 (Interpreted frame)
>  -
> com.sun.enterprise.resource.AbstractResourcePool.createSingleResource(com.sun.enterprise.resource.ResourceAllocator) @bci=8, line=756 (Interpreted frame)
>  -
> com.sun.enterprise.resource.AbstractResourcePool.createResourceAndAddToPool(com.sun.enterprise.resource.ResourceAllocator) @bci=2, line=1515 (Interpreted frame)
>  -
> com.sun.enterprise.resource.AbstractResourcePool.createResources(com.sun.enterprise.resource.ResourceAllocator, int) @bci=9, line=780 (Interpreted frame)
>  -
> com.sun.enterprise.resource.AbstractResourcePool.initPool(com.sun.enterprise.resource.ResourceSpec, com.sun.enterprise.resource.ResourceAllocator) @bci=27, line=209 (Interpreted frame)
>  -
> com.sun.enterprise.resource.AbstractResourcePool.internalGetResource(com.sun.enterprise.resource.ResourceSpec, com.sun.enterprise.resource.ResourceAllocator, javax.transaction.Transaction) @bci=10, line=501 (Interpreted frame)
>  -
> com.sun.enterprise.resource.AbstractResourcePool.getResource(com.sun.enterprise.resource.ResourceSpec, com.sun.enterprise.resource.ResourceAllocator, javax.transaction.Transaction) @bci=37, line=428 (Interpreted frame)
>  -
> com.sun.enterprise.resource.PoolManagerImpl.getResourceFromPool(com.sun.enterprise.resource.ResourceSpec, com.sun.enterprise.resource.ResourceAllocator, com.sun.enterprise.resource.ClientSecurityInfo, javax.transaction.Transaction) @bci=16, line=248 (Interpreted frame)
>  -
> com.sun.enterprise.resource.PoolManagerImpl.getResource(com.sun.enterprise.resource.ResourceSpec, com.sun.enterprise.resource.ResourceAllocator, com.sun.enterprise.resource.ClientSecurityInfo) @bci=34, line=174 (Interpreted frame)
>  -
> com.sun.enterprise.connectors.ConnectionManagerImpl.internalGetConnection(javax.resource.spi.ManagedConnectionFactory, com.sun.enterprise.deployment.ResourcePrincipal, javax.resource.spi.ConnectionRequestInfo, boolean, java.lang.String, java.lang.Object, boolean) @bci=388, line=312 (Interpreted frame)
>  -
> com.sun.enterprise.connectors.ConnectionManagerImpl.allocateConnection(javax.resource.spi.ManagedConnectionFactory, javax.resource.spi.ConnectionRequestInfo, java.lang.String, java.lang.Object) @bci=362, line=222 (Interpreted frame)
>  -
> com.sun.enterprise.connectors.ConnectionManagerImpl.allocateConnection(javax.resource.spi.ManagedConnectionFactory, javax.resource.spi.ConnectionRequestInfo, java.lang.String) @bci=5, line=152 (Interpreted frame)
>  -
> com.sun.enterprise.connectors.ConnectionManagerImpl.allocateConnection(javax.resource.spi.ManagedConnectionFactory, javax.resource.spi.ConnectionRequestInfo) @bci=7, line=145 (Interpreted frame)
>  - com.sun.gjc.spi.base.DataSource.getConnection() @bci=9, line=95
> (Interpreted frame)
> 
> ------------------------------------------------------------------------------------------------
> 
> 
> 1) Can someone please clarify the "maxthreads" & "timeslice" property ?
> 2) The above said hang seems to be permanent. Is this expected
> behavior ?
> 3) Is it possible that when derby server has lesser threads (32) and
> many requests ( > 32 ), derby will respond slowly i.e., user can
> explicitly see that the request is waiting for sometime (30 secs, for
> ex) and then get the response ?
> 
> 
> Thanks,
> -Jagadish
> 
> 
> 
> 
> 


Re: Derby causes appserver hang with "maxthreads"

Posted by Kristian Waagan <Kr...@Sun.COM>.
Bryan Pendleton wrote:
>>  When I tried to set the timeSlice (tried value 2000, used 
>> NetworkServerControl to set it), the third connection succeeded, but 
>> it failed when I issued a query on it (see error message below).
> 
> Hi Kristian,
> 
> I think this is DERBY-1856?

Yes, I think that is correct.

I'm wondering in what kind of state this code/functionality is. For 
instance, I learned about the code in ClientThread that sets a timeout 
on the socket, along with a comment saying this looks very suspicious...
I tried commenting out the code setting the socket timeout, but you 
still get errors.

To work around this issue, I think the number of connections/threads 
should either be unlimited (as in the embedded setup) or limited by 
another mechanism (say, a connection pool in an appserver). The 
derby.drda.maxThreads property does work, but without time slicing, the 
(maxThreads +1)th concurrent connection will hang until another one 
disconnects.



regards,
-- 
Kristian

> 
> thanks,
> 
> bryan
> 
> 


Re: Derby causes appserver hang with "maxthreads"

Posted by Bryan Pendleton <bp...@amberpoint.com>.
>  When I tried to set the timeSlice (tried value 2000, used 
> NetworkServerControl to set it), the third connection succeeded, but it 
> failed when I issued a query on it (see error message below).

Hi Kristian,

I think this is DERBY-1856?

thanks,

bryan