¡¡¡¡±¾À´ÕâһƪÊÇ´òËãд°üÍ·ÔÚ·Ö²¼Ê½Æ½Ì¨ÖеľßÌå±ä»»¹ý³ÌµÄ¡£ÆäʵÎÄÕÂÒѾдºÃÁË¡£µ«ÊÇÏëÁËÕâ¸öÓ¦¸ÃÊDz»ÄÜËæ±ã·¢±íµÄ¡£±Ï¾¹Èç¹ûÖªµÀÁËÒ»¸ö°üµÄ¾ßÌåÿ¸ö×Ö½ÚµÄÒâÒå¡£ÄÜαÔì°üÀ´¹¥»÷ϵͳ¡£Æä´ÎÀ´½éÉÜÒ»¸ö°üµÄ¾ßÌå±ä»»¹ý³ÌÒâÒå²»´ó¡£ÔÚÿ¸ö·Ö²¼Ê½ÏµÍ³µÄÀï¡£°üµÄŤתӦ¸ÃÊǸöÓв»Í¬¡£ÎÒÃÇ×ÅÖصÄÓ¦¸ÃÊÇÒ»ÖÖ˼Ïë¡£Ò»ÖÖ¹²ÐÔ¡£¶ø²»ÊǸöÌåµÄ¾ßÌåʵÏÖ¡£
ÕâÀï´òËã¾Í½éÉÜÏ´ó°üµÄ´¦Àí¡£ÆäʵÕâ¸ö¸ü¶àµÄÊǽéÉÜÁËÏÂTCPÇаü¡£¸ú·Ö²¼Ê½Ã»É¶¹Øϵ¡£¡£¡£¡£ ²»¹ýÕâÒ²ËãÊÇϵͳµÄÒ»²¿·Ö
ÏÂÃæ½éÉÜÏÂÒ»¸ö´ó°üµÄ¾ßÌå´¦Àí¹ý³Ì
Ò»¡¢·¢ËÍÇëÇó²¢·ÖÎö1£©Ê×ÏÈÎÒÃÇÔÚ¿Í»§¶Ë·¢ËÍÒ»¸ö³¬¹ý1M µÄ°ü¸ø¿Í»§¶Ë´¦Àí£¬½á¹ûÊÇ·þÎñ¶ËÖ»ÊÕÁËÒ»´Îrecv¾Í¾Ü¾øÁË
2£©ÎªÁ˸üÇåÎú ÎÒÃÇÓÃtcpdumpÀ´×¥°ü´¦Àí
×¢ÒâÓÉÓÚÊÇÔÚ±¾»úÉÏ·¢ËÍ°ü½ÓÊÕ°ü¡£ËùÒÔ×ßµÄÊǻط¡£¼´Íø¿¨lo ¶ø²»ÊÇeth0.×¥°üµÄʱºò ÐèҪץlo ·ñÔò¿´²»µ½Êý¾Ý
[root@localhost git]# tcpdump -i lo port 53101 -w ./target.cap
Äõ½Êý¾ÝÒÔºó·Åµ½wiresharkÀï·ÖÎö
a)Ϊʲô×î´óÐÉÌÊÇ16396 ¶øʵ¼ÊÊÕÁË16384¸ö×Ö½Ú
¿ÉÒÔ¿´µ½ÐÉ̵Ämss×î´ó´«Ê䵥ԪΪ16396
µ«ÊÇÏÔʾnetio revcÖ»ÊÕµ½ÁË16384¸ö×Ö½Ú¡£
ÒòΪTCP°üÍ·Öлá´øÓÐ12×Ö½ÚµÄÑ¡Ïî----ʱ¼ä´Á
ËùÒÔʵ¼ÊÊÇ16396-12 = 16384
ËùÒÔneitoÒ»´ÎÊÕµ½µÄÊÇ16384¸ö×Ö½Ú¡£
×¢ÒâÕâÀïµÄ²âÊÔ»·¾³ÊDZ¾»ú»Ø·¡£
Èç¹ûÊÇÔÚ¹«ÍøÉÏ¡£
Ò»´ÎTCPÄܳÐÔصÄ×î´óÊý¾Ý°ü Ó¦¸ÃÊÇ 1448£¨1500MTU-20 IP°üÍ· -20TCP°üÍ· -12ʱ¼ä´Á£©
£¨¾ßÌåÇÒ°üµÄÔÀíÇë¿´ÏÂÃ棩
ÄÜrevcµÄÊý¾Ý¸úTCPµÄ½ÓÊÕ»º³å¶ÓÁÐÓйء£
b)Ϊʲô±¾»ú¾ÍÖ»ÊÕÁËÒ»´Î mss ?
sysctl -a | grep net.ipv4.tcp_wmem net.ipv4.tcp_wmem =
µÚ¶þ¸öÖµÊÇsendĬÈÏ·¢ËÍ»º³åÇø×ֽڵĸöÊý
ËùÒÔsendÒ»´Î 16384¸ö×Ö½Ú È»ºómssµÄ´óС¸ÕºÃÐÉ̵ÄÊÇ16396¡£ ËùÒԾͱ»recvÒ»´ÎÊÕµ½ÁË¡£
Õý³£ÔÚ¹«ÍøÏ¡£send µÄ16384¸ö×ֽڻᱻTCPÇгÉ11¸ö°ü·¢µ½netio¡£
TCP»áÔÚ½ÓÊܶË×é°ü¡£µ«ÊDz»Ò»¶¨»áһ϶¼ÊÕµ½Õâ11¸ö°ü¡£¿ÉÄܾÍÊÕµ½5¸ö È»ºó×é°ü¸ørecvÀ´´¦Àí¡£È»ºó¼ÌÐøÑ»·recv¡£»¹ÊÕÏÂÃæµÄ6¸ö°ü.×é°ü¸ørecv
ËùÒÔnetio»á¸ù¾Ý»º³å¶ÓÁÐÒѾÍø·Çé¿ö recvµ½²¿·Ö×Ö½Ú»òÕßÈ«²¿µÄ16384¸ö×Ö½Ú¡£
ÕâÀïÈç¹ûsendµÄÊý¾Ý´óÓÚ 16384 ¸ö×Ö½Ú¡£ÄÇô¾ÍÊÇÑ»·ÉÏÃæµÄ²½Öè .
c)Ϊʲô·þÎñ¶ËÄõ½Ò»´Îrecv¾ÍÖ®¼ä¹Ø±ÕÇëÇóÁË¡£
ÒòΪÎÒÃÇ·þÎñ¶ËÔÊÐí¿Í»§¶Ë´«À´µÄÇëÇó±ØÐëСÓÚ1M.ËùÒÔÄõ½Ò»´ÎrecvÒԺ󡣾ͿÉÒÔ½âÎö°üÍ·¡£·¢ÏÖ¿Í»§¶Ëµ½µ×ÐèÒª·¢ËͶàÉÙ¸ö×Ö½Ú¡£
³¬¹ý1M ÎÒÃÇÈÏΪ¾ÍÊÇ·Ç·¨°ü¡£Ö±½Ó¾Ü¾ø²¢¹Ø±Õ¿Í»§¶ËÁ¬½Ó¡£
¶þ¡¢½ÓÏÂÀ´ÎÒÃÇÀ´·ÖÎöÒ»¸ö·þÎñ¶ËÄÜ´¦ÀíµÄ´ó°ü
1¡¢ÎÒÃÇ·¢ËÍÒ»¸ö262360 ¸ö×Ö½Ú°ü¸ø·þÎñ¶Ë
2¡¢ÕâÀï×¢ÒâÏÂepollÊÕ°üµÄд·¨
µ±recvÍêÒ»¸ö°üµÄʱºò¡£Èç¹ûÕýÈ·¡£¾Í»á»Øµ½×ʼµÄwhileÑ»·È»ºó¼ÌÐø¼àÌý epoll¡£È»ºó»á´¥·¢E_TCP_CONNʼþ¡£
¿´ÈçÏÂͼ¡£ÊÕÍêÒ»¸örecv¾Í»áÌøµ½while¡£¼ÌÐøepoll wait À´ÊÕÏÂÒ»°ü¡£·´¸´Èç´ËÖ±µ½ÊÕÍêÒ»¸öÍêÕûµÄ°ü
×¢ÒâÔçÆÚµÄд·¨ÊÇÕâÑùµÄ¡£Ö±½ÓÔÚwhileÑ»·ÀïÊÕrecv¡£ ÕâÊÇÔÚ×èÈû»úÖÆϵÄд·¨¡£
ÎÒÃÇÓõ½epoll. ¿ÉÒÔ²»ÓÃ×èÈûÔÚrecv ¿ÉÒԵȴýʼþ´¥·¢¶ÁÈ¡¡£
¿ÉÒÔ×Ô¼º±È¶ÔÏÂ
while(1) { cnt = (int)recv(m_socket, pBuf,RECVSIZE, 0); if( cnt >0 ) { //Õý³£´¦ÀíÊý¾Ý } else { if((cnt<0) &&(errno == EAGAIN||errno == EWOULDBLOCK||errno == EINTR)) { continue;//¼ÌÐø½ÓÊÕÊý¾Ý } break;//Ìø³ö½ÓÊÕÑ»· } }
3¡¢½á¹ûÒÔ¼°·ÖÎö
×îºóÊÕµ½µÄ½á¹ûÈçÏ ÊÕÁË11´Î¡£×ܹ²262360¸ö×Ö½Ú m_iRecvBufLen:16384 sizeof(m_achRecvBuf):131072 TPT_RECV_BUF_LEN:131072 m_iRecvBufLen:16384 sizeof(m_achRecvBuf):131072 TPT_RECV_BUF_LEN:131072 m_iRecvBufLen:32768 sizeof(m_achRecvBuf):131072 TPT_RECV_BUF_LEN:131072 m_iRecvBufLen:16384 sizeof(m_achRecvBuf):131072 TPT_RECV_BUF_LEN:131072 m_iRecvBufLen:16384 sizeof(m_achRecvBuf):131072 TPT_RECV_BUF_LEN:131072 m_iRecvBufLen:65536 sizeof(m_achRecvBuf):131072 TPT_RECV_BUF_LEN:131072 m_iRecvBufLen:32768 sizeof(m_achRecvBuf):131072 TPT_RECV_BUF_LEN:131072 m_iRecvBufLen:16384 sizeof(m_achRecvBuf):131072 TPT_RECV_BUF_LEN:131072 m_iRecvBufLen:16384 sizeof(m_achRecvBuf):131072 TPT_RECV_BUF_LEN:131072 m_iRecvBufLen:16384 sizeof(m_achRecvBuf):131072 TPT_RECV_BUF_LEN:131072 m_iRecvBufLen:16602 sizeof(m_achRecvBuf):131072 TPT_RECV_BUF_LEN:131072
ÎÒÃÇ¿´µ½Ã¿´Î·¢Ë͵Älength¶¼ÊÇ16384 µ«ÊÇÓÉÓÚ»¬¶¯´°¿Úwin¡£Ê±´óʱС¡£·¢Ë͵ÄËٶȡ£²»Ò»Ñù¡£µ¼ÖÂrecvÒ»´ÎÄÜÊÕµ½µÄÊý¾ÝÒ²ÊDz»Ò»ÑùµÄ
ÊÕµ½ÕâЩ°ü¡£°ÑËûÃÇ×é³ÉÒ»¸öÍêÕûµÄ°ü¡£¼´·¢ËͶ˷¢¹ýÀ´µÄ262360µÄ°ü
¿ªÊ¼Ìøµ½int CNetioApp::OnRecv(int iTcpHandle,char* pBuffer,uint32_t nBufLen)´¦Àí
ºóÃæ¾ÍÊdz£¹æÂß¼ÁË¡£¶ªµ½containerµÄÇëÇóÏûÏ¢¶ÓÁС£
È»ºócontainer´¦ÀíÍ궪µ½netioµÄ»Ø°ü¶ÓÁС£
×îºónetioÄõ½°ü·µ»Ø¸øÇ°¶Ë
ÕâÀï×îºó×ܽ᣺
¡¡