John said:
Joseph said:
Roedy said:
One question that I could use advice, is it possible to use Channels
for Process management? My thought is to monitor the output stream
of the Process for OP_READ, and wait for EOF when the process
terminates. Any flaws in my thought?
One area I still have not explored is nio. I have done such things at
very low level poking hardware devices, but not with the nio package.
[snip]
I have been watching Java develop since '96. I avoided it even though
I admired the effort for several reasons. But 1.4 has changed my
thinking, and the nio package has addressed my last concern, moving
back towards multiplex technology. The package allows an alternative
to launching threads for each new client, a time consuming process.
So, then, why aren't you multiplexing your socket listening? That would
save you a whole lot of threads. You would want to look into the
Selector class, which, with some associated classes, provides more or
less an OO version of C's select() function.
Actually, as I have said before, I am using channels for socket
management, and assigning new connections to a connection pool of
created client threads.
You wrote earlier that the back-end app does not make use of stdin /
stdout / stderr to communicate with the caller. Can you wrap it in a
script or other wrapper program that will adapt it to do so? I think
that would allow you to use NIO to multiplex monitoring of the state of
the back-end process invocations as well, hence giving you an entry into
implementing some of the suggestions Roedy has been offering.
Now, I have explored the NIO library, but have not found a
ProcessChannel that monitors a Process, nor a implementation of a
StreamChannel. To implement either as a channel for SelectableChannel I
would need more threads to watch the Process streams. I want to use
blocking threads, to not needlessly eat CPU time, so I would need a
thread per "transaction," or connection in my case. Thus I would need
even more threads.
It really should not be necessary to spawn hundreds of threads for an
application like this. Much as Roedy already said, it is probably not
very useful to launch more than a handful of threads if you have a way
to use that handful to perform all the needed work.
And, you are correct. one thread can handle any number of requests, if
the remote clients are willing to wait to be service. However, as I
have also said, throughput is critical. The remote clients will not
wait long, perhaps five to ten seconds, before the connection is aborted
from the peer. Since the remote client MUST communicate via my
application, to get real work done, aborted connections will result in a
new, quickly generated, connect attempt, and another socket to service,
while the old socket, perhaps waiting in a queue for processing, is now
dead. This potential will only add to the burden of the application I
am creating.
But, if you have suggestion for using NIO channels to monitor Process
object, I would be greatly interested in your input. I have confirmed
that on most OS/hardware I have access to, I can create the desired
number of threads. The problem seems to be localized to Linux, and I
believe MIGHT be a kernel setting, however I have already ruled out
threads-max. On some Linux systems I have tested, I am unable to even
launch the 1015 threads I can on my development system.
Additionally, I have tried JVM 1.5.0(beta), and found that by using the
"-Xprof" option, the limit did not appear, yet without that option, I
still got a 1015 thread limit. I was hoping someone from Sun monitors
this group, and would perhaps offer a reason for the limit I am noticing
on Linux ONLY.