FastDfs异常处理

1  receive conent error java.net.SocketTimeoutException: Read timed out/com.github.tobato.fastdfs.domain.conn.ConnectionManager - execute fdfs command error
com.github.tobato.fastdfs.exception.FdfsIOException: 客户端连接服务端出现了io异常:socket io exception occured while receive content

客户端报如下错误(客户端每分钟4000个请求上传文件100K)

2020-01-10 16:29:02.782 [Thread-23] ERROR com.github.tobato.fastdfs.domain.proto.AbstractFdfsCommand - receive conent error
java.net.SocketTimeoutException: Read timed out
    at java.net.SocketInputStream.socketRead0(Native Method)
    at java.net.SocketInputStream.socketRead(SocketInputStream.java:116)
    at java.net.SocketInputStream.read(SocketInputStream.java:171)
    at java.net.SocketInputStream.read(SocketInputStream.java:141)
    at java.net.SocketInputStream.read(SocketInputStream.java:127)
    at com.github.tobato.fastdfs.domain.proto.ProtoHead.createFromInputStream(ProtoHead.java:103)
    at com.github.tobato.fastdfs.domain.proto.AbstractFdfsCommand.receive(AbstractFdfsCommand.java:103)
    at com.github.tobato.fastdfs.domain.proto.AbstractFdfsCommand.execute(AbstractFdfsCommand.java:50)
    at com.github.tobato.fastdfs.domain.conn.ConnectionManager.execute(ConnectionManager.java:81)
    at com.github.tobato.fastdfs.domain.conn.ConnectionManager.executeFdfsCmd(ConnectionManager.java:65)
    at com.github.tobato.fastdfs.service.DefaultFastFileStorageClient.uploadFileAndMetaData(DefaultFastFileStorageClient.java:223)
    at com.github.tobato.fastdfs.service.DefaultFastFileStorageClient.uploadFile(DefaultFastFileStorageClient.java:112)
    at com.github.tobato.fastdfs.service.DefaultFastFileStorageClient.uploadFile(DefaultFastFileStorageClient.java:68)
    at com.cf.viias.config.fastdfs.FastDFSClientWrapper.uploadFile(FastDFSClientWrapper.java:44)
    at com.cf.viias.service.PushFaceService$1.run(PushFaceService.java:138)
    at java.lang.Thread.run(Thread.java:748)
2020-01-10 16:29:02.782 [Thread-18] ERROR com.github.tobato.fastdfs.domain.conn.ConnectionManager - execute fdfs command error
com.github.tobato.fastdfs.exception.FdfsIOException: 客户端连接服务端出现了io异常:socket io exception occured while receive content
    at com.github.tobato.fastdfs.domain.proto.AbstractFdfsCommand.execute(AbstractFdfsCommand.java:53)
    at com.github.tobato.fastdfs.domain.conn.ConnectionManager.execute(ConnectionManager.java:81)
    at com.github.tobato.fastdfs.domain.conn.ConnectionManager.executeFdfsCmd(ConnectionManager.java:65)
    at com.github.tobato.fastdfs.service.DefaultFastFileStorageClient.uploadFileAndMetaData(DefaultFastFileStorageClient.java:223)
    at com.github.tobato.fastdfs.service.DefaultFastFileStorageClient.uploadFile(DefaultFastFileStorageClient.java:112)
    at com.github.tobato.fastdfs.service.DefaultFastFileStorageClient.uploadFile(DefaultFastFileStorageClient.java:68)
    at com.cf.viias.config.fastdfs.FastDFSClientWrapper.uploadFile(FastDFSClientWrapper.java:44)
    at com.cf.viias.service.PushFaceService$1.run(PushFaceService.java:138)
    at java.lang.Thread.run(Thread.java:748)
Caused by: java.net.SocketTimeoutException: Read timed out
    at java.net.SocketInputStream.socketRead0(Native Method)
    at java.net.SocketInputStream.socketRead(SocketInputStream.java:116)
    at java.net.SocketInputStream.read(SocketInputStream.java:171)
    at java.net.SocketInputStream.read(SocketInputStream.java:141)
    at java.net.SocketInputStream.read(SocketInputStream.java:127)
    at com.github.tobato.fastdfs.domain.proto.ProtoHead.createFromInputStream(ProtoHead.java:103)
    at com.github.tobato.fastdfs.domain.proto.AbstractFdfsCommand.receive(AbstractFdfsCommand.java:103)
    at com.github.tobato.fastdfs.domain.proto.AbstractFdfsCommand.execute(AbstractFdfsCommand.java:50)
    ... 8 common frames omitted

解决方案:

出现此错误的本质是服务端处理不过来了客户端的请求,核心是需要调高服务端的处理能力,也可以增加客户端超时时长 ,让客户端等待服务端处理。

客户端优化

springboot 将 fdfs.so-timeout=1500 增大 fdfs.so-timeout=5000(其实质是调整了  socket.setSoTimeout(soTimeout))

 

服务端优化 

可以增加服务端节点数量,如果没有条件 可以调整如下参数

优化Storage的配置参数

1、accept_threads 该参数决定接收客户端连接的线程数,默认值为1,适当放大该参数可改善Storage处理连接的能力,改成     2
2、work_threads 工作线程用来处理网络IO,默认值为4,该参数影响Stroage可以同时处理的连接数,适当的调整这里改为20.
3、disk_reader_threads 读取磁盘数据的线程数,对应到每个存储路径,线上环境Storage只有一个路径,默认为1,这里改为4、disk_writer_threads 写磁盘的线程数量,也是对应一个存储路径,默认为1这里修改为5 ,提高读取磁盘的线程数.
5  如果有条件增加磁盘 ,可以调整

# path(disk or mount point) count, default value is 1
store_path_count=1
# 存放文件时storage server支持多个路径(例如磁盘)。这里配置存放文件的基路径数目,通常只配一个目录。

# store_path#, based 0, if store_path0 not exists, it's value is base_path
# the paths must be exist
store_path0=/home/yuqing/fastdfs
#store_path1=/home/yuqing/fastdfs2
# 逐一配置store_path个路径,索引号基于0。注意配置方法后面有0,1,2 ......,需要配置0到store_path - 1。

你可能感兴趣的:(FastDFS)