web 服务器中的 http 请求

2019-04-27  本文已影响0人  良人与我

关于HTTP

HTTP/1.1 当前版本。持久连接被默认采用,并能很好地配合代理服务器工作。还支持以管道方式同时发送多个请求,以便降低线路负载,提高传输速度。

http 底层是通过 tcp 实现的,为了省去 每次建立链接的开销采用了长连接的方式。

spring boot 中 tomcat的 一些默认配置

server.tomcat.accept-count=100 # Maximum queue length for incoming connection requests when all possible request processing threads are in use.
server.tomcat.max-connections=10000 # Maximum number of connections that the server accepts and processes at any given time.
server.tomcat.max-threads=200 # Maximum amount of worker threads.
server.tomcat.min-spare-threads=10 # Minimum amount of worker threads.
server.tomcat.accept-count=100 # Maximum queue length for incoming connection requests when all possible request processing threads are in use.

可以看到最大connect 数是 10000 , 这里指的就是 长连接。
那么如果资源不够会出现什么情况呢?
如果服务器已经饱和无法处理 ,会回复服务器正忙。
如果服务挂掉了 会返回服务器不可达。

例如如下情况

1.max-threads 已经达到上限 建立链接请求 max-connection 未满。
用户的 数据在tcp 层面会接收,然后等待响应。
等到有空余线程 就会处理他,只要没超过http最大相应时间就能成功。

2.max-threads 已经达到上限 处理数据请求(get 、 post)。
如果tcp 可以成功接收 ,就会等待响应。
如果tcp 不能成功接口,就是丢包,client 会重发 - 超时就是服务器不可达。

3.如果服务器收到包,却不能建立链接去处理(max-connection 和 accept-coun已满 )
tcp 包已经接收成功,服务器会返回正忙。

上一篇 下一篇

猜你喜欢

热点阅读