美文网首页
fastdfs 高并发场景下的异常处理

fastdfs 高并发场景下的异常处理

作者: 咦咦咦萨 | 来源:发表于2019-01-17 17:55 被阅读0次

    我们用fastdfs做为商户文件资料的存储,近期随着业务变动,也开始对外提供文件访问服务,发现请求偶尔会报错,异常大概如下:

    java.net.SocketException: Connection reset
            at java.net.SocketInputStream.read(SocketInputStream.java:209) ~[na:1.8.0_74]
            at java.net.SocketInputStream.read(SocketInputStream.java:141) ~[na:1.8.0_74]
            at java.net.SocketInputStream.read(SocketInputStream.java:127) ~[na:1.8.0_74]
            at org.csource.fastdfs.ProtoCommon.recvHeader(ProtoCommon.java:168) ~[fastdfs-client-java-1.27.jar!/:na]
            at org.csource.fastdfs.ProtoCommon.recvPackage(ProtoCommon.java:201) ~[fastdfs-client-java-1.27.jar!/:na]
            at org.csource.fastdfs.TrackerClient.getStorages(TrackerClient.java:392) ~[fastdfs-client-java-1.27.jar!/:na]
            at org.csource.fastdfs.TrackerClient.getFetchStorage(TrackerClient.java:296) ~[fastdfs-client-java-1.27.jar!/:na]
            at org.csource.fastdfs.StorageClient.newReadableStorageConnection(StorageClient.java:1647) ~[fastdfs-client-java-1.27.jar!/:na]
            at org.csource.fastdfs.StorageClient.download_file(StorageClient.java:1118) ~[fastdfs-client-java-1.27.jar!/:na]
            at org.csource.fastdfs.StorageClient.download_file(StorageClient.java:1105) ~[fastdfs-client-java-1.27.jar!/:na]
    
    
    
    java.io.IOException: recv package size -1 != 10
            at org.csource.fastdfs.ProtoCommon.recvHeader(ProtoCommon.java:169) ~[fastdfs-client-java-1.27.jar!/:na]
            at org.csource.fastdfs.ProtoCommon.recvPackage(ProtoCommon.java:201) ~[fastdfs-client-java-1.27.jar!/:na]
            at org.csource.fastdfs.TrackerClient.getStorages(TrackerClient.java:392) ~[fastdfs-client-java-1.27.jar!/:na]
            at org.csource.fastdfs.TrackerClient.getFetchStorage(TrackerClient.java:296) ~[fastdfs-client-java-1.27.jar!/:na]
            at org.csource.fastdfs.StorageClient.newReadableStorageConnection(StorageClient.java:1647) ~[fastdfs-client-java-1.27.jar!/:na]
            at org.csource.fastdfs.StorageClient.download_file(StorageClient.java:1118) ~[fastdfs-client-java-1.27.jar!/:na]
            at org.csource.fastdfs.StorageClient.download_file(StorageClient.java:1105) ~[fastdfs-client-java-1.27.jar!/:na]
            at com.ielpm.images.viewer.FastDFSClient.downloadFile(FastDFSClient.java:173) ~[classes!/:0.0.1-SNAPSHOT]
            at com.ielpm.images.viewer.ViewController.imgViewer(ViewController.java:53) ~[classes!/:0.0.1-SNAPSHOT]
            at sun.reflect.GeneratedMethodAccessor30.invoke(Unknown Source) ~[na:na]
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_74]
            at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_74]
    
    

    软件环境如下:

    解决方法:

    1. 由于fastdfs客户端的实现中,storageClient、trackerServer和storageClient都不是线程安全的,而且,每次调用都会new一个socket连接,调用完成后会关闭,所以不能复用

    2. 在5.05版本中,storage和tracker的默认最大连接数(max_connections)为256,访问量一大就会超出报错,所以要根据场景,适当调整该值的大小。

    相关文章

      网友评论

          本文标题:fastdfs 高并发场景下的异常处理

          本文链接:https://www.haomeiwen.com/subject/mctwdqtx.html