Process Hadoop RPC服务器没有停止
我试图使用Hadoop IPC在它们之间创建一个简单的父子进程。结果表明,程序执行并打印结果,但它没有退出。这是它的代码Process Hadoop RPC服务器没有停止,process,hadoop,ipc,rpc,Process,Hadoop,Ipc,Rpc,我试图使用Hadoop IPC在它们之间创建一个简单的父子进程。结果表明,程序执行并打印结果,但它没有退出。这是它的代码 interface Protocol extends VersionedProtocol{ public static final long versionID = 1L; IntWritable getInput(); } public final class JavaProcess implements Protocol{ Server server;
interface Protocol extends VersionedProtocol{
public static final long versionID = 1L;
IntWritable getInput();
}
public final class JavaProcess implements Protocol{
Server server;
public JavaProcess() {
String rpcAddr = "localhost";
int rpcPort = 8989;
Configuration conf = new Configuration();
try {
server = RPC.getServer(this, rpcAddr, rpcPort, conf);
server.start();
} catch (IOException e) {
e.printStackTrace();
}
}
public int exec(Class klass) throws IOException,InterruptedException {
String javaHome = System.getProperty("java.home");
String javaBin = javaHome +
File.separator + "bin" +
File.separator + "java";
String classpath = System.getProperty("java.class.path");
String className = klass.getCanonicalName();
ProcessBuilder builder = new ProcessBuilder(
javaBin, "-cp", classpath, className);
Process process = builder.start();
int exit_code = process.waitFor();
server.stop();
System.out.println("completed process");
return exit_code;
}
public static void main(String...args) throws IOException, InterruptedException{
int status = new JavaProcess().exec(JavaProcessChild.class);
System.out.println(status);
}
@Override
public IntWritable getInput() {
return new IntWritable(10);
}
@Override
public long getProtocolVersion(String paramString, long paramLong)
throws IOException {
return Protocol.versionID;
}
}
下面是子进程类。然而,我已经意识到,这是由于服务器端的RPC.getServer,它才是罪魁祸首。是已知的hadoop bug,还是我遗漏了什么
public class JavaProcessChild{
public static void main(String...args){
Protocol umbilical = null;
try {
Configuration defaultConf = new Configuration();
InetSocketAddress addr = new InetSocketAddress("localhost", 8989);
umbilical = (Protocol) RPC.waitForProxy(Protocol.class, Protocol.versionID,
addr, defaultConf);
IntWritable input = umbilical.getInput();
JavaProcessChild my = new JavaProcessChild();
if(input!=null && input.equals(new IntWritable(10))){
Thread.sleep(10000);
}
else{
Thread.sleep(1000);
}
} catch (Throwable e) {
e.printStackTrace();
} finally{
if(umbilical != null){
RPC.stopProxy(umbilical);
}
}
}
}
我们通过邮件解决了这个问题。但我只想把我的两分钱给公众: 因此,不让主线程结束的线程是org.apache.hadoop.ipc.Server$Reader。 原因是,readSelector.select的实现;是不可中断的。如果仔细查看调试器或线程转储,它将永远等待该调用,即使主线程已被清理 两种可能的修复方法: 让读者线程成为一个执事不那么酷,因为选择器 无法正确清理,但过程将结束 中断线程池时,从外部显式关闭readSelector 然而,这是Hadoop中的一个bug,我没有时间查看JIRAs。也许这个问题已经解决了,不管怎样,旧的IPC已经被protobuf和节俭所取代 顺便说一句,这取决于选择器的实现,我在debian/windows系统上观察到了这些僵尸,但在redhat/solaris上没有观察到 如果有人对Hadoop 1.0的补丁感兴趣,请发电子邮件给我。我将在不久的将来整理JIRA bug,并在这里编辑更多信息。也许这是固定的同时无论如何