我正在使用TomCat编写服务,并试图了解HTTP1.1的流水线功能及其在Tomcat中的实现.
这是我的问题:
1] TomCat中的流水线并行.即=>获得流水线请求后,是否将其分解为单个请求并同时调用所有这些请求?
这是我做的一个小测试:从我的测试看起来像,但我试图找到一个授权文件等?
public static void main(String[] args) throws IOException, InterruptedException
{
Socket socket = new Socket();
socket.connect(new InetSocketAddress("ServerHost", 2080));
int bufferSize = 166;
byte[] reply = new byte[bufferSize];
DataInputStream dis = null;
//first without pipeline - TEST1
// socket.getOutputStream().write(
// ("GET URI HTTP/1.1\r\n" +
// "Host: ServerHost:2080\r\n" +
// "\r\n").getBytes());
//
// final long before = System.currentTimeMillis();
// dis = new DataInputStream(socket.getInputStream());
// Thread.currentThread().sleep(20);
// final long after = System.currentTimeMillis();
//
// dis.readFully(reply);
// System.out.println(new String(reply));
//now pipeline 3 Requests - TEST2
byte[] request = ("GET URI HTTP/1.1\r\n" +
"Host:ServerHost:2080\r\n" +
"\r\n"+
"GET URI HTTP/1.1\r\n" +
"Host: ServerHost:2080\r\n" +
"\r\n"+
"GET URI HTTP/1.1\r\n" +
"Host: ServerHost:2080\r\n" +
"\r\n").getBytes();
socket.getOutputStream().write(request);
bufferSize = 1000*1;
reply = new byte[bufferSize];
final long before = System.currentTimeMillis();
dis = new DataInputStream(socket.getInputStream());
Thread.currentThread().sleep(20);
final long after = System.currentTimeMillis();
dis.readFully(reply);
System.out.println(new String(reply));
long time = after-before;
System.out.println("Request took :"+ time +"milli secs");
}
在上述测试中,在test2中,响应时间不是[20 * 3 = 60 ms].实际的GET请求非常快.这暗示这些是并行化的,除非我遗漏了什么?
2] Tomcat中的默认管道深度是多少?我该如何控制它?
3]当在服务器端允许流水线操作时,我是否需要考虑其他任何事情,假设客户端在处理流水线操作时遵循http://www.w3.org/Protocols/rfc2616/rfc2616-sec8.html#sec8.1.4规范?欢迎任何经验.
最佳答案 我有一个关于Apache如何工作的类似问题,并且经过多次测试后我可以确认Apache确实在开始处理下一个请求之前等待每个请求被处理,因此处理是SEQUENTIAL