java.net.SocketTimeoutException: 60000 millis timeout while waiting for channel to be ready for read
Posted 魏大宾
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了java.net.SocketTimeoutException: 60000 millis timeout while waiting for channel to be ready for read相关的知识,希望对你有一定的参考价值。
环境:
- Spark 2.11-2.0.2
- Hadoop 2.6.5
使用Spark连接HDFS,在高并发的时候,偶尔会遇到以下异常:
[plain] view plain copy
- 2017-01-26 10:30:29,079 ERROR org.apache.hadoop.hdfs.server.datanode.DataNode: xxx:50010:DataXceiver error processing WRITE_BLOCK operation src: /xxx:52827 dst: /xxx:50010
- java.net.SocketTimeoutException: 60000 millis timeout while waiting for channel to be ready for read. ch : java.nio.channels.SocketChannel[connected local=/xxx:50010 remote=/xxx:52827]
- at org.apache.hadoop.net.SocketIOWithTimeout.doIO(SocketIOWithTimeout.java:164)
- at org.apache.hadoop.net.SocketInputStream.read(SocketInputStream.java:161)
- at org.apache.hadoop.net.SocketInputStream.read(SocketInputStream.java:131)
- at java.io.BufferedInputStream.read1(BufferedInputStream.java:256)
- at java.io.BufferedInputStream.read(BufferedInputStream.java:317)
- at java.io.DataInputStream.read(DataInputStream.java:132)
- at org.apache.hadoop.io.IOUtils.readFully(IOUtils.java:192)
- at org.apache.hadoop.hdfs.protocol.datatransfer.PacketReceiver.doReadFully(PacketReceiver.java:213)
- at org.apache.hadoop.hdfs.protocol.datatransfer.PacketReceiver.doRead(PacketReceiver.java:171)
- at org.apache.hadoop.hdfs.protocol.datatransfer.PacketReceiver.receiveNextPacket(PacketReceiver.java:109)
- at org.apache.hadoop.hdfs.server.datanode.BlockReceiver.receivePacket(BlockReceiver.java:496)
- at org.apache.hadoop.hdfs.server.datanode.BlockReceiver.receiveBlock(BlockReceiver.java:891)
- at org.apache.hadoop.hdfs.server.datanode.DataXceiver.writeBlock(DataXceiver.java:758)
- at org.apache.hadoop.hdfs.protocol.datatransfer.Receiver.opWriteBlock(Receiver.java:137)
- at org.apache.hadoop.hdfs.protocol.datatransfer.Receiver.processOp(Receiver.java:74)
- at org.apache.hadoop.hdfs.server.datanode.DataXceiver.run(DataXceiver.java:239)
- at java.lang.Thread.run(Thread.java:662)
出现以上错误是因为datanode的服务线程连接数都被占用,导致Spark等待超时。可以通过以下方法解决:
- 根据datanode的资源情况适当增加的服务线程数:在hdfs-default.xml配置文件里面新增或修改dfs.datanode.handler.count,默认是10
- 增加客户端的超时时间dfs.client.socket-timeout,默认是60000ms,注意,旧版本的Hadoop用的是dfs.socket.timeout,可参考http://hadoop.apache.org/docs/stable/hadoop-project-dist/hadoop-common/DeprecatedProperties.html
- try (JavaSparkContext context = new JavaSparkContext(new SparkConf().setMaster("local[*]").setAppName("test")))
- context.sc().hadoopConfiguration().set("dfs.client.socket-timeout", "300000");
- ......
以上是关于java.net.SocketTimeoutException: 60000 millis timeout while waiting for channel to be ready for read的主要内容,如果未能解决你的问题,请参考以下文章