Microsoft MVP성태의 닷넷 이야기
개발 환경 구성: 535. Wireshark + C#으로 확인하는 TCP 통신의 MIN RTO [링크 복사], [링크+제목 복사],
조회: 10380
글쓴 사람
정성태 (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)
12426정성태11/24/20208887오류 유형: 685. WinDbg Preview - error InitTypeRead
12425정성태11/24/202010083VC++: 141. Visual C++ - "Treat Warnings As Errors" 옵션이 꺼져 있는데도 일부 경고가 에러 처리되는 경우
12424정성태11/24/202010393VC++: 140. C++의 연산자 동의어(operator synonyms), 대체 토큰 [1]
12423정성태11/22/202011288.NET Framework: 974. C# 9.0 - (16) 제약 조건이 없는 형식 매개변수 주석(Unconstrained type parameter annotations)파일 다운로드1
12422정성태11/21/20209094.NET Framework: 973. .NET 5, .NET Framework에서만 허용하는 UnmanagedCallersOnly 사용예파일 다운로드1
12421정성태11/19/20208848.NET Framework: 972. DNNE가 출력한 NE DLL을 직접 생성하는 방법파일 다운로드1
12420정성태11/19/20208031오류 유형: 684. Visual C++ - MSIL .netmodule or module compiled with /GL found; restarting link with /LTCG; add /LTCG to the link command line to improve linker performance
12419정성태11/19/20209311VC++: 139. Visual C++ - .NET Core의 nethost.lib와 정적 링크파일 다운로드1
12418정성태11/19/202011339오류 유형: 683. Visual C++ - error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MT_StaticRelease' doesn't match value 'MDd_DynamicDebug'파일 다운로드1
12417정성태11/19/20208756오류 유형: 682. Visual C++ - warning LNK4099: PDB '...pdb' was not found with '...lib(pch.obj)' or at '...pdb'; linking object as if no debug info
12416정성태11/19/202010022오류 유형: 681. Visual C++ - error LNK2001: unresolved external symbol _CrtDbgReport
12415정성태11/18/202010144.NET Framework: 971. UnmanagedCallersOnly 특성과 DNNE 사용파일 다운로드1
12414정성태11/18/202011200VC++: 138. x64 빌드에서 extern "C"가 아닌 경우 ___cdecl name mangling 적용 [4]파일 다운로드1
12413정성태11/17/202010862.NET Framework: 970. .NET 5 / .NET Core - UnmanagedCallersOnly 특성을 사용한 함수 내보내기파일 다운로드1
12412정성태11/16/202013100.NET Framework: 969. .NET Framework 및 .NET 5 - UnmanagedCallersOnly 특성 사용파일 다운로드1
12411정성태11/12/202010134오류 유형: 680. C# 9.0 - Error CS8889 The target runtime doesn't support extensible or runtime-environment default calling conventions.
12410정성태11/12/20209995디버깅 기술: 174. windbg - System.TypeLoadException 예외 분석 사례
12409정성태11/12/202011376.NET Framework: 968. C# 9.0의 Function pointer를 이용한 함수 주소 구하는 방법파일 다운로드1
12408정성태11/9/202023003도서: 시작하세요! C# 9.0 프로그래밍 [8]
12407정성태11/9/202011713.NET Framework: 967. "clr!JIT_DbgIsJustMyCode" 호출이 뭘까요?
12406정성태11/8/202013266.NET Framework: 966. C# 9.0 - (15) 최상위 문(Top-level statements) [5]파일 다운로드1
12405정성태11/8/202010655.NET Framework: 965. C# 9.0 - (14) 부분 메서드에 대한 새로운 기능(New features for partial methods)파일 다운로드1
12404정성태11/7/202011212.NET Framework: 964. C# 9.0 - (13) 모듈 이니셜라이저(Module initializers)파일 다운로드1
12403정성태11/7/202011235.NET Framework: 963. C# 9.0 - (12) foreach 루프에 대한 GetEnumerator 확장 메서드 지원(Extension GetEnumerator)파일 다운로드1
12402정성태11/7/202011841.NET Framework: 962. C# 9.0 - (11) 공변 반환 형식(Covariant return types) [1]파일 다운로드1
12401정성태11/5/202010858VS.NET IDE: 153. 닷넷 응용 프로그램에서의 "My Code" 범위와 "Enable Just My Code"의 역할 [1]
... 46  47  48  [49]  50  51  52  53  54  55  56  57  58  59  60  ...