Comments (4)
友情提示:TrackerClient和StorageClient都是非线程安全的,需要每个线程实例化一份。
from fastdfs-client-java.
每次进行上传文件的时候,都已经实例化TrackerClient和StorageClient;
`public class FastDFSTest{
public static void main(String[] args) throws IOException, MyException{
String local_filename = "D:\smallData.xml";
FastDFSBean fb = new FastDFSBean();
fb.setFileName("TestFile");
fb.setFileExt("xml");
File file = new File(local_filename);
fb.setFile(file);
Resource resource = new FileSystemResource("d:\\fdfs_client.conf");
File file2 = resource.getFile();
String configFile = file2.getAbsolutePath();
ClientGlobal.init(configFile);
ExecutorService fixedThreadPool = Executors.newFixedThreadPool(100);
for (int i = 0; i < 50; i++) {
fixedThreadPool.execute(new FastdfsThread(fb));
}
}
}`
线程如下:
` @OverRide
public void run() {
try {
TrackerServer trackerServer = null;
StorageServer storageServer = null;
for (int i = 0; i < 100000; i++) {
TrackerClient tracker = new TrackerClient();
trackerServer = tracker.getConnection();
StorageClient storageClient = new StorageClient(trackerServer, storageServer);
NameValuePair nvp[] = new NameValuePair[] {
new NameValuePair("age", i+""),
new NameValuePair("sex", Thread.currentThread().getName()+i)
};
byte[] filebtyes = fileToBytes(this.bean.getFile());//bean为file的实体类
String fileIds[] = storageClient.upload_file(filebtyes, this.bean.getFileExt(), nvp);
System.out.println("文件数:"+i+" 组名:" + fileIds[0]+" 路径: " + fileIds[1]);
trackerServer.close();
}
} catch (IOException e) {
e.printStackTrace();
} catch (MyException e) {
e.printStackTrace();
}
}`
根据上述的代码执行,无法通过压力测试....也尝试过将TrackerClient tracker = new TrackerClient(); trackerServer = tracker.getConnection(); 放到for循环外,结果一样;期待解答,谢谢
from fastdfs-client-java.
我的一个猜测,没有验证,仅供参考哈。
你这总共有50个线程,每个线程会创建10w个storageClient,每个storageClient都会去建立一个socket上传完成之后又关闭,所以,这段代码理论上会执行500w次socket的连接和关闭操作,是不是超出了服务器的承受能力了呢?
from fastdfs-client-java.
楼上说的没错,短时间内500w个连接,会占用500w个socket端口,而linux上socket最多只有65535个,超过后就开始从头开始分配,而释放tcp端口是需要几十秒的时间的,所以会出现Address already in use。你没必要在线程的for循环里创建storageClient,只要在线程开始的时候创建一个storageClient就可以,然后这个线程共享这个storageClient。
from fastdfs-client-java.
Related Issues (20)
- 关于所有带有1的对象和原对象的问题 HOT 1
- 获取IP地址错误 HOT 2
- 获取storageServer 连接失败connect to server 127.0.0.1:23000 fail, emsg:Connection refused: connect HOT 1
- 麻烦作者把jar包推送到maven仓库吧,不然挺麻烦的 HOT 1
- 请问一下fastdfs client能否指定上传的目录呢? HOT 2
- 申请发布到 Maven **仓库
- TrackerClient.listStorages协议传参最大长度和服务端不太符合
- java.lang.ArrayIndexOutOfBoundsException: Input to decode not an even multiple of 4 characters; pad with =. HOT 1
- 已经被删除的文件但是get_file_info方法会返回数据
- com.github.tobato.fastdfs.exception.FdfsConnectException: 无法获取服务端连接资源 端口号为0 HOT 1
- 推送maven**仓库 HOT 4
- fastdfs集群分片上传问题 HOT 2
- 建议支持文件同步不完整时,下载请求可以自动回源重定向
- so terrible
- ProtoStructDecoder.java有不安全的操作
- 该如何获取某个组下的全部文件 HOT 3
- 【分享问题】upload方法如果通过available()获取文件大小值大于INT的最大值,将会发生越界异常 HOT 2
- StorageClient需要每次调用时创建吧 Test样例中有些误导 HOT 1
- fastdfs是否支持S3?
- fastdfs的Tracker和nginx的区别是什么? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from fastdfs-client-java.