Some of my servlets will involve heavy procession and time-consuming. And other servlets are simple. If the heavy servlet calls are very high in number, the simple servlets cannot be used. so, I want to limit the heavy servlets that it can use only up to 50% of the total CPU. Is it possible? if so, please explain how/where to proceed in tomcat.
Capsulate the code away from the rest of the application as war
then
create a secound instance of Tomcat and configure via the operating system the priority.
Ubuntu (Linux) system priority
or
try to set threadPriority into the Executor (thread pool) in Tomcat
Related
Assume we have a computer with four physical cores, and we want to decrease latency of a task and best number of threads to do that is 4.
But if we are in a web application, and we use an application server(or servlet container) like tomcat, jetty, netty, I think for doing throughput performance issue, that application server uses 4 threads.
At this point, if we want to use 4 threads to decrease latency of a task, Given that 4 threads is used by application server. With using multi threading, we can not get the most or great benefits. Is that true for web applications?
Thank you so much in advance.
Is there any config in tomcat where in I can mention that start all application at same time when tomcat restarts. This is to avoid latency during tomcat restarts.
The best you can do is configure a suitably large startStopThreads setting for the <Host .../> element in server.xml so each Context starts in a parallel thread.
How successful this is will depend on how many cores you have on your system compared to the number of web applications and the relative start times of each web application.
Full details of the startStopThreads are available in the Tomcat Documentation.
They all start automatically, I'm not sure what else you need.
AFAIK they're started sequentially, one after the other - probably this is what you're aiming at. I'm not aware of a multi-threaded concurrent start, but even if this would be the case, they'd all have an individual startup time anyways, so you might shorten the time, but still have the same problems.
You can counter any problem by making your tomcat available to the outside world only when it has fully been started up (e.g. through proper loadbalancer configuration). If your applications take too long to inintialize, you might want to work on this issue as well.
I'd like to run a web container where each webapp runs in its own process (JVM). Incoming requests get forwarded by a proxy webapp running on port 80 to individual webapps, each (webapp) running on its own port in its own JVM.
This will solve three problems:
Webapps using JNI (where the JNI code changes between restarts) cannot be restarted. There is no way to guarantee that the old webapp has been garbage-collected before loading the new webapp, so when the code invokes System.loadLibrary() the JVM throws: java.lang.UnsatisfiedLinkError: Native Library x already loaded in another classloader.
Libraries leak memory every time a webapp is reloaded, eventually forcing a full server restart. Tomcat has made headway in addressing this problem but it will never be completely fixed.
Faster restarts. The mechanism I'm proposing would allow near-instant webapp restarts. We no longer have to wait for the old webapp to finish unloading, which is the slowest part.
I've posted a RFE here and here. I'd like to know what you think.
Does any existing web container do this today?
I'm closing this question because I seem to have run into a dead end: http://tomcat.10.n6.nabble.com/One-process-per-webapp-td2084881.html
As a workaround, I'm manually launching a separate Jetty instance per webapp.
Can't you just deploy one app per container and then use DNS entries and reverse proxies to do the exact same thing? I believe Weblogic has something like this in the form of managed domains.
No, AFAIK, none of them do, probably because Java web containers emphasize following the servlet API - which spins off a thread per http request. What you want would be a fork at the JVM level - and that simply isn't a standard Java idiom.
If I understand correctly you are asking for the standard features for enterprise quality servers such IBM's WebSphere Network Deployment (disclaimer I work for IBM) where you can distribute applications across many JVMs, and those JVMs can in fact be distributed across many physical machines.
I'm not sure that your fundamental premise is correct though. It's not necessary to restart a whole JVM in order to deploy a new version of an application. Many app servers will use a class-loader strategy that allows them to discard a version of an app and load a new one.
We have several Java web-applications that need to be deployed on the same machine, over tomcat. The web-applications are not related to each other. Some of them do intensive I/O and CPU operations and consume much memory.
Under the above conditions, which approach is recommended - having a single tomcat with multiple webapps, or multiple tomcats each running a single webapp ?
If all webapps are deployed on the same tomcat, is there a way to guarantee minimum resources per webapp ? I.e. minimum amount of memory, number of threads, etc.
Thanks,
Arnon.
What we did at our company is we run 1 application per instance of Tomcat. We originally started with multiple instances and it occurred occasionally that one application would affect the other, especially if you had to restart the Tomcat instance.
One thing that might be worth evaluating is Spring's TC Server.
http://www.springsource.com/developer/tcserver
Similar to #tjg184 's experience. I would recommend running a tomcat per application instance. If you have a decent config and process management system, the incremental cost is not all that high and it gives you the best isolation possible without separate vm's for each tomcat instance. You could start with a single tomcat and some solid monitoring and then see if you need to move to one tomcat per app.
I'm writing a java application that runs in Tomcat, on a multi-core hardware.
The application executes an algorithm and returns the answer to the user. The problem is that even when I run two requests simultaneously, the tomcat process uses at most one CPU core.
As far as I understand each request in Tomcat is executed in separate thread, and JVM should run each thread on separate CPU core.
What could be the problem that bounds the JVM or Tomcat to use no more than one core?
Thanks in advance.
Are you sure that two threads are being created. You could simply print the name of the thread as a quick test.
What happens if you run the algorithm in a standalone app?
All the processor management will be taken care by the server itself. It is not mandatory that if you pass two requests, it should use two CPUs.
Are you executing any synchronized blocks/methods which would force serial execution? The tomcat connector configuration in server.xml controls the request thread pool - but the default is 200 threads, IIRC.
Here is the procedure to do a load balancing in tomcat http://tomcat.apache.org/tomcat-5.5-doc/balancer-howto.html
I think this will work with Tomcat 6 too as they mentioned balancer webapp is shipped with tomcat 5.0 and later.