SocketException, Broken pipe , 为什么 1000 ?

linux 上,使用HTTPClient 发送请求到 远程服务器,在1000个并发以内(包括1000) 的时候无任何异常, 但是只要超过1000, 即使是1001, 则出现问题:

INFO [08-17 15:52:12] [Thread-2024] org.apache.http.impl.client.DefaultRequestDirector.tryExecute(696) | I/O exception (java.net.SocketException) caught when processing request to {}->http://192.168.4.190:80: Broken pipe
INFO [08-17 15:52:12] [Thread-2024]
org.apache.http.impl.client.DefaultRequestDirector.tryExecute(706) | Retrying request to {}->http://192.168.4.190:80

不知道为什么是 1000 , 不知道哪里有限制 刚好是1000 。

windows上执行同样的代码就没有这样的问题现象。这太奇怪了, 我百思不得其解。 请求各位大神看看。

java代码:

import java.io.File;
import java.util.Date;
import java.util.concurrent.ExecutionException;

public class TestHTTP {

// 线程池的容量

/**
 * @param args
 * @throws ExecutionException 
 * @throws InterruptedException 
 */
public static void main(String[] args) throws InterruptedException, ExecutionException {

    int cnt = 2001;
    if (args.length > 0 ) {
        cnt = StringUtil.str2Int(args[0]);
    }

    System.out.println(111 +  new Date().toString());

    for (int i = 0; i < cnt; i++) {

        TTT ttt = new TTT();// f, "test"
        Thread t = new Thread(ttt);
        t.start();
    }
}

}

class TTT extends Thread {

@Override
public void run() {

    String pathname = "E:\\test\\cca.txt";
    pathname = "C:\\Users\\Public\\Documents\\data.txt";
    pathname = "/usr/linkapp/bin/tomcat-master/lktest/data.txt";
    File f = new File(pathname);
    String key = LKRestUtil.put(f);

    System.out.println(" key : " + key + new Date().toString());

}

}

LKRestUtil.put 方法 :

    HttpClient httpClient = getHttpClient(); // 从连接池中获取 
    String url = "http://"+MyNodeStatusChecker.mainHost +"/cmd/put";
    HttpPost httppost = new HttpPost(url);

    httppost.setHeader("content-type", "application/octet-stream");

    httppost.setHeader("x-my-policy", policy );
    httppost.setHeader("Connection", "keep-alive");

    ByteArrayEntity entity = new ByteArrayEntity(data);
    httppost.setEntity(entity);

    String key = "";
    try {
        HttpResponse response = httpClient.execute(httppost, context);
        HttpEntity entity2 = response.getEntity();

        if (entity2 != null) {
            StatusLine statusLine = response.getStatusLine();
            int statusCode = statusLine.getStatusCode();

            if (statusCode == 200) {
                Header[] allHeaders = response.getAllHeaders();
                for (int i = 0; i < allHeaders.length; i++) {
                    Header header = allHeaders[i];
                    if ("x-my-key".equals(header.getName())) {
                        key = header.getValue();
                        //System.out.println(header.getName() +" : "+ header.getValue());
                    }
                }
            } else {
                return "MyError:"+statusCode;
            }
        } else {
            return "MyError: entity2 is null "+ entity2;
        }
        EntityUtils.consume(entity);
    } catch (Exception e) {
        httppost.abort();
        logger.error("My出现异常: " + e.toString());
        return "MyError:" + e.getMessage();
    }finally{
        httppost.releaseConnection();
    }

1个回答

open files 已经修改过了的:

ulimit -a

core file size (blocks, -c) 0
data seg size (kbytes, -d) unlimited
scheduling priority (-e) 0
file size (blocks, -f) unlimited
pending signals (-i) 62812
max locked memory (kbytes, -l) 64
max memory size (kbytes, -m) unlimited
open files (-n) 2024
pipe size (512 bytes, -p) 8
POSIX message queues (bytes, -q) 819200
real-time priority (-r) 0
stack size (kbytes, -s) 10240
cpu time (seconds, -t) unlimited
max user processes (-u) 62812
virtual memory (kbytes, -v) unlimited
file locks (-x) unlimited

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐