netstat输出中Recv-Q的含义,当然就和man中说的一样,我们做实验只看Established状态下Recv-Q的数据。
https://man7.org/linux/man-pages/man8/netstat.8.html
OUTPUT top
Active Internet connections (TCP, UDP, UDPLite, raw)
Proto
The protocol (tcp, udp, udpl, raw) used by the socket.Recv-Q
Established: The count of bytes not copied by the user program
connected to this socket. Listening: Since Kernel 2.6.18 this column
contains the current syn backlog.Send-Q
Established: The count of bytes not acknowledged by the remote host.
Listening: Since Kernel 2.6.18 this column contains the maximum size
of the syn backlog.
tomcat只开启一个http线程,且,处理时为sleep 3600s。也就是说,tomcat只在处理一个请求
@RequestMapping("/greeting")
public @ResponseBody
String greeting(HttpServletResponse rsp, @RequestParam(name = "cost") long cost) {
try {
Thread.sleep(cost * 1000L);
} catch (Exception e) {
e.printStackTrace();
}
String format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS").format(new Date());
LOG.info(format);
return format;
}
使用Jmeter同时发送200个请求。由于我们设置为只能接受10个连接:
maxConnections + ( min(acceptCount, somaxconn) + 1 ) == 6 + ( min(3, 4096) + 1 ) == 6+ ( 3+1 ) == 10
所以,tomcat只能接受10个连接
上图中"192.168.86.204:8080 192.168.86.1:xxx ESTABLISHED"的确实只有10个,其中
- "ESTABLISHED -"意思是该tcp连接由OS代为持有,放到了OS的 全连接队列中
- "ESTABLISHED 7977/java"意思是该tcp连接已经交由pid为7977的java应用
只在 "192.168.86.204:8080 192.168.86.1:45523"时Recv-Q显示为0,其余都是187。那么,这里的187是什么意思呢?
当然就是man netstat中说的含义了:The count of bytes not copied by the user program connected to this socket,也就是“OS已接收到,但,OS尚未交付给应用程序的数据”的大小"
Recv-Q
Established: The count of bytes not copied by the user program
connected to this socket.Listening: Since Kernel 2.6.18 this column contains the current syn backlog
我们是http请求,这就是我们http请求的数据,包括http头和http body数据(如果有)。把这个数据抓包到187.pcap文件中,我们用wireshark看下
marvin@vm204:~$ sudo tcpdump -v -nn -i ens33 port 8080 -w 187.pcap
[sudo] password for marvin:
tcpdump: listening on ens33, link-type EN10MB (Ethernet), capture size 262144 bytes
^C2548 packets captured
2548 packets received by filter
0 packets dropped by kernel
marvin@vm204:~$
整个http的大小,正好是187
完