D*0
2 楼
有很多连续的http request,如果每次都重新open一个connection,performance下降
很明显,能不能打开一次,然后多次发送http request呢?放狗了一下,没发现什么方
法,keep-alive好像是默认的。有人说要从tcp socket开始自己写http协议。不知道有
没有做过这方面的大侠指点一下,一下是我测试的代码。这段代码如果每次都重新call
HttpsURLConnection con = HttpsURLConnection)myurl.openConnection(); 就没问
题,但是如果先这样,那个URL里只有第一个值(忘了说这个是REST)。谢谢。
String httpsURL = "https://xxxx.yyyy.com/users.json";
URL myurl = new URL(httpsURL);
HttpsURLConnection con = (HttpsURLConnection)myurl.openConnection();
con.setRequestMethod("PUT");
con.setDoOutput(true);
con.setDoInput(true);
DataOutputStream output = new DataOutputStream(con.getOutputStream()
);
JSONObject json = new JSONObject();
json.put("first", "xxx");
json.put("last", "yyy");
System.out.println(json.toString());
output.writeBytes(json.toString());
output.flush();
json.put("first", "aaa");
json.put("last", "bbbb");
System.out.println(json.toString());
output.writeBytes(json.toString());
output.flush();
json.put("first", "eee");
json.put("last", "rrrr");
System.out.println(json.toString());
output.writeBytes(json.toString());
output.flush();
input = new DataInputStream( con.getInputStream() );
for( int c = input.read(); c != -1; c = input.read() )
System.out.print( (char)c );
System.out.println("Resp Code:"+con .getResponseCode());
System.out.println("Resp Message:"+ con .getResponseMessage());
input.close();
output.close();
con.disconnect();
很明显,能不能打开一次,然后多次发送http request呢?放狗了一下,没发现什么方
法,keep-alive好像是默认的。有人说要从tcp socket开始自己写http协议。不知道有
没有做过这方面的大侠指点一下,一下是我测试的代码。这段代码如果每次都重新call
HttpsURLConnection con = HttpsURLConnection)myurl.openConnection(); 就没问
题,但是如果先这样,那个URL里只有第一个值(忘了说这个是REST)。谢谢。
String httpsURL = "https://xxxx.yyyy.com/users.json";
URL myurl = new URL(httpsURL);
HttpsURLConnection con = (HttpsURLConnection)myurl.openConnection();
con.setRequestMethod("PUT");
con.setDoOutput(true);
con.setDoInput(true);
DataOutputStream output = new DataOutputStream(con.getOutputStream()
);
JSONObject json = new JSONObject();
json.put("first", "xxx");
json.put("last", "yyy");
System.out.println(json.toString());
output.writeBytes(json.toString());
output.flush();
json.put("first", "aaa");
json.put("last", "bbbb");
System.out.println(json.toString());
output.writeBytes(json.toString());
output.flush();
json.put("first", "eee");
json.put("last", "rrrr");
System.out.println(json.toString());
output.writeBytes(json.toString());
output.flush();
input = new DataInputStream( con.getInputStream() );
for( int c = input.read(); c != -1; c = input.read() )
System.out.print( (char)c );
System.out.println("Resp Code:"+con .getResponseCode());
System.out.println("Resp Message:"+ con .getResponseMessage());
input.close();
output.close();
con.disconnect();
g*g
4 楼
Try a client library such as Apache HttpClient instead of trying to reinvent
the wheel. It's easy to configure connection management from there.
call
);
【在 D***0 的大作中提到】
: 有很多连续的http request,如果每次都重新open一个connection,performance下降
: 很明显,能不能打开一次,然后多次发送http request呢?放狗了一下,没发现什么方
: 法,keep-alive好像是默认的。有人说要从tcp socket开始自己写http协议。不知道有
: 没有做过这方面的大侠指点一下,一下是我测试的代码。这段代码如果每次都重新call
: HttpsURLConnection con = HttpsURLConnection)myurl.openConnection(); 就没问
: 题,但是如果先这样,那个URL里只有第一个值(忘了说这个是REST)。谢谢。
: String httpsURL = "https://xxxx.yyyy.com/users.json";
: URL myurl = new URL(httpsURL);
: HttpsURLConnection con = (HttpsURLConnection)myurl.openConnection();
: con.setRequestMethod("PUT");
the wheel. It's easy to configure connection management from there.
call
);
【在 D***0 的大作中提到】
: 有很多连续的http request,如果每次都重新open一个connection,performance下降
: 很明显,能不能打开一次,然后多次发送http request呢?放狗了一下,没发现什么方
: 法,keep-alive好像是默认的。有人说要从tcp socket开始自己写http协议。不知道有
: 没有做过这方面的大侠指点一下,一下是我测试的代码。这段代码如果每次都重新call
: HttpsURLConnection con = HttpsURLConnection)myurl.openConnection(); 就没问
: 题,但是如果先这样,那个URL里只有第一个值(忘了说这个是REST)。谢谢。
: String httpsURL = "https://xxxx.yyyy.com/users.json";
: URL myurl = new URL(httpsURL);
: HttpsURLConnection con = (HttpsURLConnection)myurl.openConnection();
: con.setRequestMethod("PUT");
o*2
6 楼
Turn a HTTP connection into a full-duplex communication
http://javakenai-dev.cognisync.net/blog/2008/09/10/turn-http-co
http://javakenai-dev.cognisync.net/blog/2008/09/14/turn-http-co
http://javakenai-dev.cognisync.net/blog/2008/09/10/turn-http-co
http://javakenai-dev.cognisync.net/blog/2008/09/14/turn-http-co
D*0
10 楼
I can only control my side(client side).
【在 o**2 的大作中提到】
: Turn a HTTP connection into a full-duplex communication
: http://javakenai-dev.cognisync.net/blog/2008/09/10/turn-http-co
: http://javakenai-dev.cognisync.net/blog/2008/09/14/turn-http-co
【在 o**2 的大作中提到】
: Turn a HTTP connection into a full-duplex communication
: http://javakenai-dev.cognisync.net/blog/2008/09/10/turn-http-co
: http://javakenai-dev.cognisync.net/blog/2008/09/14/turn-http-co
D*0
18 楼
g*g
22 楼
If the requests can be executed concurrently, you should do that along with
PoolingClientConnectionManager. If the requests have to be executed
sequentially, there's not much to optimize there beyond keep-alive which the
framework has taken care of. You may still be able to execute multiple
transactions concurrently and achieve high throughput.
Ning Async httpclient is a better option if you need to push the performance
to its extreme.
httpPut
【在 D***0 的大作中提到】
: 谢谢,刚才写了段小程序测试,能写,但是performance一样没达到要求,不知道是我
: 写的问题还是,因为那个httpput还是每次都new,然后httpClient.execute( httpPut
: );在发送完所有的data之后我才
: if(mgr != null)
: {
: mgr.shutdown();
: }
: if(httpClient != null)
: {
: httpClient.getConnectionManager().shutdown();
PoolingClientConnectionManager. If the requests have to be executed
sequentially, there's not much to optimize there beyond keep-alive which the
framework has taken care of. You may still be able to execute multiple
transactions concurrently and achieve high throughput.
Ning Async httpclient is a better option if you need to push the performance
to its extreme.
httpPut
【在 D***0 的大作中提到】
: 谢谢,刚才写了段小程序测试,能写,但是performance一样没达到要求,不知道是我
: 写的问题还是,因为那个httpput还是每次都new,然后httpClient.execute( httpPut
: );在发送完所有的data之后我才
: if(mgr != null)
: {
: mgr.shutdown();
: }
: if(httpClient != null)
: {
: httpClient.getConnectionManager().shutdown();
D*0
24 楼
谢谢,的确这些request不能concurrent,必须sequential,再去试试Ning Async
httpclient。谢谢好虫
with
the
performance
【在 g*****g 的大作中提到】
: If the requests can be executed concurrently, you should do that along with
: PoolingClientConnectionManager. If the requests have to be executed
: sequentially, there's not much to optimize there beyond keep-alive which the
: framework has taken care of. You may still be able to execute multiple
: transactions concurrently and achieve high throughput.
: Ning Async httpclient is a better option if you need to push the performance
: to its extreme.
:
: httpPut
httpclient。谢谢好虫
with
the
performance
【在 g*****g 的大作中提到】
: If the requests can be executed concurrently, you should do that along with
: PoolingClientConnectionManager. If the requests have to be executed
: sequentially, there's not much to optimize there beyond keep-alive which the
: framework has taken care of. You may still be able to execute multiple
: transactions concurrently and achieve high throughput.
: Ning Async httpclient is a better option if you need to push the performance
: to its extreme.
:
: httpPut
b*i
29 楼
你需要的指标到底怎样?比如,需要每秒钟几次?
call
);
【在 D***0 的大作中提到】
: 有很多连续的http request,如果每次都重新open一个connection,performance下降
: 很明显,能不能打开一次,然后多次发送http request呢?放狗了一下,没发现什么方
: 法,keep-alive好像是默认的。有人说要从tcp socket开始自己写http协议。不知道有
: 没有做过这方面的大侠指点一下,一下是我测试的代码。这段代码如果每次都重新call
: HttpsURLConnection con = HttpsURLConnection)myurl.openConnection(); 就没问
: 题,但是如果先这样,那个URL里只有第一个值(忘了说这个是REST)。谢谢。
: String httpsURL = "https://xxxx.yyyy.com/users.json";
: URL myurl = new URL(httpsURL);
: HttpsURLConnection con = (HttpsURLConnection)myurl.openConnection();
: con.setRequestMethod("PUT");
call
);
【在 D***0 的大作中提到】
: 有很多连续的http request,如果每次都重新open一个connection,performance下降
: 很明显,能不能打开一次,然后多次发送http request呢?放狗了一下,没发现什么方
: 法,keep-alive好像是默认的。有人说要从tcp socket开始自己写http协议。不知道有
: 没有做过这方面的大侠指点一下,一下是我测试的代码。这段代码如果每次都重新call
: HttpsURLConnection con = HttpsURLConnection)myurl.openConnection(); 就没问
: 题,但是如果先这样,那个URL里只有第一个值(忘了说这个是REST)。谢谢。
: String httpsURL = "https://xxxx.yyyy.com/users.json";
: URL myurl = new URL(httpsURL);
: HttpsURLConnection con = (HttpsURLConnection)myurl.openConnection();
: con.setRequestMethod("PUT");
s*e
30 楼
there are four tcp/ip keep alive mechanisms (server push). They are Polling,
long polling, http streaming and web socket. Among them only websocket is a
real duplex mechanism. But unfortunately not all browsers support websocket
.
Frameworks can make the connection management transparent. try atmosphere
framework to see if it meets your need.
long polling, http streaming and web socket. Among them only websocket is a
real duplex mechanism. But unfortunately not all browsers support websocket
.
Frameworks can make the connection management transparent. try atmosphere
framework to see if it meets your need.
D*0
32 楼
谢谢指点,
恩,这四种其实最想使用web socket,以前弄过一段,但是就是因为浏览器的原因,就
没往这个方向走,其实主要还是想实现一个前台控制,后台push的结构。主要是计算都
在后台,前台实时更新显示和接收user各种控制点击。试过pushlet,也知道comet,但
是没在实际当中用过。感觉web socket是最符合要求的。现在这个问题是看见了有个
firebase的东东,看看能不能用它当中转,目前写的一些测试程序显示performance不
是很好,所以才来问问。
Polling,
a
websocket
【在 s******e 的大作中提到】
: there are four tcp/ip keep alive mechanisms (server push). They are Polling,
: long polling, http streaming and web socket. Among them only websocket is a
: real duplex mechanism. But unfortunately not all browsers support websocket
: .
: Frameworks can make the connection management transparent. try atmosphere
: framework to see if it meets your need.
恩,这四种其实最想使用web socket,以前弄过一段,但是就是因为浏览器的原因,就
没往这个方向走,其实主要还是想实现一个前台控制,后台push的结构。主要是计算都
在后台,前台实时更新显示和接收user各种控制点击。试过pushlet,也知道comet,但
是没在实际当中用过。感觉web socket是最符合要求的。现在这个问题是看见了有个
firebase的东东,看看能不能用它当中转,目前写的一些测试程序显示performance不
是很好,所以才来问问。
Polling,
a
websocket
【在 s******e 的大作中提到】
: there are four tcp/ip keep alive mechanisms (server push). They are Polling,
: long polling, http streaming and web socket. Among them only websocket is a
: real duplex mechanism. But unfortunately not all browsers support websocket
: .
: Frameworks can make the connection management transparent. try atmosphere
: framework to see if it meets your need.
o*2
33 楼
楼主,你的问题解决了没有?
o*2
35 楼
我觉得你这里有几个相关但独立的问题:
1,performance问题;
2,http protocol细节问题;
3,Java对http protocol的支持及其实现细节问题;
4,其他libraries对http protocol的支持及其实现细节问题。
我个人认为你最好把第二个问题弄清楚,这样就算performance问题最终解决不了,你
起码也学到了新的知识,对不对?
要弄清楚http的细节,特别是你的server特定的情况下的细节,你应该用socket来编测
试程序,这样你才能知道到底哪些bytes去了server,和哪些bytes从server来。这应该
不难,你用proxy软件就可以看到你的现有软件的http内容,然后用socket来发这些内
容。再根据http spec,修改或添加内容,并试验你的多request方案。
【在 D***0 的大作中提到】
: 还在试验,现在还不知道是不是因为第三方的performance的原因,还是我的写法有问
: 题,还是java本身的performance的问题,谢谢关心
1,performance问题;
2,http protocol细节问题;
3,Java对http protocol的支持及其实现细节问题;
4,其他libraries对http protocol的支持及其实现细节问题。
我个人认为你最好把第二个问题弄清楚,这样就算performance问题最终解决不了,你
起码也学到了新的知识,对不对?
要弄清楚http的细节,特别是你的server特定的情况下的细节,你应该用socket来编测
试程序,这样你才能知道到底哪些bytes去了server,和哪些bytes从server来。这应该
不难,你用proxy软件就可以看到你的现有软件的http内容,然后用socket来发这些内
容。再根据http spec,修改或添加内容,并试验你的多request方案。
【在 D***0 的大作中提到】
: 还在试验,现在还不知道是不是因为第三方的performance的原因,还是我的写法有问
: 题,还是java本身的performance的问题,谢谢关心
D*0
36 楼
其实发送和接收的都没问题,就是速度不能达到要求,用wireshark看看和server的
communication应该有帮助。谢谢指点,我会从这几方面查的。
【在 o**2 的大作中提到】
: 我觉得你这里有几个相关但独立的问题:
: 1,performance问题;
: 2,http protocol细节问题;
: 3,Java对http protocol的支持及其实现细节问题;
: 4,其他libraries对http protocol的支持及其实现细节问题。
: 我个人认为你最好把第二个问题弄清楚,这样就算performance问题最终解决不了,你
: 起码也学到了新的知识,对不对?
: 要弄清楚http的细节,特别是你的server特定的情况下的细节,你应该用socket来编测
: 试程序,这样你才能知道到底哪些bytes去了server,和哪些bytes从server来。这应该
: 不难,你用proxy软件就可以看到你的现有软件的http内容,然后用socket来发这些内
communication应该有帮助。谢谢指点,我会从这几方面查的。
【在 o**2 的大作中提到】
: 我觉得你这里有几个相关但独立的问题:
: 1,performance问题;
: 2,http protocol细节问题;
: 3,Java对http protocol的支持及其实现细节问题;
: 4,其他libraries对http protocol的支持及其实现细节问题。
: 我个人认为你最好把第二个问题弄清楚,这样就算performance问题最终解决不了,你
: 起码也学到了新的知识,对不对?
: 要弄清楚http的细节,特别是你的server特定的情况下的细节,你应该用socket来编测
: 试程序,这样你才能知道到底哪些bytes去了server,和哪些bytes从server来。这应该
: 不难,你用proxy软件就可以看到你的现有软件的http内容,然后用socket来发这些内
相关阅读
Re: how to integrate java api doc with eTomcat和什么一起作Application Server?How to rename a file to Chinese?问个最基本问题感谢fryingfish。Calling Java from C/C++Pls help how to open a dialog or frame?[转载] Urgent Help needed about Java Servlet?Java如何调用MATLAB?pdf -> txtjsp开发请教How to combine java code with applet?急问:装了JSDK2.0,servlet engine 不 运 行 ?how to deploy a .NET project with database系统class请教学java的方法请推荐一些J2EE 和 Oracle PL/SQL的速成tutorialRe: 怎么取到Weblogic server里的所有用户信息?发现weblogic 8.1 workshop一个bugjbuilderx 注册问题