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

问题描述

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();
}
}
}

解决方案

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

时间: 2024-08-03 07:46:23

HttpURLConnection可以设置socket send buffer size大小吗的相关文章

User select font-face/color/size/backgroundColor设置 字体,颜色,大小,背景色兼容主流浏览器

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta content="text/html;

mysql Sort aborted: Out of sort memory, consider increasing server sort buffer size的解决方法_Mysql

今天在检查mysql服务器的时候提示Sort aborted: Out of sort memory, consider increasing server sort buffer size,安装字面意思就是 sort内存溢出,考虑增加服务器的排序缓冲区(sort_buffer_size)大小 sort_buffer_size=3M join_buffer_size = 3M 下面是针对16G 内存设置的参数: sort_buffer_size = 2M # Sort_Buffer_Size 是

string-使用 Spinner 中选择的值设置 TextView 中 text 的大小

问题描述 使用 Spinner 中选择的值设置 TextView 中 text 的大小 我想使用 spinner 设置一个值,然后在onClick方法中给选定项设置一个Remote View TextView 中text的大小.如何实现? String selected; Context context = WidgetConfig.this; static Spinner spinner; ... spinner.setOnItemSelectedListener(this); public

asp.net使用Socket.Send发送信息及Socket.SendFile传输文件的方法_实用技巧

本文实例讲述了asp.net使用Socket.Send发送信息及Socket.SendFile传输文件的方法.分享给大家供大家参考,具体如下: // Displays sending with a connected socket // using the overload that takes a buffer. public static int SendReceiveTest1(Socket server) { byte[] msg = Encoding.UTF8.GetBytes("Th

电脑怎么设置IE浏览器自动调整图像大小?

  电脑怎么设置IE浏览器自动调整图像大小?          1.打开IE浏览器,打开菜单,点击"Internet选项"; 2.打开Internet选项后,切换到"高级"选项卡; 3.在设置列表中找到"启用自动图像大小调整",勾选该选项,点击确定即可.

win7系统如何设置让文件夹按大小排序

  win7系统如何设置让文件夹按大小排序: 1.在资源管理器中右击,在弹出的菜单里选择"分组依据"下的"更多"; 2.在"选择详细信息"对话框中,选择"大小"; 3.在资源管理器中右击,在弹出的菜单里选择"排序方式"下的"大小"; 4.这个时候你也许认为就解决了问题,WIN7如何单单这样的吧,也算不上进化,不要忘记"分组依据",同样在资源管理器中右击,在弹出的菜单里

为python设置socket代理的方法_python

首先,你得下载SocksiPy这个.解压出来之后里面会有一个socks.py文件.然后你可以把这个文件复制到python安装目录里面的Lib\site-packages中.或者把这个文件复制到程序所在的目录中. 然后就可以再程序中使用socket代理来编写程序了. 下面是示例代码 import socks import socket socks.setdefaultproxy(socks.PROXY_TYPE_SOCKS5,"127.0.0.1",8088) socket.socket

HttpURLConnection 如何设置请求cookie

使用HttpURLConnection 如何设置请求cookie呢?   Java代码   huc.addRequestProperty("content-type", contentType);           if (ValueWidget.isHasValue(cookie)) {               huc.setRequestProperty("Cookie", cookie);           }       如何获取应答的cookie呢

C#pagesetupdialog怎么设置内容缩放适应纸张大小

问题描述 C#pagesetupdialog怎么设置内容缩放适应纸张大小 我在使用Pagesetupdialog去打印一个窗口的时候,窗口太大造成打印的结果不能消失全部的窗口画面.请问怎么去设置内容适应纸张大小,使我打印的内容可以全部显示在A4至内 解决方案 Pagesetupdialog本身没有打印窗口的功能,关键是你的Paint事件的代码怎么写的,你可以在这个里面实现缩放.