tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Christopher Schultz <ch...@christopherschultz.net>
Subject Re: Memory Consumption - Using Process Commands from Java program in Tomcat
Date Mon, 30 Jun 2008 02:14:51 GMT
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Arun,

Arun Raj Ramkumar wrote:
| Can you tell me the impact of using following commands in a java
program in
| tomcat?

Yikes! Spawning processes can be dangerous business on a production
system. Be VERY careful what you do, here.

| Will they take more memory?

They will take whatever memory is required of them. However, they do not
directly take memory away from the JVM. Of course, you will need to use
of the JVM resources to track the Process as it runs (and hopefully
completes).

| Will they take time to release memory?

Generally, the OS will reclaim any memory used by a process as soon as
it terminates. Remember: the process must terminate, and there are
certain things that can keep the process around (such as not reading the
stdout and stderr streams from Java -- BE CAREFUL!).

| Is there any other way we can call?

My preferred methos for these types of things is:

1. Store data somewhere central (an RDBMS or the filesystem) and run a
batch job. This divorces job execution from the servlet container, and
tends to be safer and more stable. Of course, if you have any kind of
immediate-response requirements or are expecting synchronous execution,
this is not possible.

2. Have the "outside" program run as a deamon, and communicate via
TCP/IP. Process management is soooo much more of a pain in the heck than
communicating via a socket (although socket connections require more API
work for the programmer).

| to find best way
| print statments on the child perl will affect the parent tomcat?

Just remember that you have to read 100% of the output and error streams
of the child process, or your child process might never die. This is
really bad if you have lots of calls to these processes. You can easily
get an OOME from "too many files open" because each Process gets at
least 3 file handles allocated to it.

| Invoking perl programs like the following ways:
|
| 1) Process process = new ProcessBuilder(params).start();
|  process.waitFor();
|
| 2) Runtime.getRuntime().exec(command+" &");
|
| 3) RunCommand runcmd = new RunCommand(cmd);
| runcmd.start();

Yeah, this is the naive way of executing a process. You need to manage
all the streams, too, or you can run into trouble. There are several
libraries that exist to help you run external processes without having
to do everything yourself. One such library is commons-exec
(http://commons.apache.org/exec/). Check that out and see if you can get
that to work. The API is probably just as simple as what you're doing,
but I think it will be a lot safer -- if you decide that spawning child
processes really is the best thing to do.

Hope that helps,
- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEYEARECAAYFAkhoQZsACgkQ9CaO5/Lv0PALOwCdEvgvpcephqvFcCGI8edm0umP
Y0YAn0qZwt0mJjt22jlPavtrUJqyKNMn
=M32n
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Mime
View raw message