我正在使用TomCat編寫服務,並試圖瞭解HTTP1.1的流水線功能及其在Tomcat中的實現。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的同樣的問題http://serverfault.com/questions/266184/does-apache-webserver-process-http-pipelined-requests-in-parallel – 2011-05-04 21:06:01