gpt4 book ai didi

apache - Tomcat 中的流水线 - 并行?

转载 作者:可可西里 更新时间:2023-11-01 15:29:20 25 4
gpt4 key购买 nike

我正在使用 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 实际上会等待每个请求被处理,然后再开始处理下一个请求,因此处理是连续的

关于apache - Tomcat 中的流水线 - 并行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5748897/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com