You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Michael Jerger <je...@jerger.org> on 2011/04/04 16:43:41 UTC
How to limit tomcats thread consumption?
Hi all,
last days I leased a virtual host at 1und1 (a german hoster). Unfortunately
1und1 found a new, creative way to limit the joy of using their VPH - they
limit the number of operating-system processes to 256 processes in total.
Thats quite a huge issue, because I want to operate two virtual hosts:
apache-dev -- tomcat-dev -- mysql
apache-www -- tomcat-prod -- mysql
* mysql uses 50 threads in total
* apache uses 5
* tomcat_prod - 109
* tomcat_dev - 73
As u see, there is not much space left for chron jobs / ssh-shells a.s.o.
I tried to limit
* apache Maxclients (50 in total)
* mod_jk connection_pool_size (3/40), socket_keepalive=false
* server.xml:
<Executor name="tomcatDevThreadPool" namePrefix="catalina-exec-"
daemon="false" maxThreads="(3/40)" maxSpareThreads="5"
minSpareThreads="1"/>
<Connector executor="tomcatDevThreadPool" port="8009"
protocol="AJP/1.3" URIEncoding="UTF-8"/>
But all of these actions result in no change - and pstree shows the same
number of processes without any change (I use ubunut 10.4, java 1.6.0_20,
tomcat 7.0.11).
Any idea how to cope with this silly process limit?
Kind regards,
Michael
--
Informatikbüro Jerger http://www.jerger.org
Zeppelinstr. 13, D-72770 Reutlingen
fon: +49-7121-578913 mob: +49-178-8189878
RE: How to limit tomcats thread consumption?
Posted by "Caldarale, Charles R" <Ch...@unisys.com>.
> From: Michael Jerger [mailto:jerger@jerger.org]
> Subject: Re: How to limit tomcats thread consumption?
Do you actually need to be running httpd? Is it doing anything useful? (Serving just static content isn't useful.)
> <Executor name="tomcatDevThreadPool" namePrefix="catalina-exec-"
> daemon="false" maxThreads="(3/40)" maxSpareThreads="5"
> minSpareThreads="1"/>
Your maxThreads setting looks invalid, so it's probably defaulting to 200. Bring it down to a reasonable number, based on how many concurrent requests you expect. (Make it even smaller on your test Tomcat.)
Also, insure that the httpd AJP connection configuration matches your Tomcat <Connector> or <Executor>; if it doesn't, one side or the other will be wasting threads.
- 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: How to limit tomcats thread consumption?
Posted by Michael Jerger <je...@jerger.org>.
Hi,
> thread != process
To be exact - "numproc - Number of processes and kernel-level threads" is
limited.
> (Unless you're on a really old version of Linux.)
ubuntu10.4 isn't really old .. I think ;-)
> > Any idea how to cope with this silly process limit?
>
> 1) Are you sure you have a problem?
Yes - I'm not able to start an remote ssh shell - thats definitly a real
problem.
> 2) If the provider is in fact limiting the VM to 256 _threads_, find
> another provider.
I will do this - but a dedicated server will take some time. In the meantime
I'm forced to use the 1und1 VPH - so do you have any real suggestions?
Kind regadrs,
Michael
RE: How to limit tomcats thread consumption?
Posted by "Caldarale, Charles R" <Ch...@unisys.com>.
> From: Michael Jerger [mailto:jerger@jerger.org]
> Subject: How to limit tomcats thread consumption?
> they limit the number of operating-system processes to
> 256 processes in total.
thread != process
(Unless you're on a really old version of Linux.)
> Any idea how to cope with this silly process limit?
1) Are you sure you have a problem?
2) If the provider is in fact limiting the VM to 256 _threads_, find another provider.
- 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: How to limit tomcats thread consumption?
Posted by André Warnier <aw...@ice-sa.com>.
Michael Jerger wrote:
> Am Dienstag, 5. April 2011, 18:13:57 schrieb Michael Jerger:
>> Andre wrote:
>>> That is one of those areas where giving a precise answer is not easy,
>>> because it depends on so many things..
>>>
>>> You can run two separate Apache httpd instances of course, each with its
>>> individual MaxClients setting. But then you will have to give them
>>> separate listening ports, which may or may not make other things more
>>> complicated in your case.
>> I'm not shure about this - let me figure this out the next days. Are you
>> interested in a way to run two instances on the same port?
>> I think I've seen such a configuration allready ...
>
> Found out how it works ... but I think, this solution is new only to me - but
> anyhow :-)
>
> Many apache instances on one machine can run
> * either on 1IP & different ports
> * or on different IPs & same port
>
Well, let me throw in some additional confusion then : you can even run a single Apache
httpd instance, with several VHosts, each listening on a separate IP address.
See : http://httpd.apache.org/docs/2.2/vhosts/ip-based.html
>> thank you very much for the elaborated answer - there are some good points
>> to think about.
>>
>> On question left for me (I think, you asked it allready) - why using apache
>> in front of tomcat at all - if its so complicated to configure?
>>
>> Do you have an answer to that question?
>>
>> For me the answer is - security, loadbalancing and client certificate
>> handling - at least in general and for larger applications.
>>
A lot of people just use Apache httpd as a front-end, because that is the first
configuration that they have found, and they do not realise that Tomcat can act as a good
"normal" webserver too, to serve static html pages.
I would say that if you are using an Apache front-end, but you find yourself forwarding
"/" to Tomcat, then you most probably do not need Apache. But a lot of people come to
this list, who are doing exactly that.
Load-balancing is one good reason. Tomcat by itself cannot do that, it needs a front-end.
There exist other front-end load-balancers than Apache httpd, as well open-source/free as
commercial, and hardware-based too.
But Apache httpd is well-know and well-tested, so many people use that.
For scenarios involving user authentication and/or SSL, I personally find it easier to use
Apache httpd as a front-end, and do the authentication/SSL bit at that level, and pass to
Tomcat the already authenticated user-id from Apache.
Another thing that Tomcat by itself cannot do, and httpd easily can, is act as a HTTP
proxy server (forward or reverse).
And then, there are a whole series of cases where Tomcat is not the most appropriate
server to use for some kinds of contents : for example, running cgi-bin scripts is often a
lot more efficient (or the only way) under httpd than under Tomcat (which is optimised to
run Java servlets).
There also exists a very vast library of Apache add-on modules and filters, which is not
yet matched by the Tomcat/Java add-on libraries (or at least, let's say that they are
usually much easier to find and set up for Apache httpd than for Tomcat).
My own personal main reason is that I am a perl programmer, and use a lot of perl add-on
modules for doing all kinds of nifty things at the request and response level. The
mod_perl add-on to Apache httpd is very tightly integrated into Apache, very powerful and
very efficient, and it allows one to leverage the amazing CPAN library of perl modules,
which can help solve just about any problem under the sun, is extremely well documented,
concentrated in one place and easy to search and browse.
(http://www.cpan.org/modules/index.html)
Generally speaking, I like the Apache httpd / Tomcat combination a lot, because each one
has different strengths, and the combination is extremely powerful and flexible (as its
success on the WWW demonstrates).
>> In my scenario described the only good argument would be security - have
>> you ever done/seen an pentest to tomcat without fronting apache?
Security, by itself, should not be a valid enough reason, because Tomcat is as secure as
httpd. And if you use Apache httpd as a front-end to Tomcat, there are many opportunities
for configuring this wrongly, and allow accesses to bypass the Tomcat security mechanisms,
thus in general making your whole configuration less secure, instead of more so.
>> Do you have a good starting point to read about this topic?
>
Not really, apart from the whole documentation of Apache httpd and Tomcat. There are
little bits and pieces about security spread all over the place.
Probably the one major piece of advice would be : if you are configuring Apache as a
front-end to Tomcat, then /do not/ allow Apache to access the Tomcat application
directories directly. For example, /do not/ configure the Apache DocumentRoot to be the
same as the Tomcat webapps directory.
(See the red warning here : http://tomcat.apache.org/connectors-doc/reference/apache.html)
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
Re: How to limit tomcats thread consumption?
Posted by Michael Jerger <je...@jerger.org>.
Am Dienstag, 5. April 2011, 18:13:57 schrieb Michael Jerger:
> Andre wrote:
> > That is one of those areas where giving a precise answer is not easy,
> > because it depends on so many things..
> >
> > You can run two separate Apache httpd instances of course, each with its
> > individual MaxClients setting. But then you will have to give them
> > separate listening ports, which may or may not make other things more
> > complicated in your case.
>
> I'm not shure about this - let me figure this out the next days. Are you
> interested in a way to run two instances on the same port?
> I think I've seen such a configuration allready ...
Found out how it works ... but I think, this solution is new only to me - but
anyhow :-)
Many apache instances on one machine can run
* either on 1IP & different ports
* or on different IPs & same port
> thank you very much for the elaborated answer - there are some good points
> to think about.
>
> On question left for me (I think, you asked it allready) - why using apache
> in front of tomcat at all - if its so complicated to configure?
>
> Do you have an answer to that question?
>
> For me the answer is - security, loadbalancing and client certificate
> handling - at least in general and for larger applications.
>
> In my scenario described the only good argument would be security - have
> you ever done/seen an pentest to tomcat without fronting apache?
> Do you have a good starting point to read about this topic?
Kind regadrs,
Michaeal
Re: How to limit tomcats thread consumption?
Posted by Michael Jerger <je...@jerger.org>.
Andre wrote:
> That is one of those areas where giving a precise answer is not easy,
> because it depends on so many things..
>
> You can run two separate Apache httpd instances of course, each with its
> individual MaxClients setting. But then you will have to give them
> separate listening ports, which may or may not make other things more
> complicated in your case.
I'm not shure about this - let me figure this out the next days. Are you
interested in a way to run two instances on the same port?
I think I've seen such a configuration allready ...
> About Apache "children" versus "VirtualHosts" :
...
>
thank you very much for the elaborated answer - there are some good points to
think about.
On question left for me (I think, you asked it allready) - why using apache in
front of tomcat at all - if its so complicated to configure?
Do you have an answer to that question?
For me the answer is - security, loadbalancing and client certificate handling
- at least in general and for larger applications.
In my scenario described the only good argument would be security - have you
ever done/seen an pentest to tomcat without fronting apache?
Do you have a good starting point to read about this topic?
Kind regards,
Michael
Re: How to limit tomcats thread consumption?
Posted by Michael Jerger <je...@jerger.org>.
Mark wrote:
> On 05/04/2011 13:21, André Warnier wrote:
> > I'll split my response in 2 parts, so that the right person(s) here have
> > an easier time to interject their answers/suggestions :
> >
> > Part 1, for a tomcat expert :
> >
> > Michael Jerger wrote:
> > ...
> >
> >> So I'm wondering why tomcat needs all these threads and whether I can
> >> limit these threads ... (on my system tomcat runs as java). It seams
> >> to me that my tomcat rus about 50 threads in idle mode ... thats quite
> >> a lot.
> >
> > It does seem quite a lot to me too, but maybe someone else can give a
> > clue.
>
> Seems high to me too. A thread dump will explain what is going on.
Found the answer allready - in the deployed webapp (liferay) is a c3po - db-
connection pool used.
Due to another bug (concerning spring and c3po) the configuration was not
handeld correctly at this point - so there was the default configuration in
place.
Default configuration means maxPoolSize = 100 - and every pooled db-connection
uses an own thread. So these high thread count had not much to do with tomcat
but with the app deploed within - sorry for that.
But discussing with Andre lead me to the right point - I used another way of
configuration for c3po - now threads are under controll - thank u very much
:-)).
Michael
Re: How to limit tomcats thread consumption?
Posted by Mark Thomas <ma...@apache.org>.
On 05/04/2011 13:21, André Warnier wrote:
> I'll split my response in 2 parts, so that the right person(s) here have
> an easier time to interject their answers/suggestions :
>
> Part 1, for a tomcat expert :
>
> Michael Jerger wrote:
> ...
>>
>> So I'm wondering why tomcat needs all these threads and whether I can
>> limit these threads ... (on my system tomcat runs as java). It seams
>> to me that my tomcat rus about 50 threads in idle mode ... thats quite
>> a lot.
>>
>
> It does seem quite a lot to me too, but maybe someone else can give a clue.
Seems high to me too. A thread dump will explain what is going on.
Mark
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
Re: How to limit tomcats thread consumption?
Posted by André Warnier <aw...@ice-sa.com>.
I'll split my response in 2 parts, so that the right person(s) here have an easier time to
interject their answers/suggestions :
Part 1, for a tomcat expert :
Michael Jerger wrote:
...
>
> So I'm wondering why tomcat needs all these threads and whether I can limit
> these threads ... (on my system tomcat runs as java). It seams to me that my
> tomcat rus about 50 threads in idle mode ... thats quite a lot.
>
It does seem quite a lot to me too, but maybe someone else can give a clue.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
Re: How to limit tomcats thread consumption?
Posted by André Warnier <aw...@ice-sa.com>.
Part 2, Apache httpd matters..
Michael Jerger wrote:
...
>
> Sorry for beeing not precise enough. I was talking about apache VirtualHosts.
> I've two sites enabled www and dev.
> So I've to set Maxclients to the total of both maximums concurrent requests -
> righ? While writing this - I tend to two seperated apache instances - so I can
> set maxclients per web.
>
That is one of those areas where giving a precise answer is not easy, because it depends
on so many things..
You can run two separate Apache httpd instances of course, each with its individual
MaxClients setting. But then you will have to give them separate listening ports, which
may or may not make other things more complicated in your case.
About Apache "children" versus "VirtualHosts" :
When Apache (pre-fork MPM) starts, it will fork n1 children processes, where n1 is the
"StartServers" setting. Then it waits for requests. When a request comes in, the "main
Apache" looks for a child that is idle. If it finds one, it will pass the request to that
one, and go back to listening for more requests. If another request comes in, same thing.
If a child is done with one request (that includes the time needed by the back-end
tomcat to process the request if needed), the child becomes idle again.
If a request comes in and there is no idle child available, Apache will fork again to
create another child, and pass the request to it. It will do this, as long as the number
of live children does not exceed MaxClients. When MaxClients is exceeded, any new request
has to wait (*), until a child becomes available again.
If no more requests come in for a while, and there are lots of idle children, Apache will
start killing off some, until the number of children is back to MinSpareServers.
(*) that is, as long as the "socket queue length" for the listening socket is not
exhausted. If it is, the connection will be refused right away.
(See http://httpd.apache.org/docs/2.2/mod/mpm_common.html#listenbacklog)
Now the less obvious part to understand, is that each Apache child is a "full" server : it
can handle a request for *any* VirtualHost. When it processes the request, it just
temporarily adopts the "personality" (aka the configuration settings) of the corresponding
VirtualHost to which this request is addressed.
When this request is processed, it goes back to being idle, and maybe the next request
that this child will handle is for another VirtualHost.
So the concept of "child" (or thread) is separate from the concept of VirtualHost, and
VirtualHost is just a configuration that one child temporarily adopts for processing one
request.
Put another way, you can can have one Apache with 50 VirtualHosts, and it will not change
the number of (children) processes of Apache.
In the practice that means that you could just set MaxClients and the other
children-related counters, to the reasonable number of requests that you want to be able
to process immediately (auf der Stelle) at any one moment, all VirtualHosts together, by
having always an idle Apache child to take care of it right away.
If your applications (tomcat included) respond very quickly, then a quite small number of
Apache children may be sufficient to handle the load. During a peak of requests, some of
them may have to wait a fraction of a second to receive a child to take care of them, but
is might not be noticeable. And the lower number of Apache children would mean a lower
number of Tomcat threads also, so each child less in Apache counts double.
Now all of the above would be put in question if the requests to your server are such that
they take a long time to be processed of course. But that is something that you have to
determine.
To make Apache children more quickly go back to the pool of idle children, you could also
reduce the KeepAliveTimeOut setting. See
http://httpd.apache.org/docs/2.2/mod/core.html#keepalivetimeout
and
http://httpd.apache.org/docs/2.2/mod/core.html#timeout
for the explanation.
(the main point being that as long as a child is waiting for another client request, it is
blocked with this one client, maybe for nothing, and cannot go back to the idle pool).
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
Re: How to limit tomcats thread consumption?
Posted by Michael Jerger <je...@jerger.org>.
Hi Andre,
thanx very much for the detailed answer ...
> > Maxclinets is defined for two v-hosts - prod with 40 and dev with 3 so
> > your right, I can save 7 processes here :-)
>
> I am not sure, but you may have the wrong understanding of v-hosts. Are you
> talking about Apache VirtualHosts, or (VMware) virtual machines here ?
> What I mean is that the MaxClients setting for Apache httpd is global, and
> does not apply to VirtualHosts separately.
Sorry for beeing not precise enough. I was talking about apache VirtualHosts.
I've two sites enabled www and dev.
So I've to set Maxclients to the total of both maximums concurrent requests -
righ? While writing this - I tend to two seperated apache instances - so I can
set maxclients per web.
> I have no idea how the following is going to show up in an email, but this
> is what I get when I enter "pstree" on one of my linux Debian production
> systems running Apache httpd and tomcat :
>
> evm2:~# pstree
> init─┬─acpid
> ├─apache2───25*[apache2]
> ├─avahi-daemon───avahi-daemon
> ├─cron
> ├─dbus-daemon
> ├─6*[getty]
> ├─2*[java───14*[{java}]]
> ├─jsvc─┬─jsvc
> │ └─jsvc───40*[{jsvc}]
> ├─klogd
> ├─nmbd
> ├─nullmailer-send
> ├─portmap
> ├─rpc.statd
> ├─smbd───3*[smbd]
> ├─sshd─┬─sshd───bash
> │ └─sshd───bash───pstree
> ├─syslogd
> ├─udevd
> └─vmware-guestd
Youre right. Unfortunately the difference between thread and process is not
important to numproc. You can simulate this by entering the following line in
/etc/security/limits.conf (location for ubuntu):
"{tomcat-user} hard nproc 60"
My pstres looks like:
init-+-apache2---8*[apache2]
|-cron
|-java---109*[{java}]
|-java---52*[{java}]
|-master-+-pickup
| |-qmgr
| `-tlsmgr
|-mysqld---48*[{mysqld}]
|-sshd-+-sshd---sshd---bash---less
| `-sshd---bash---pstree
`-syslogd
So I'm wondering why tomcat needs all these threads and whether I can limit
these threads ... (on my system tomcat runs as java). It seams to me that my
tomcat rus about 50 threads in idle mode ... thats quite a lot.
> In the case above, the relevant part of the Tomcat (5.5) configuration is
> (I am not using an Executor, just plain Connectors) :
As I know in 5.5 executor is not working - shared executor workes not until
tomcat7.
> <Connector port="8180" maxHttpHeaderSize="8192"
> maxThreads="50" minSpareThreads="5" maxSpareThreads="25"
> enableLookups="false" redirectPort="8443" acceptCount="100"
> connectionTimeout="20000" disableUploadTimeout="true" />
>
> <Connector port="8009" protocol="AJP/1.3"
> connectionTimeout="2000" maxThreads="50" minSpareThreads="10"
> maxSpareThreads="25" />
So in my undaerstanding you have two executor pools - each configured for
maxthreads 50 - in total 100.
> and Apache httpd settings are :
>
> <IfModule mpm_prefork_module>
> StartServers 15
> MinSpareServers 15
> MaxSpareServers 25
> MaxClients 200
> MaxRequestsPerChild 0
> </IfModule>
>
> (So as you see, I am not even following my own principles ;-) ).
We all hav to live with diminution :)).
> Are you sure that the problems you have in starting scripts/connecting to
> the system are really due to that process limit ?
Definitely yes.
> What for instance does the command "netstat -an --tcp" show ?
I've:
* 5 CloseWaits on Port 80
* 2 Established ssh on Port 22
* 5 Established on Port 8009 (ajp dev)
* 5 Established on Port 8039 (ajp www)
* 40 Established on Port 3306 (mysql)
While writing this - I will have a look to the c3po connection pool settings -
there is a c3po / spring bug (c3po configuration with <props> works not with
every versions) ... and ... gotcha :-)
The correct c3p0 config leads to the following pstree:
init-+-apache2---6*[apache2]
|-cron
|-java---109*[{java}]
|-java---22*[{java}]
|-master-+-pickup
| |-qmgr
| `-tlsmgr
|-mysqld---36*[{mysqld}]
|-sshd-+-sshd---bash---su---bash
| |-sshd---sftp-server
| |-sshd---sshd---bash---less
| `-sshd---bash---pstree
`-syslogd
Thanx & Kind regards,
Michael
Re: How to limit tomcats thread consumption?
Posted by André Warnier <aw...@ice-sa.com>.
Michael Jerger wrote:
> Hi,
>
>> a) are you sure ? Since, commercially speaking, I can't imagine what
>> benefit they would get from this (as opposed to e.g. limiting the amount
>> of RAM or disk space), I tend to have a doubt.
>
> unfortunately I am ... and yes, I agree - this option is absolutely mindless
> ...
>
>> Also, I am not sure but it seems to me that if there is a maximum number of
>> processes built-in, that should be a configurable OS setting in Linux.
>
> This option is set by the VM Hostingsystem - so I can't change this on os
> level.
>
>> b) thread != process. See e.g.
>> http://manpages.ubuntu.com/manpages/intrepid/man7/pthreads.7.html
>
> I know the difference - so to get my process count I use pstree. As I Know
> pstree counts processes (parent and child) - right?
>
>>> Thats quite a huge issue, because I want to operate two virtual hosts:
>>>
>>> apache-dev -- tomcat-dev -- mysql
>>> apache-www -- tomcat-prod -- mysql
>>>
>>> * mysql uses 50 threads in total
>>> * apache uses 5
>>> * tomcat_prod - 109
>>> * tomcat_dev - 73
>> c) again, are you not confusing threads and processes ?
>> For Apache httpd e.g., depending on the MPM model used, you will be using
>> either processes (pre-fork MPM) or threads, or both.
>
> No I use prefork - but I know the other mpm options to so I will switch to
> threading as soon as I understand the tomcat behaviour.
>
>> In a prefork MPM, that can indeed lead to up to 51 simultaneous *processes*
>> (aka 1 main Apache + 50 Apache "children"), IF you have as many
>> simultaneous requests being processed. I run many sites with Maxclients
>> 20, or less (specially for development sites).
>
> Maxclinets is defined for two v-hosts - prod with 40 and dev with 3 so your
> right, I can save 7 processes here :-)
>
I am not sure, but you may have the wrong understanding of v-hosts. Are you talking about
Apache VirtualHosts, or (VMware) virtual machines here ?
What I mean is that the MaxClients setting for Apache httpd is global, and does not apply
to VirtualHosts separately.
>
>>> * mod_jk connection_pool_size (3/40), socket_keepalive=false
>> There is not really any benefit to have more Apache-Tomcat connections,
>> than your MaxClients setting above.
>
> (3/40) means 3 for dev and 40 for prod.
>
>>> * server.xml:
>>>
>>> <Executor name="tomcatDevThreadPool" namePrefix="catalina-exec-"
>>>
>>> daemon="false" maxThreads="(3/40)" maxSpareThreads="5"
>>>
>>> minSpareThreads="1"/>
>> Ideally, you need as many threads as there can be individual *tomcat*
>> requests in the course of being processed at the same time. There is no
>> benefit in having (or starting) more than that.
>> Since presumably all requests pass first through Apache before there reach
>> Tomcat, you need as a maximum number of Tomcat threads, the same number ax
>> MaxClients in Apache.
>
> Your right - I will decrease my maxclients for 7. But how can I limit the
> number of tomcat-processes?
> Even if I assume that a java thread is mapped to one os-process I don't
> understand the 109 tomcat processes in a nearly idle tomcat with maxthreads 4
> configured at his only connector!
>
I have no idea how the following is going to show up in an email, but this is what I get
when I enter "pstree" on one of my linux Debian production systems running Apache httpd
and tomcat :
evm2:~# pstree
init─┬─acpid
├─apache2───25*[apache2]
├─avahi-daemon───avahi-daemon
├─cron
├─dbus-daemon
├─6*[getty]
├─2*[java───14*[{java}]]
├─jsvc─┬─jsvc
│ └─jsvc───40*[{jsvc}]
├─klogd
├─nmbd
├─nullmailer-send
├─portmap
├─rpc.statd
├─smbd───3*[smbd]
├─sshd─┬─sshd───bash
│ └─sshd───bash───pstree
├─syslogd
├─udevd
└─vmware-guestd
According to the man page of pstree, child /processes/ are shown between (only) [square
brackets], and child /threads/ are shown between [{square and curly brackets}].
On that system, tomcat is running under "jsvc" (see "Apache commons daemon" project), so
what is shown above as "jsvc" processes are actually the Java JVM instances running tomcat.
A "ps -ef" command shows only 3 jsvc processes for tomcat, thus matching the 3 instances
of jsvc above, but not the "40*[{jsvc}]" part, which I tend to think then are really
threads, not processes.
Now, independently of the "Connector" threads, which process the HTTP/AJP requests, I know
that Tomcat (and the JVM) start a number of additional threads to handle various things.
For example, there will be at least one JVM thread taking care of periodic garbage
collection; and at least one (optional) Tomcat thread taking care of watching the webapps
directories for any changes; and each "event listener" probably has its own thread and so
on. But they should not count as processes.
In the case above, the relevant part of the Tomcat (5.5) configuration is (I am not using
an Executor, just plain Connectors) :
<Connector port="8180" maxHttpHeaderSize="8192"
maxThreads="50" minSpareThreads="5" maxSpareThreads="25"
enableLookups="false" redirectPort="8443" acceptCount="100"
connectionTimeout="20000" disableUploadTimeout="true" />
<Connector port="8009" protocol="AJP/1.3"
connectionTimeout="2000" maxThreads="50" minSpareThreads="10" maxSpareThreads="25"
/>
and Apache httpd settings are :
<IfModule mpm_prefork_module>
StartServers 15
MinSpareServers 15
MaxSpareServers 25
MaxClients 200
MaxRequestsPerChild 0
</IfModule>
(So as you see, I am not even following my own principles ;-) ).
But even with the above settings on a running system, "top" shows only 100 processes :
Tasks: 100 total, 2 running, 98 sleeping, 0 stopped, 0 zombie
(And that includes quite a bit of cron jobs, samba and vmware daemons, denyhosts and a
bunch of similar things. And I have no problems starting scripts or making connections to
the system).
Are you sure that the problems you have in starting scripts/connecting to the system are
really due to that process limit ?
What for instance does the command "netstat -an --tcp" show ?
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
Re: How to limit tomcats thread consumption?
Posted by Michael Jerger <je...@jerger.org>.
Hi,
> a) are you sure ? Since, commercially speaking, I can't imagine what
> benefit they would get from this (as opposed to e.g. limiting the amount
> of RAM or disk space), I tend to have a doubt.
unfortunately I am ... and yes, I agree - this option is absolutely mindless
...
> Also, I am not sure but it seems to me that if there is a maximum number of
> processes built-in, that should be a configurable OS setting in Linux.
This option is set by the VM Hostingsystem - so I can't change this on os
level.
> b) thread != process. See e.g.
> http://manpages.ubuntu.com/manpages/intrepid/man7/pthreads.7.html
I know the difference - so to get my process count I use pstree. As I Know
pstree counts processes (parent and child) - right?
> > Thats quite a huge issue, because I want to operate two virtual hosts:
> >
> > apache-dev -- tomcat-dev -- mysql
> > apache-www -- tomcat-prod -- mysql
> >
> > * mysql uses 50 threads in total
> > * apache uses 5
> > * tomcat_prod - 109
> > * tomcat_dev - 73
>
> c) again, are you not confusing threads and processes ?
> For Apache httpd e.g., depending on the MPM model used, you will be using
> either processes (pre-fork MPM) or threads, or both.
No I use prefork - but I know the other mpm options to so I will switch to
threading as soon as I understand the tomcat behaviour.
> In a prefork MPM, that can indeed lead to up to 51 simultaneous *processes*
> (aka 1 main Apache + 50 Apache "children"), IF you have as many
> simultaneous requests being processed. I run many sites with Maxclients
> 20, or less (specially for development sites).
Maxclinets is defined for two v-hosts - prod with 40 and dev with 3 so your
right, I can save 7 processes here :-)
> > * mod_jk connection_pool_size (3/40), socket_keepalive=false
>
> There is not really any benefit to have more Apache-Tomcat connections,
> than your MaxClients setting above.
(3/40) means 3 for dev and 40 for prod.
> > * server.xml:
> >
> > <Executor name="tomcatDevThreadPool" namePrefix="catalina-exec-"
> >
> > daemon="false" maxThreads="(3/40)" maxSpareThreads="5"
> >
> > minSpareThreads="1"/>
>
> Ideally, you need as many threads as there can be individual *tomcat*
> requests in the course of being processed at the same time. There is no
> benefit in having (or starting) more than that.
> Since presumably all requests pass first through Apache before there reach
> Tomcat, you need as a maximum number of Tomcat threads, the same number ax
> MaxClients in Apache.
Your right - I will decrease my maxclients for 7. But how can I limit the
number of tomcat-processes?
Even if I assume that a java thread is mapped to one os-process I don't
understand the 109 tomcat processes in a nearly idle tomcat with maxthreads 4
configured at his only connector!
> > <Connector executor="tomcatDevThreadPool" port="8009"
> >
> > protocol="AJP/1.3" URIEncoding="UTF-8"/>
...
> > Any idea how to cope with this silly process limit?
>
> Change the provider ?
Yes, thats what I will do - but in meantie I've to cope with this one.
Kind regards,
Michael
Re: How to limit tomcats thread consumption?
Posted by Peter Crowther <pe...@melandra.com>.
On 4 April 2011 18:29, André Warnier <aw...@ice-sa.com> wrote:
> Michael Jerger wrote:
>
>> last days I leased a virtual host at 1und1 (a german hoster).
>> Unfortunately 1und1 found a new, creative way to limit the joy of using
>> their VPH - they limit the number of operating-system processes to 256
>> processes in total.
>>
>
> a) are you sure ? Since, commercially speaking, I can't imagine what
> benefit they would get from this (as opposed to e.g. limiting the amount of
> RAM or disk space), I tend to have a doubt.
>
> Doesn't surprise me at all. I've moved completely off 1and1; I found them
an incredibly low-quality provider who quietly limited many areas of
functionality. I've used Memset in the UK for the last 2 years and have so
far been very impressed.
André, the commercial benefit to 1and1 is summarised in the following
conversation:
Techie: "We've run out of threads, and it'll take days to migrate our
application off 1and1."
Money person: "What can we do?"
Techie: "Pay 1and1 more money for a bigger machine."
Money person: "Erm... OK."
- Peter
Re: How to limit tomcats thread consumption?
Posted by André Warnier <aw...@ice-sa.com>.
Michael Jerger wrote:
> Hi all,
>
> last days I leased a virtual host at 1und1 (a german hoster). Unfortunately
> 1und1 found a new, creative way to limit the joy of using their VPH - they
> limit the number of operating-system processes to 256 processes in total.
a) are you sure ? Since, commercially speaking, I can't imagine what benefit they would
get from this (as opposed to e.g. limiting the amount of RAM or disk space), I tend to
have a doubt.
Also, I am not sure but it seems to me that if there is a maximum number of processes
built-in, that should be a configurable OS setting in Linux.
b) thread != process. See e.g.
http://manpages.ubuntu.com/manpages/intrepid/man7/pthreads.7.html
>
> Thats quite a huge issue, because I want to operate two virtual hosts:
>
> apache-dev -- tomcat-dev -- mysql
> apache-www -- tomcat-prod -- mysql
>
> * mysql uses 50 threads in total
> * apache uses 5
> * tomcat_prod - 109
> * tomcat_dev - 73
>
c) again, are you not confusing threads and processes ?
For Apache httpd e.g., depending on the MPM model used, you will be using either processes
(pre-fork MPM) or threads, or both.
> As u see, there is not much space left for chron jobs / ssh-shells a.s.o.
>
> I tried to limit
> * apache Maxclients (50 in total)
In a prefork MPM, that can indeed lead to up to 51 simultaneous *processes* (aka 1 main
Apache + 50 Apache "children"), IF you have as many simultaneous requests being processed.
I run many sites with Maxclients 20, or less (specially for development sites).
> * mod_jk connection_pool_size (3/40), socket_keepalive=false
There is not really any benefit to have more Apache-Tomcat connections, than your
MaxClients setting above.
> * server.xml:
>
> <Executor name="tomcatDevThreadPool" namePrefix="catalina-exec-"
> daemon="false" maxThreads="(3/40)" maxSpareThreads="5"
> minSpareThreads="1"/>
>
Ideally, you need as many threads as there can be individual *tomcat* requests in the
course of being processed at the same time. There is no benefit in having (or starting)
more than that.
Since presumably all requests pass first through Apache before there reach Tomcat, you
need as a maximum number of Tomcat threads, the same number ax MaxClients in Apache.
> <Connector executor="tomcatDevThreadPool" port="8009"
> protocol="AJP/1.3" URIEncoding="UTF-8"/>
>
>
> But all of these actions result in no change - and pstree shows the same
> number of processes without any change (I use ubunut 10.4, java 1.6.0_20,
> tomcat 7.0.11).
>
> Any idea how to cope with this silly process limit?
>
Change the provider ?
>
> Kind regards,
> Michael
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org