yxjhhdx 2016-08-19 03:02 采纳率: 33.3%
浏览 1502
已采纳

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条回答

  • yxjhhdx 2016-08-19 03:33
    关注

    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

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

问题事件

  • 已采纳回答 4月17日

悬赏问题

  • ¥15 vue3+express部署到nginx
  • ¥20 搭建pt1000三线制高精度测温电路
  • ¥15 使用Jdk8自带的算法,和Jdk11自带的加密结果会一样吗,不一样的话有什么解决方案,Jdk不能升级的情况
  • ¥15 画两个图 python或R
  • ¥15 在线请求openmv与pixhawk 实现实时目标跟踪的具体通讯方法
  • ¥15 八路抢答器设计出现故障
  • ¥15 opencv 无法读取视频
  • ¥15 按键修改电子时钟,C51单片机
  • ¥60 Java中实现如何实现张量类,并用于图像处理(不运用其他科学计算库和图像处理库))
  • ¥20 5037端口被adb自己占了