You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by ped <pe...@virtualcomputer.com> on 2008/12/09 15:33:49 UTC
Tomcat thread pool question
I am deploying my web app war thru tomcat6.0 on Windows 2003 - I am not
changing any tomcat configuration files directly (or indirectly, afaik).
My app is using Hibernate for DB access and I have added c3p0 to handle DB
connection pooling to Hibernate.
I am seeing some strange results, that lead me to believe that tomcat is
honoring the c3p0 max threads configuration, tho I believe this should not
be happenning.
When I set c3p0 max threads to a large number, I have no problem with my
app. When I set the max threads in c3p0 to smaller values, I see the
following problem:
- my client (written in GWT) executes a loop as follows:
1 - remote call to web app to start a DB transaction (essentially
reserving a 3cp0 connection)
2 - on callback from 1, make a remote call to web app to perform a DB
query using the above transaction
3 - on callback from 2, make a remote call to the web app to commit the
db transaction (freeing the c3p0 connection)
The problem occurs if I set max threads to N and execute the above loop N+1
or more times (where N is a small number like 3 or 4). I see Tomcat threads
sitting in c3p0 code waiting for a connection. There is no thread handling
the incoming commit calls (step 3 above). The initial N iterations thru the
loop all complete their DB transaction, they just hang while trying to
commit the transaction.
If I execute the loop N-1 times, I have no problems - I can execute my loop
over and over. I can verify that I am not leaking connections (I have a
monitor thread that displays the number of active connections).
I've got logging turned on in both the client and my web app that shows that
my commit code is running in the client, but the request to my server is
never received.
As strange as it seems, my experiments leads me to believe that Tomcat is
honoring the c3p0 max threads.
Any help or insight is appreciated.
--
View this message in context: http://www.nabble.com/Tomcat-thread-pool-question-tp20915752p20915752.html
Sent from the Tomcat - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
RE: Tomcat thread pool question
Posted by "Caldarale, Charles R" <Ch...@unisys.com>.
> From: André Warnier [mailto:aw@ice-sa.com]
> Subject: Re: Tomcat thread pool question
>
> So it has nothing to do directly with the threads.
Only in determining how many requests can be accepted by Tomcat before going on the limited TCP/IP queue and subsequent requests being rejected.
> I will suppose for now that the webapp saves each borrowed
> connection, in some place related to the session-id of the
> client that triggered the borrowing of each connection.
I hope so; otherwise the application architecture is complete wishful thinking.
> Think I got it.
Yup.
> But on the other hand, if you increase the number of threads above the
> number of simultaneous clients that you could possibly have, then it
> would unblock the situation, no ?
In a test environment, that might be feasible; in the real world, it is highly unlikely that one has sufficient control over the clients to limit the number of requests that they might submit in toto. (It's not really the number of clients that's the problem; it's the number of concurrent requests, since there's nothing stopping a client from issuing multiple requests simultaneously. Given the poor design demonstrated so far by the app in question, I wouldn't be surprised that they aren't providing for that situation either.)
> I'm not saying that it is a good design, but maybe it's a
> temporary solution ?
Maybe, but I would never condone putting such a scheme into production. I wonder what other shortcomings this app has...
- Chuck
THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY MATERIAL and is thus for use only by the intended recipient. If you received this in error, please contact the sender and delete the e-mail and its attachments from all computers.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
How to get a free adult friend finder gold membership
Posted by charlesg <ch...@pearceshardware.co.uk>.
Free tutorial on how to get a free Adult Friend Finder Gold Membership.
http://free-aff-gold.blogspot.com/
--
View this message in context: http://www.nabble.com/Tomcat-thread-pool-question-tp20915752p22197154.html
Sent from the Tomcat - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
Re: Tomcat thread pool question
Posted by André Warnier <aw...@ice-sa.com>.
Caldarale, Charles R wrote:
>> From: André Warnier [mailto:aw@ice-sa.com]
>> Subject: Re: Tomcat thread pool question
>>
>> So we have a Tomcat, which somehow has a "pool of database
>> connections" ready to be lent to webapps.
>
> In this particular case, the db connection pool is managed by Hibernate, not Tomcat. More typical usage would have Tomcat managing the pool, but it wouldn't make any difference for this problem.
>
>> And we have a webapp capable of borrowing one of the
>> connections from the pool to do something with it, the
>> understanding being that when it's done, it gives it
>> back to the pool.
>
> That's the standard model, but this app design isn't using it. Instead, the connections are not returned to the pool until the client says it's ok to do so.
>
>> - Tomcat receives the request # 2, and passes it to the
>> same / a different thread. Say it is the same (how that
>> works I don't know, question below).
>
> Unlikely to be the same, but it doesn't matter.
>
>> - the thread somehow re-uses the same db connection which
>> was borrowed before. How ? was it saved somewhere and can
>> this thread get the same one back ?
>
> One presumes the webapp stored the connection somewhere retrievable, although the OP provided no actual evidence of that. It coule be stored in the Session, or kept in a completely separate active connection structure managed by the webapp.
>
>> - Client issues HTTP request # 3, which is a signal for the webapp to
>> return the db connection to the pool
>
> Not just return the db connection, but also commit the db updates.
>
>> - Tomcat receives the request # 3, and passes it to the same / a
>> different thread. Say it is the same (how that works I don't know).
>
> Doesn't matter if it's the same thread or not.
>
>> Now my question is : considering this is HTTP, where each request is
>> supposedly independent from previous and following ones, can a scheme
>> like the above possibly work ?
>
> Yes, because each client can be identified by a session identifier or some other cookie. However, unless the client is very well controlled and extremely robust, this design abdicates responsibility for management of server resources (the db connections) and delegated that to the client, an extremely poor design choice.
>
>> Is it one particular thread which holds this borrowed db
>> connection, and is request # 2 necessarily processed by
>> the same thread as request # 1 ?
>
> Highly unlikely.
>
>> Where is the borrowed connection stored between the requests ?
>
> Could be in the Session object associated with the client, or some webapp-managed structure.
>
>> Am I right in thinking that for such a scheme to work, even
>> with well-behaved clients, the borrowed db connection would
>> need to be saved somewhere independent of a Tomcat thread,
>> but dependent on some kind of client "session", so that any
>> thread could pick it up where another one or itself left it
>> between transactions of that same client ?
>
> Correct; it's only a minor - albeit dangerous - variation on the frequently used shopping cart seen on many web sites.
>
Thanks Chuck.
So it has nothing to do directly with the threads.
And I will suppose for now that the webapp saves each borrowed
connection, in some place related to the session-id of the client that
triggered the borrowing of each connection.
Suppose we have 5 available db connections in the pool, and 10 threads,
and 15 clients.
The first 5 clients send their request # 1, resulting in 5 threads busy
momentarily, and 5 db connections borrowed. So the pool is empty.
The next 5 clients come in with request # 1, they also get 5 threads,
but these threads have to wait for a db connection to become available
in the pool again. So these threads block, until the first client
issues its request # 3, and one db connection is returned to the pool.
The next 5 clients arrive, and for the moment there is no thread
available to service the request, so they block earlier, in the "accept"
queue of the Connector or something.
So now the first client receives the response to its request # 1.
A thread is now free, and one of the waiting accept connections gets it.
This thread immediately tries to get a new db connection from the pool,
but it cannot because it's empty. So it too has to wait, and this blocks
another thread. So now there are 6 threads blocked.
A second client receives a response # 1 and issues a request #2. It
doesn't get a thread, because in the meantime another waiting accept
connection got that free thread, and also waits on a free db connection.
So now we have 7 threads blocked, and one request # 2 waiting in the
accept queue.
And so on.
Thus finally, if there are more threads than db connections in the pool,
we can get completely locked up, even with clients that are perfectly
well-behaved and always issue request # 3 if they can.
And if a client is not well-behaved and never issues its request # 3, we
lose a db connection from the pool.
Think I got it.
But on the other hand, if you increase the number of threads above the
number of simultaneous clients that you could possibly have, then it
would unblock the situation, no ?
Because then each client would get a thread, and a client that issues
request # 2 does not have to wait for a db connection, it already has
one stored away. So it can do its thing, get its response and issue its
request # 3, which frees a db connection.
I'm not saying that it is a good design, but maybe it's a temporary
solution ?
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
RE: Tomcat thread pool question
Posted by "Caldarale, Charles R" <Ch...@unisys.com>.
> From: André Warnier [mailto:aw@ice-sa.com]
> Subject: Re: Tomcat thread pool question
>
> So we have a Tomcat, which somehow has a "pool of database
> connections" ready to be lent to webapps.
In this particular case, the db connection pool is managed by Hibernate, not Tomcat. More typical usage would have Tomcat managing the pool, but it wouldn't make any difference for this problem.
> And we have a webapp capable of borrowing one of the
> connections from the pool to do something with it, the
> understanding being that when it's done, it gives it
> back to the pool.
That's the standard model, but this app design isn't using it. Instead, the connections are not returned to the pool until the client says it's ok to do so.
> - Tomcat receives the request # 2, and passes it to the
> same / a different thread. Say it is the same (how that
> works I don't know, question below).
Unlikely to be the same, but it doesn't matter.
> - the thread somehow re-uses the same db connection which
> was borrowed before. How ? was it saved somewhere and can
> this thread get the same one back ?
One presumes the webapp stored the connection somewhere retrievable, although the OP provided no actual evidence of that. It coule be stored in the Session, or kept in a completely separate active connection structure managed by the webapp.
> - Client issues HTTP request # 3, which is a signal for the webapp to
> return the db connection to the pool
Not just return the db connection, but also commit the db updates.
> - Tomcat receives the request # 3, and passes it to the same / a
> different thread. Say it is the same (how that works I don't know).
Doesn't matter if it's the same thread or not.
> Now my question is : considering this is HTTP, where each request is
> supposedly independent from previous and following ones, can a scheme
> like the above possibly work ?
Yes, because each client can be identified by a session identifier or some other cookie. However, unless the client is very well controlled and extremely robust, this design abdicates responsibility for management of server resources (the db connections) and delegated that to the client, an extremely poor design choice.
> Is it one particular thread which holds this borrowed db
> connection, and is request # 2 necessarily processed by
> the same thread as request # 1 ?
Highly unlikely.
> Where is the borrowed connection stored between the requests ?
Could be in the Session object associated with the client, or some webapp-managed structure.
> Am I right in thinking that for such a scheme to work, even
> with well-behaved clients, the borrowed db connection would
> need to be saved somewhere independent of a Tomcat thread,
> but dependent on some kind of client "session", so that any
> thread could pick it up where another one or itself left it
> between transactions of that same client ?
Correct; it's only a minor - albeit dangerous - variation on the frequently used shopping cart seen on many web sites.
- Chuck
THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY MATERIAL and is thus for use only by the intended recipient. If you received this in error, please contact the sender and delete the e-mail and its attachments from all computers.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
Re: Tomcat thread pool question
Posted by André Warnier <aw...@ice-sa.com>.
Possibly [OT], and just disregard if so.
I am just trying to follow this thread and to understand, from my very
superficial and elementary knowledge of things Java and Tomcat.
So we have a Tomcat, which somehow has a "pool of database connections"
ready to be lent to webapps.
And we have a webapp capable of borrowing one of the connections from
the pool to do something with it, the understanding being that when it's
done, it gives it back to the pool.
And we have several Tomcat threads ready to execute instances of this
webapp, to service HTTP requests.
We also have a client, who sends 3 HTTP requests in a row to Tomcat, as
follows :
- Client sends HTTP request # 1 to Tomcat
- Tomcat passes this request to a thread, which runs the webapp
- the thread borrows a connection from the pool
- the thread for the moment doesn't do anything with it, but sends a
response to the Client
- request # 1 is terminated, the thread is ready to process another request
- Client receives response to request # 1
- Client issues HTTP request # 2, which is a db transaction
- Tomcat receives the request # 2, and passes it to the same / a
different thread. Say it is the same (how that works I don't know,
question below).
- the thread somehow re-uses the same db connection which was borrowed
before. How ? was it saved somewhere and can this thread get the same
one back ? But suppose it does.
- the thread makes the db query, and sends a response to the Client
- request # 2 is terminated, the thread is ready to process another request
- Client receives response to request # 2
- Client issues HTTP request # 3, which is a signal for the webapp to
return the db connection to the pool
- Tomcat receives the request # 3, and passes it to the same / a
different thread. Say it is the same (how that works I don't know).
- the thread somehow re-uses the same db connection it had borrowed
before, to finalise the db transaction, then returns the connection to
the pool. The thread sends a response to the Client.
- request # 3 is terminated, the thread is ready to process another request
- Client receives response to request # 3 and is happy.
Now my question is : considering this is HTTP, where each request is
supposedly independent from previous and following ones, can a scheme
like the above possibly work ?
Is it one particular thread which holds this borrowed db connection, and
is request # 2 necessarily processed by the same thread as request # 1 ?
Where is the borrowed connection stored between the requests ?
Am I right in thinking that for such a scheme to work, even with
well-behaved clients, the borrowed db connection would need to be saved
somewhere independent of a Tomcat thread, but dependent on some kind of
client "session", so that any thread could pick it up where another one
or itself left it between transactions of that same client ?
Is that what everyone is trying to say ?
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
Re: Tomcat thread pool question
Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
All,
Christopher Schultz wrote:
> So, unless you have maxActive == dbcp size, you're screwed.
Er, that should be maxActive == maxThreads.
- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
iEYEARECAAYFAklAQa0ACgkQ9CaO5/Lv0PCD+QCguPOh1/0anb6avQkFiARkn9w5
tj8AmgIbTo5wT1cHRtoE/FGShAj8YLDu
=qbed
-----END PGP SIGNATURE-----
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
Re: Tomcat thread pool question
Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Ped,
ped wrote:
> I would think that I should be able to increase the number of threads
> available to Tomcat to prevent this problem (I'm not saying that is the
> correct solution to my problem - I fully understand that our design is the
> root of this problem).
If you have many clients:
1. borrowing db connections
2. executing queries
3. committing transactions and returning the connections to the pool
...then you have very nondeterministic behavior.
If every request requires a db connection (either from the pool, or from
the session, or wherever you store it), and you have fewer db
connections available than the number of processing threads configured,
then everything will eventually go to hell. Here's how:
1. Many clients borrow connections from the dbcp, exhausting it
2. New clients requiring new borrowed connections /block/ waiting for
those pooled connections to be available
3. The requests blocked in #2 prevent new requests from being serviced
4. Clients who already "own" pooled connections cannot successfully
make requests that will ultimately re-populate your dbcp
So, unless you have maxActive == dbcp size, you're screwed.
- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
iEYEARECAAYFAklAQUQACgkQ9CaO5/Lv0PAS5QCfV90jki6OkspGN3oIVaW1ZKMK
IgkAn0hL1tzOVUt2NrvBvU9GNUaUartv
=DIbX
-----END PGP SIGNATURE-----
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
Re: Tomcat thread pool question
Posted by Michael Ludwig <mi...@gmx.de>.
ped schrieb am 10.12.2008 um 10:33:23 (-0800):
> > The Tomcat thread pool is finite; we'll call the maxThread value T.
> > Likewise, the db connection pool is finite, and we'll call its size
> > D. The client makes some number of requests that are not committed,
> > which we'll label R. Anytime R > T + D, you're stuck.
>
> Yes - that's my understanding of the problem. But as I change D (my db
> connection pool size) and R, Tomcat's maxThread value (T) seems to be
> very small (1 or 2). That surprised me, and led me to think something
> else was going on here.
Tomcat's maxThread is what you configure it to be.
Quoting from your original post:
| my client (written in GWT) executes a loop as follows:
| 1 - remote call to web app to start a DB transaction (essentially
| reserving a 3cp0 connection)
Which will never go back to the pool. You think you're "reserving" it,
but you'll never get back to it, so you're actually losing it.
| 2 - on callback from 1, make a remote call to web app to perform a DB
| query using the above transaction
Another one that will never again be available for anybody, as you don't
commit your work and don't give it back to the pool.
| 3 - on callback from 2, make a remote call to the web app to commit
| the db transaction (freeing the c3p0 connection)
And another one, which there isn't any point in committing, as no work
has been done in it.
You have to close your connection each and every time to give it back
to the pool. That's the idiomatics of the pool: Calling close() on a
connection returns it to the pool.
http://commons.apache.org/dbcp/apidocs/org/apache/commons/dbcp/PoolableConnection.html
Michael Ludwig
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
RE: Tomcat thread pool question
Posted by ped <pe...@virtualcomputer.com>.
>The Tomcat thread pool is finite; we'll call the maxThread value T.
Likewise, the db connection pool is finite, and we'll call its size D. The
client makes some number of requests that are not committed, which we'll
label R. Anytime R > T + D, you're stuck.
Yes - that's my understanding of the problem. But as I change D (my db
connection pool size) and R, Tomcat's maxThread value (T) seems to be very
small (1 or 2). That surprised me, and led me to think something else was
going on here.
--
View this message in context: http://www.nabble.com/Tomcat-thread-pool-question-tp20915752p20941231.html
Sent from the Tomcat - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
RE: Tomcat thread pool question
Posted by "Caldarale, Charles R" <Ch...@unisys.com>.
> From: ped [mailto:peter.donahue@virtualcomputer.com]
> Subject: RE: Tomcat thread pool question
>
> So that implies that Tomcat only supports a max of 3 threads...
Obviously untrue, since the default is 200.
> I uncommented:
> <Executor name="tomcatThreadPool" namePrefix="catalina-exec-"
> maxThreads="150" minSpareThreads="1"/>
> in Tomcat's server.xml. But I still see the problem when I cap
> my db connection pool at 3.
A useless exercise unless you changed all of the <Connector> elements you're using to utlize the executor; if you didn't, each <Connector> has its own thread pool.
> I would think that I should be able to increase the number of
> threads available to Tomcat to prevent this problem
You cannot fix this problem in Tomcat, since you have turned over responsibility for server resources to the client(s). The Tomcat thread pool is finite; we'll call the maxThread value T. Likewise, the db connection pool is finite, and we'll call its size D. The client makes some number of requests that are not committed, which we'll label R. Anytime R > T + D, you're stuck. The first D requests get processed, *do not* return the db connection to the pool, respond to the client, and return to the thread pool. The next T requests get stuck in the db pool waiting for db connections to become available. At this point, the db pool is fully consumed, the thread pool is fully consumed, and some number of subsequent requests are held in the platform's TCP/IP stack. Since you have no control over the clients (at least in the real world), you cannot ever configure T and D large enough to exceed all possible values of R; one of them would have to be infinite.
- Chuck
THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY MATERIAL and is thus for use only by the intended recipient. If you received this in error, please contact the sender and delete the e-mail and its attachments from all computers.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
RE: Tomcat thread pool question
Posted by ped <pe...@virtualcomputer.com>.
>all of the Tomcat threads are waiting for db connections to become available
So that implies that Tomcat only supports a max of 3 threads...
I uncommented:
<Executor name="tomcatThreadPool" namePrefix="catalina-exec-"
maxThreads="150" minSpareThreads="1"/>
in Tomcat's server.xml. But I still see the problem when I cap my db
connection pool at 3.
I would think that I should be able to increase the number of threads
available to Tomcat to prevent this problem (I'm not saying that is the
correct solution to my problem - I fully understand that our design is the
root of this problem).
--
View this message in context: http://www.nabble.com/Tomcat-thread-pool-question-tp20915752p20939919.html
Sent from the Tomcat - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
RE: Tomcat thread pool question
Posted by "Caldarale, Charles R" <Ch...@unisys.com>.
> From: ped [mailto:peter.donahue@virtualcomputer.com]
> Subject: RE: Tomcat thread pool question
>
> Perhaps there is a subtle bug here, or misconfiguration on
> my part
It's not subtle - it's blatant. The db connection pool is exhausted, all of the Tomcat threads are waiting for db connections to become available, and further requests are queued in the OS TCP/IP stack. You have a designed-in deadlock in your application, and there's nothing Tomcat can do about that.
- Chuck
THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY MATERIAL and is thus for use only by the intended recipient. If you received this in error, please contact the sender and delete the e-mail and its attachments from all computers.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
RE: Tomcat thread pool question
Posted by ped <pe...@virtualcomputer.com>.
>It's the top frames that are critical, of course, since they show where the
thread is stuck.
That stack trace is not from when the thread is hung - I put a bp on the
entry point to my code so that I could see what code an incoming request
must go thru before being passed to my code - my theory being that my commit
requests were stuck somewhere in there.
I don't believe my code is stuck in the top 4 frames, since when I recreate
the problem, there are no threads that are sitting in that code - I see no
evidence of the commit requests that have been sent from the client.
>Because you're not releasing the connections back to the pool.
Yes - my requests that are attempting to release the connections back to the
pool are not arriving in my code. My client is sending them, but they are
not arriving at my server.
>If I have interpreted that statement correctly, you have a fatally flawed
application architecture. Each
Understood - we are in the process of re-writing some of this logic.
However, poor design or not, I see no reason why Tomcat stops processing
incoming requests when an underlying pool (that it should have no knowledge
of) has been depleted.
I am pursuing this point because it occurs to me that Tomcat is not behaving
as I would expect - perhaps I misunderstand what Tomcat is doing, in which
case I'm looking for guidance. Perhaps there is a subtle bug here, or
misconfiguration on my part (other than the obvious undersizing of the pool
- but that should just cause poor performance, rather than non-functional
code).
--
View this message in context: http://www.nabble.com/Tomcat-thread-pool-question-tp20915752p20937425.html
Sent from the Tomcat - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
RE: Tomcat thread pool question
Posted by "Caldarale, Charles R" <Ch...@unisys.com>.
> From: ped [mailto:peter.donahue@virtualcomputer.com]
> Subject: RE: Tomcat thread pool question
>
> I believe that all of the code below (except the top 4 call
> frames) are coyote and catalina code.
It's the top frames that are critical, of course, since they show where the thread is stuck.
> When I recreate my problem and look at the threads in
> Tomcat, the only hung threads are the ones waiting for
> a free DB connection in c3p0 code.
Because you're not releasing the connections back to the pool.
> There is no trace of the incoming commit requests
If I have interpreted that statement correctly, you have a fatally flawed application architecture. Each request should complete all its processing - including committing or rolling back database updates and releasing connections - before returning a response to the client. Otherwise, you have put yourself at the mercy of the client to release resources; what if the client never submits the commit request? If you need to maintain some state information about the client from one request to the next, use the Session object, not a database connection.
- Chuck
THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY MATERIAL and is thus for use only by the intended recipient. If you received this in error, please contact the sender and delete the e-mail and its attachments from all computers.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
RE: Tomcat thread pool question
Posted by ped <pe...@virtualcomputer.com>.
You're right, maybe I put this in the wrong forum. Below is a stack trace of
a request when it first enters my code on a successful request. In the error
case, my code is not being invoked.
I believe that all of the code below (except the top 4 call frames) are
coyote and catalina code. I thought this was the correct forum for this
question - perhaps not?
What I meant by 'Tomcat processing the request' was that Tomcat receives the
HTTP request and passes it into my code. I assumed the request is being
blocked in Tomcat...
When I recreate my problem and look at the threads in Tomcat, the only hung
threads are the ones waiting for a free DB connection in c3p0 code. There is
no trace of the incoming commit requests, which I do believe are
successfully sent from my client (according to my logs).
ServiceProxyServlet(HttpServlet).service(HttpServletRequest,
HttpServletResponse) line: 709
ServiceProxyServlet(HttpServlet).service(ServletRequest, ServletResponse)
line: 802
GWTShellServlet.service(HttpServletRequest, HttpServletResponse) line: 253
GWTShellServlet(HttpServlet).service(ServletRequest, ServletResponse) line:
802
ApplicationFilterChain.internalDoFilter(ServletRequest, ServletResponse)
line: 237
ApplicationFilterChain.doFilter(ServletRequest, ServletResponse) line: 157
StandardWrapperValve.invoke(Request, Response, ValveContext) line: 214
StandardValveContext.invokeNext(Request, Response) line: 104
StandardPipeline.invoke(Request, Response) line: 520
StandardContextValve.invokeInternal(Wrapper, Request, Response) line: 198
StandardContextValve.invoke(Request, Response, ValveContext) line: 152
StandardValveContext.invokeNext(Request, Response) line: 104
StandardPipeline.invoke(Request, Response) line: 520
StandardHostValve.invoke(Request, Response, ValveContext) line: 137
StandardValveContext.invokeNext(Request, Response) line: 104
ErrorReportValve.invoke(Request, Response, ValveContext) line: 118
StandardValveContext.invokeNext(Request, Response) line: 102
StandardPipeline.invoke(Request, Response) line: 520
StandardEngineValve.invoke(Request, Response, ValveContext) line: 109
StandardValveContext.invokeNext(Request, Response) line: 104
StandardPipeline.invoke(Request, Response) line: 520
StandardEngine(ContainerBase).invoke(Request, Response) line: 929
CoyoteAdapter.service(Request, Response) line: 160
Http11Processor.process(InputStream, OutputStream) line: 799
Http11Protocol$Http11ConnectionHandler.processConnection(TcpConnection,
Object[]) line: 705
TcpWorkerThread.runIt(Object[]) line: 577
ThreadPool$ControlRunnable.run() line: 683
ThreadWithAttributes(Thread).run() line: 619
Caldarale, Charles R wrote:
>
> Tomcat doesn't process requests - your webapp does. Take a thread dump
> and find out where your webapp is stuck and failing to reach its commit
> points.
>
> - Chuck
>
>
--
View this message in context: http://www.nabble.com/Tomcat-thread-pool-question-tp20915752p20935709.html
Sent from the Tomcat - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
RE: Tomcat thread pool question
Posted by "Caldarale, Charles R" <Ch...@unisys.com>.
> From: ped [mailto:peter.donahue@virtualcomputer.com]
> Subject: Re: Tomcat thread pool question
>
> No DB connections will be freed because the requests from the
> client that are trying to perform commits (thereby freeing a DB
> connection) are not being processed by Tomcat.
Tomcat doesn't process requests - your webapp does. Take a thread dump and find out where your webapp is stuck and failing to reach its commit points.
- Chuck
THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY MATERIAL and is thus for use only by the intended recipient. If you received this in error, please contact the sender and delete the e-mail and its attachments from all computers.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
Re: Tomcat thread pool question
Posted by ped <pe...@virtualcomputer.com>.
Tomcat does not return any error - any requests after I have exhausted the
pool,, are sitting in a wait state waiting for a DB connection to be freed.
No DB connections will be freed because the requests from the client that
are trying to perform commits (thereby freeing a DB connection) are not
being processed by Tomcat. My logging indicates that I send the commit
requests, but I never get a response.
The problem is caused (I believe) by Tomcat's inability to process the
requests that come in after the DB connection pool has been exhausted.
When I increase c3p0's max thread limit, there is no problem - Tomcat seems
to be able to handle as many requests as I throw at it.
Kirk True wrote:
>
> When you issue N+1 requests you say "there is no thread handling the
> incoming . . . calls". Is Tomcat returning any errors to your client for
> the N+1th request? Is the connection being closed or anything?
>
> Is it possible to reproduce the error by making a Servlet that simulates
> blocking on a database connection by sleeping for N seconds?
>
>
>
--
View this message in context: http://www.nabble.com/Tomcat-thread-pool-question-tp20915752p20927444.html
Sent from the Tomcat - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
Re: Tomcat thread pool question
Posted by Kirk True <ki...@mustardgrain.com>.
Hi Peter,
ped wrote:
> The problem occurs if I set max threads to N and execute the above loop N+1
> or more times (where N is a small number like 3 or 4). I see Tomcat threads
> sitting in c3p0 code waiting for a connection. There is no thread handling
> the incoming commit calls (step 3 above). The initial N iterations thru the
> loop all complete their DB transaction, they just hang while trying to
> commit the transaction.
>
When you issue N+1 requests you say "there is no thread handling the
incoming . . . calls". Is Tomcat returning any errors to your client for
the N+1th request? Is the connection being closed or anything?
Is it possible to reproduce the error by making a Servlet that simulates
blocking on a database connection by sleeping for N seconds?
Kirk
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
RE: Tomcat thread pool question
Posted by Martin Gainty <mg...@hotmail.com>.
i have a thread going on another list about integrating corner cases for SQL e.g. 1 connection or 999 connections
it would be helpful for the Build manager to auto-execute these corner cases before deploying to <staging> servers
I usually never say this but ..good catch
Martin
______________________________________________
Disclaimer and confidentiality note
Everything in this e-mail and any attachments relates to the official business of Sender. This transmission is of a confidential nature and Sender does not endorse distribution to any party other than intended recipient. Sender does not necessarily endorse content contained within this transmission.
> Date: Wed, 10 Dec 2008 17:15:39 -0500
> From: chris@christopherschultz.net
> To: users@tomcat.apache.org
> Subject: Re: Tomcat thread pool question
>
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> Ped,
>
> ped wrote:
> > If I execute the loop N-1 times, I have no problems - I can execute my loop
> > over and over. I can verify that I am not leaking connections (I have a
> > monitor thread that displays the number of active connections).
>
> I'm probably joining this thread very late, but if you set your
> connection pool size to 1 (that is, a single connection), can you still
> execute any tests?
>
> Just because you aren't leaking connections doesn't mean that there's no
> potential for deadlock. We run all our development servers with
> maxActive=1 to catch just such potential deadlocks: if a single thread
> borrows two connections from the connection pool (instead of more
> correctly using the same one for all transactions), you can deadlock
> your app.
>
> Just a thought.
>
> - -chris
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.9 (MingW32)
> Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
>
> iEYEARECAAYFAklAP4sACgkQ9CaO5/Lv0PDdAwCeImZkU0CiroF82SZR0bFLjLIF
> angAn0Wlchlp1se5ywh1fLw8FTxBiEL+
> =82bg
> -----END PGP SIGNATURE-----
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
_________________________________________________________________
Send e-mail faster without improving your typing skills.
http://windowslive.com/Explore/hotmail?ocid=TXT_TAGLM_WL_hotmail_acq_speed_122008
Re: Tomcat thread pool question
Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Ped,
ped wrote:
> If I execute the loop N-1 times, I have no problems - I can execute my loop
> over and over. I can verify that I am not leaking connections (I have a
> monitor thread that displays the number of active connections).
I'm probably joining this thread very late, but if you set your
connection pool size to 1 (that is, a single connection), can you still
execute any tests?
Just because you aren't leaking connections doesn't mean that there's no
potential for deadlock. We run all our development servers with
maxActive=1 to catch just such potential deadlocks: if a single thread
borrows two connections from the connection pool (instead of more
correctly using the same one for all transactions), you can deadlock
your app.
Just a thought.
- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
iEYEARECAAYFAklAP4sACgkQ9CaO5/Lv0PDdAwCeImZkU0CiroF82SZR0bFLjLIF
angAn0Wlchlp1se5ywh1fLw8FTxBiEL+
=82bg
-----END PGP SIGNATURE-----
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org