Microsoft MVP성태의 닷넷 이야기
개발 환경 구성: 535. Wireshark + C#으로 확인하는 TCP 통신의 MIN RTO [링크 복사], [링크+제목 복사],
조회: 10379
글쓴 사람
정성태 (techsharer at outlook.com)
홈페이지
첨부 파일
 

(시리즈 글이 8개 있습니다.)
개발 환경 구성: 533. Wireshark + C#으로 확인하는 TCP 통신의 MSS(Maximum Segment Size) - 리눅스 환경
; https://www.sysnet.pe.kr/2/0/12527

개발 환경 구성: 534. Wireshark + C#으로 확인하는 TCP 통신의 MSS(Maximum Segment Size) - 윈도우 환경
; https://www.sysnet.pe.kr/2/0/12528

개발 환경 구성: 535. Wireshark + C#으로 확인하는 TCP 통신의 MIN RTO
; https://www.sysnet.pe.kr/2/0/12529

개발 환경 구성: 536. Wireshark + C#으로 확인하는 TCP 통신의 Receive Window
; https://www.sysnet.pe.kr/2/0/12530

개발 환경 구성: 538. Wireshark + C#으로 확인하는 ReceiveBufferSize(SO_RCVBUF), SendBufferSize(SO_SNDBUF)
; https://www.sysnet.pe.kr/2/0/12532

개발 환경 구성: 539. Wireshark + C/C++로 확인하는 TCP 연결에서의 shutdown 동작
; https://www.sysnet.pe.kr/2/0/12533

개발 환경 구성: 540. Wireshark + C/C++로 확인하는 TCP 연결에서의 closesocket 동작
; https://www.sysnet.pe.kr/2/0/12534

개발 환경 구성: 541.  Wireshark로 확인하는 LSO(Large Send Offload), RSC(Receive Segment Coalescing) 옵션
; https://www.sysnet.pe.kr/2/0/12535




Wireshark + C#으로 확인하는 TCP 통신의 MIN RTO

RTO와 InitialRTO에 대해 아래의 글에서 잘 설명하고 있습니다.

TCP retransmission과 튜닝 포인트
; https://brunch.co.kr/@alden/15

이 중에서 InitialRTO에 대해서는 지난번에 저도 다룬 적이 있는데요,

윈도우 응용 프로그램의 Socket 연결 시 time-out 시간 제어
; https://www.sysnet.pe.kr/2/0/12015

RTO를 이번 기회에 마저 다뤄보도록 하겠습니다. ^^




TCP는 처음 3-way handshake를 하기 위한 SYN 패킷을 서버로 전송할 때 서버로부터의 응답(SYN+ACK)을 일정 시간 동안 기다리게 됩니다. 바로 그때의 "일정 시간"과 관련 있는 것이 InitialRTO입니다. 그리고 일단 연결이 되면 이후 데이터 전송을 하게 될 텐데, 그 전송 패킷에 대해서도 서버로부터의 응답(ACK) 시간 제한을 두고, 이때 관여하는 설정값이 바로 MinRTO입니다.

연결 시의 RTO와 전송 시의 RTO 설정이 나눠진 이유는 간단합니다. 가령, 전송 시의 RTO는 그동안 오고 간 패킷(즉 TCP 협상 동안 오고 간 패킷을 포함)의 RTT 자료를 기반으로 내부적인 계산을 거쳐 결정할 수 있는 반면, 최초 연결 시는 RTT를 판정할 수 있는 지난 데이터가 없으므로 별도로 정해진 InitialRTO를 사용하게 되는 것입니다.

또한 RTO가 아닌 MinRTO로 나눠진 이유는, 일반적으로 RTT는 대상 서버와의 네트워크 bandwidth, hop 수 및 지리적 위치 등의 영향을 받게 됩니다. 그래서 일괄적으로 단일 값으로 설정할 수 없기 때문에 오고 간 패킷 데이터를 기반으로 TCP Socket마다 결정되는 것이 맞습니다. 단지, 내부적으로 계산한 값이 너무 작게 되는 것을 방지하기 위해 MinRTO가 의미 있는 것입니다. (이러한 이야기가 "TCP retransmission과 튜닝 포인트" 글에 잘 나옵니다.)

리눅스의 경우 MinRTO의 기본값은 200ms라고 하며, 윈도우의 경우에는 다음의 문서 기준으로 300ms입니다.

You cannot customize some TCP configurations by using the netsh command in Windows Server 2008 R2
; https://support.microsoft.com/en-us/topic/you-cannot-customize-some-tcp-configurations-by-using-the-netsh-command-in-windows-server-2008-r2-c1feebea-82a8-cb05-83c7-46ffb5fd9cec




그럼, 실제로 RTO를 확인해 볼까요? 이번에도 C# 소스 코드는 지난번의 것을 활용할 수 있습니다. 따라서 연결 후, send(10000 바이트)를 하면 이때의 패킷 교환은 wireshark에 다음과 같은 식으로 나옵니다.

// 서버, 클라이언트 모두 Windows 10 환경
49	1.978239	210.91.106.100	168.126.144.30	TCP	66	2015 → 15000 [SYN] Seq=0 Win=64240 Len=0 MSS=1460 WS=256 SACK_PERM=1
50	1.981763	168.126.144.30	210.91.106.100	TCP	66	15000 → 2015 [SYN, ACK] Seq=0 Ack=1 Win=65535 Len=0 MSS=1460 WS=256 SACK_PERM=1
51	1.981859	210.91.106.100	168.126.144.30	TCP	54	2015 → 15000 [ACK] Seq=1 Ack=1 Win=262656 Len=0

317	8.132118	210.91.106.100	168.126.144.30	TCP	10054	2015 → 15000 [PSH, ACK] Seq=1 Ack=1 Win=262656 Len=10000
318	8.137492	168.126.144.30	210.91.106.100	TCP	60	15000 → 2015 [ACK] Seq=1 Ack=4381 Win=131328 Len=0
319	8.137492	168.126.144.30	210.91.106.100	TCP	60	15000 → 2015 [ACK] Seq=1 Ack=5841 Win=131328 Len=0
320	8.137492	168.126.144.30	210.91.106.100	TCP	60	15000 → 2015 [ACK] Seq=1 Ack=8761 Win=131328 Len=0
323	8.185561	168.126.144.30	210.91.106.100	TCP	60	15000 → 2015 [ACK] Seq=1 Ack=10001 Win=130048 Len=0

send 한 시각과 그에 대한 최초 ACK 패킷의 시간 간격은 5.374ms라고 나옵니다. 이 정도의 성능이면 대개의 경우 시스템 최솟값인 MinRTO가 설정되어 있을 가능성이 큽니다. 그렇다면 실제로 그런지 확인을 해볼까요? ^^ 이를 위한 재현은 서버를 VM 환경에서 구동하면 쉽게 할 수 있습니다. 즉, connect가 성공적으로 이뤄진 후 서버 측의 VM을 (stop이 아닌) "중지(pause)" 시킨 후 클라이언트에서 send(10000 바이트)로 테스트했을 때 다음과 같은 결과를 얻게 됩니다.

117 1.334232    210.91.106.100  168.126.144.30  TCP 66  2509 → 15000 [SYN] Seq=0 Win=64240 Len=0 MSS=1460 WS=256 SACK_PERM=1
118 1.339242    168.126.144.30  210.91.106.100  TCP 66  15000 → 2509 [SYN, ACK] Seq=0 Ack=1 Win=65535 Len=0 MSS=1460 WS=256 SACK_PERM=1
119 1.339343    210.91.106.100  168.126.144.30  TCP 54  2509 → 15000 [ACK] Seq=1 Ack=1 Win=262656 Len=0

1140    11.845833   210.91.106.100  168.126.144.30  TCP 10054   2509 → 15000 [PSH, ACK] Seq=1 Ack=1 Win=262656 Len=10000
1208    12.147417   210.91.106.100  168.126.144.30  TCP 1514    [TCP Retransmission] 2509 → 15000 [ACK] Seq=1 Ack=1 Win=262656 Len=1460
1241    12.750457   210.91.106.100  168.126.144.30  TCP 1514    [TCP Retransmission] 2509 → 15000 [ACK] Seq=1 Ack=1 Win=262656 Len=1460
1299    13.958414   210.91.106.100  168.126.144.30  TCP 1514    [TCP Retransmission] 2509 → 15000 [ACK] Seq=1 Ack=1 Win=262656 Len=1460
1399    16.369440   210.91.106.100  168.126.144.30  TCP 1514    [TCP Retransmission] 2509 → 15000 [ACK] Seq=1 Ack=1 Win=262656 Len=1460

보는 바와 같이 (12.147417 - 11.845833 =) 301.584ms 차이가 나고, 송신 측은 그 시간 내에 ACK를 못 받아 다시 Retransmission을 시도하고 있습니다. 즉, minRTO의 영향을 받은 것이 맞다고 추측할 수 있습니다.




그건 그렇고, 혹시 minRTO를 제어할 수 있을까요? "TCP retransmission과 튜닝 포인트" 글에는 리눅스 환경에서 설정할 수 있는 방법이 나옵니다. 그래서 저도 시도해봤는데, 제 경우에는 이상하게 "No such file or directory" 오류가 발생합니다.

// 우분투 20.04 환경

$ ip route
default via 192.168.100.1 dev eth0 proto static metric 100 
169.254.0.0/16 dev eth0 scope link metric 1000 
172.26.48.0/20 dev eth1 proto kernel scope link src 172.26.48.7 metric 101 
192.168.100.0/24 dev eth0 proto kernel scope link src 192.168.100.25 metric 100 

# ip route change default via 192.168.100.1 dev eth0 rto_min 300ms
RTNETLINK answers: No such file or directory

(혹시 원인을 아시는 분은 덧글 부탁드립니다. ^^)

반면, 윈도우 환경에서는 minRTO를 변경할 수는 있는데 기본값(300) 이하로만 가능합니다. 그러니까 아래의 글에서 소개했던 NetTCPSetting에,

Windows - TCP default template 설정 방법
; https://www.sysnet.pe.kr/2/0/12516

윈도우 환경에서 클라이언트 소켓의 최대 접속 수 (4) - ReuseUnicastPort를 이용한 포트 고갈 문제 해결
; https://www.sysnet.pe.kr/2/0/12435

MinRto 항목이 보이고,

...[생략]...
SettingName                     : InternetCustom
MinRto(ms)                      : 300
InitialCongestionWindow(MSS)    : 10
CongestionProvider              : CUBIC
CwndRestart                     : False
DelayedAckTimeout(ms)           : 40
DelayedAckFrequency             : 2
MemoryPressureProtection        : Enabled
AutoTuningLevelLocal            : Normal
AutoTuningLevelGroupPolicy      : NotConfigured
AutoTuningLevelEffective        : Local
EcnCapability                   : Disabled
Timestamps                      : Disabled
InitialRto(ms)                  : 1000
ScalingHeuristics               : Disabled
DynamicPortRangeStartPort       : 1024
DynamicPortRangeNumberOfPorts   : 64511
AutomaticUseCustom              : Disabled
NonSackRttResiliency            : Disabled
ForceWS                         : Enabled
MaxSynRetransmissions           : 4
AutoReusePortRangeStartPort     : 0
AutoReusePortRangeNumberOfPorts : 0
...[생략]...

또는 netsh 명령어로도 확인할 수 있습니다.

C:\WINDOWS\system32> netsh interface tcp show supplemental

The TCP global default template is internet

TCP Supplemental Parameters
----------------------------------------------
Minimum RTO (msec)                  : 300
Initial Congestion Window (MSS)     : 10
Congestion Control Provider         : cubic
Enable Congestion Window Restart    : disabled
Delayed ACK timeout (msec)          : 40
Delayed ACK frequency               : 2
Enable RACK                         : enabled
Enable Tail Loss Probe              : enabled

Please use the 'netsh int tcp show supplementalports' and
'netsh int tcp show supplementalsubnets' commands to view active filters.

그리고 "Set-NetTCPSetting" 문서에 따라,

* You can modify custom and non-custom settings on Windows server 2016 and 2019.
* You can modify only custom settings. Internet and Datacenter settings cannot be modified on Windows 2012 or earlier versions.
* On Windows 10, the following parameters are read-only and cannot be modified:
    -MinRtoMs
    -InitialCongestionWindowMss
    -AutomaticUseCustom
    -CongestionProvider
    -CwndRestart
    -DelayedAckTimeoutMs

Windows 2016 이상에서 모든 템플릿에 대해 MinRotMs 값을 변경할 수 있습니다.

[PowerShell]
PS C:\Windows\system32> Set-NetTCPSetting -SettingName Internet -MinRtoMs 250

[Command Prompt]
C:\Windows\system32> netsh interface tcp set supplemental template=InternetCustom minRto=250

하지만, 기본값 300보다 크게 설정하는 것은 "The parameter is incorrect."라는 오류가 발생합니다. (TCP 통신에서는 min 값을 의미하는데, 정작 설정 시에는 max 의미를 갖게 됩니다. ^^;)

PS C:\Windows\system32> Set-NetTCPSetting -SettingName InternetCustom -MinRtoMs 400
Set-NetTCPSetting : 매개 변수가 틀립니다.
위치 줄:1 문자:1
+ Set-NetTCPSetting -SettingName InternetCustom -MinRtoMs 400
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (MSFT_NetTCPSett...ystemName = ""):ROOT/StandardCimv2/MSFT_NetTCPSetting) [Set-NetTCPSetting], CimException
    + FullyQualifiedErrorId : Windows System Error 87,Set-NetTCPSetting

또한, Windows 10에서는 읽기 전용이기 때문에 오류가 발생합니다.

C:\WINDOWS\system32> netsh interface tcp set supplemental template=internet minRto=3000

Set supplemental command failed to update the specified template. The request is not supported.

PS C:\WINDOWS\system32> Set-NetTCPSetting -SettingName Internet -minRto 250
Set-NetTCPSetting : Property MinRto is read-only
At line:1 char:1
+ Set-NetTCPSetting -SettingName Internet -minRto 250
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (MSFT_NetTCPSett...ystemName = ""):ROOT/StandardCimv2/MSFT_NetTCPSetting) [Set-NetTCPSetting], CimException
    + FullyQualifiedErrorId : Windows System Error 87,Set-NetTCPSetting

그나저나... (네트워크 관리자 수준의) 웬만한 튜닝 작업이 아니라면 이 값을 바꿀 경우는 거의 없을 테지만, 웹상의 자료를 보면 현 시점에 200ms, 300ms는 너무 크다는 의견이 많습니다. 음... 그래도 아마 저 숫자를 일부러 줄여 설정하는 개발자는 많지 않겠죠? ^^




[이 글에 대해서 여러분들과 의견을 공유하고 싶습니다. 틀리거나 미흡한 부분 또는 의문 사항이 있으시면 언제든 댓글 남겨주십시오.]







[최초 등록일: ]
[최종 수정일: 7/9/2021]

Creative Commons License
이 저작물은 크리에이티브 커먼즈 코리아 저작자표시-비영리-변경금지 2.0 대한민국 라이센스에 따라 이용하실 수 있습니다.
by SeongTae Jeong, mailto:techsharer at outlook.com

비밀번호

댓글 작성자
 



2021-07-09 04시57분
New registry entry for controlling the TCP Acknowledgment (ACK) behavior in Windows
; https://docs.microsoft.com/en-US/troubleshoot/windows-server/networking/registry-entry-control-tcp-acknowledgment-behavior
정성태

... 46  47  48  49  50  51  52  53  54  55  56  57  58  [59]  60  ...
NoWriterDateCnt.TitleFile(s)
12172정성태3/7/202016314개발 환경 구성: 474. docker - container에서 root 권한 명령어 실행(sudo)
12171정성태3/6/202011379VS.NET IDE: 143. Visual Studio - ASP.NET Core Web Application의 "Enable Docker Support" 옵션으로 달라지는 점 [1]
12170정성태3/6/20209915오류 유형: 599. "Docker Desktop is switching..." 메시지와 DockerDesktopVM CPU 소비 현상
12169정성태3/5/202011935개발 환경 구성: 473. Windows nanoserver에 대한 docker pull의 태그 사용 [1]
12168정성태3/5/202012653개발 환경 구성: 472. 윈도우 환경에서의 dockerd.exe("Docker Engine" 서비스)가 Linux의 것과 다른 점
12167정성태3/5/202011904개발 환경 구성: 471. C# - 닷넷 응용 프로그램에서 DB2 Express-C 데이터베이스 사용 (3) - ibmcom/db2express-c 컨테이너 사용
12166정성태3/4/202011502개발 환경 구성: 470. Windows Server 컨테이너 - DockerMsftProvider 모듈을 이용한 docker 설치
12165정성태3/2/202011115.NET Framework: 900. 실행 시에 메서드 가로채기 - CLR Injection: Runtime Method Replacer 개선 - 네 번째 이야기(Monitor.Enter 후킹)파일 다운로드1
12164정성태2/29/202012021오류 유형: 598. Surface Pro 6 - Windows Hello Face Software Device가 인식이 안 되는 문제
12163정성태2/27/202010488.NET Framework: 899. 익명 함수를 가리키는 delegate 필드에 대한 직렬화 문제
12162정성태2/26/202013290디버깅 기술: 166. C#에서 만든 COM 객체를 C/C++로 P/Invoke Interop 시 메모리 누수(Memory Leak) 발생 [6]파일 다운로드2
12161정성태2/26/20209911오류 유형: 597. manifest - The value "x64" of attribute "processorArchitecture" in element "assemblyIdentity" is invalid.
12160정성태2/26/202010621개발 환경 구성: 469. Reg-free COM 개체 사용을 위한 manifest 파일 생성 도구 - COMRegFreeManifest
12159정성태2/26/20208716오류 유형: 596. Visual Studio - The project needs to include ATL support
12158정성태2/25/202010627디버깅 기술: 165. C# - Marshal.GetIUnknownForObject/GetIDispatchForObject 사용 시 메모리 누수(Memory Leak) 발생파일 다운로드1
12157정성태2/25/202010608디버깅 기술: 164. C# - Marshal.GetNativeVariantForObject 사용 시 메모리 누수(Memory Leak) 발생 및 해결 방법파일 다운로드1
12156정성태2/25/20209889오류 유형: 595. LINK : warning LNK4098: defaultlib 'nafxcw.lib' conflicts with use of other libs; use /NODEFAULTLIB:library
12155정성태2/25/20209116오류 유형: 594. Warning NU1701 - This package may not be fully compatible with your project
12154정성태2/25/20208907오류 유형: 593. warning LNK4070: /OUT:... directive in .EXP differs from output filename
12153정성태2/23/202011688.NET Framework: 898. Trampoline을 이용한 후킹의 한계파일 다운로드1
12152정성태2/23/202011418.NET Framework: 897. 실행 시에 메서드 가로채기 - CLR Injection: Runtime Method Replacer 개선 - 세 번째 이야기(Trampoline 후킹)파일 다운로드1
12151정성태2/22/202011867.NET Framework: 896. C# - Win32 API를 Trampoline 기법을 이용해 C# 메서드로 가로채는 방법 - 두 번째 이야기 (원본 함수 호출)파일 다운로드1
12150정성태2/21/202011760.NET Framework: 895. C# - Win32 API를 Trampoline 기법을 이용해 C# 메서드로 가로채는 방법 [1]파일 다운로드1
12149정성태2/20/202011545.NET Framework: 894. eBEST C# XingAPI 래퍼 - 연속 조회 처리 방법 [1]
12148정성태2/19/202012804디버깅 기술: 163. x64 환경에서 구현하는 다양한 Trampoline 기법 [1]
12147정성태2/19/202011436디버깅 기술: 162. x86/x64의 기계어 코드 최대 길이
... 46  47  48  49  50  51  52  53  54  55  56  57  58  [59]  60  ...