编程专栏 2014-05-18 05:18 采纳率: 0%
浏览 3901

HttpURLConnection可以设置socket send buffer size大小吗

使用apache-jmeter-2.11做上传文件测试,在服务器端发现每次都是按4k大小的数据接收,而在apache-jmeter-2.11中使用HttpURLConnection做文件上传操作,每次write数据量为1k。
java socket默认的send buffer size为8k,是不是HttpURLConnection将socket的这个默认大小设置为了4k呀?

贴一段apache-jmeter-2.11发送文件数据的源码:
/**
* Write the content of a file to the output stream
*
* @param filename the filename of the file to write to the stream
* @param out the stream to write to
* @throws IOException
*/
private static void writeFileToStream(String filename, OutputStream out) throws IOException {
byte[] buf = new byte[1 * 1024]; // default: 1024
// 1k - the previous 100k made no sense (there's tons of buffers
// elsewhere in the chain) and it caused OOM when many concurrent
// uploads were being done. Could be fixed by increasing the evacuation
// ratio in bin/jmeter[.bat], but this is better.
InputStream in = new BufferedInputStream(new FileInputStream(filename));
int read;
boolean noException = false;
try {
int i = 1;
while ((read = in.read(buf)) > 0) {
out.write(buf, 0, read);
//out.flush();
System.out.println(read+" :"+(i++));
}
//out.flush();
System.out.println("send file done.");
noException = true;
}
finally {
if(!noException) {
// Exception in progress
JOrphanUtils.closeQuietly(in);
} else {
in.close();
}
}
}

  • 写回答

1条回答

  • MiceRice 2014-05-19 07:58
    关注

    可以试试这个参数:
    setFixedLengthStreamingMode()

    评论

报告相同问题?

悬赏问题

  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作