Microsoft MVP성태의 닷넷 이야기
개발 환경 구성: 535. Wireshark + C#으로 확인하는 TCP 통신의 MIN RTO [링크 복사], [링크+제목 복사]
조회: 9941
글쓴 사람
정성태 (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
정성태

1  2  3  4  5  6  7  [8]  9  10  11  12  13  14  15  ...
NoWriterDateCnt.TitleFile(s)
13423정성태10/6/20233063스크립트: 58. 파이썬 - async/await 기본 사용법
13422정성태10/5/20233204닷넷: 2148. C# - async 유무에 따른 awaitable 메서드의 병렬 및 예외 처리
13421정성태10/4/20233243닷넷: 2147. C# - 비동기 메서드의 async 예약어 유무에 따른 차이
13420정성태9/26/20235326스크립트: 57. 파이썬 - UnboundLocalError: cannot access local variable '...' where it is not associated with a value
13419정성태9/25/20233092스크립트: 56. 파이썬 - RuntimeError: dictionary changed size during iteration
13418정성태9/25/20233758닷넷: 2146. C# - ConcurrentDictionary 자료 구조의 동기화 방식
13417정성태9/19/20233336닷넷: 2145. C# - 제네릭의 형식 매개변수에 속한 (매개변수를 가진) 생성자를 호출하는 방법
13416정성태9/19/20233152오류 유형: 877. redis-py - MISCONF Redis is configured to save RDB snapshots, ...
13415정성태9/18/20233639닷넷: 2144. C# 12 - 컬렉션 식(Collection Expressions)
13414정성태9/16/20233390디버깅 기술: 193. Windbg - ThreadStatic 필드 값을 조사하는 방법
13413정성태9/14/20233582닷넷: 2143. C# - 시스템 Time Zone 변경 시 이벤트 알림을 받는 방법
13412정성태9/14/20236853닷넷: 2142. C# 12 - 인라인 배열(Inline Arrays) [1]
13411정성태9/12/20233364Windows: 252. 권한 상승 전/후 따로 관리되는 공유 네트워크 드라이브 정보
13410정성태9/11/20234863닷넷: 2141. C# 12 - Interceptor (컴파일 시에 메서드 호출 재작성) [1]
13409정성태9/8/20233721닷넷: 2140. C# - Win32 API를 이용한 모니터 전원 끄기
13408정성태9/5/20233714Windows: 251. 임의로 만든 EXE 파일을 포함한 ZIP 파일의 압축을 해제할 때 Windows Defender에 의해 삭제되는 경우
13407정성태9/4/20233473닷넷: 2139. C# - ParallelEnumerable을 이용한 IEnumerable에 대한 병렬 처리
13406정성태9/4/20233426VS.NET IDE: 186. Visual Studio Community 버전의 라이선스
13405정성태9/3/20233841닷넷: 2138. C# - async 메서드 호출 원칙
13404정성태8/29/20233363오류 유형: 876. Windows - 키보드의 등호(=, Equals sign) 키가 눌리지 않는 경우
13403정성태8/21/20233189오류 유형: 875. The following signatures couldn't be verified because the public key is not available: NO_PUBKEY EB3E94ADBE1229CF
13402정성태8/20/20233249닷넷: 2137. ILSpy의 nuget 라이브러리 버전 - ICSharpCode.Decompiler
13401정성태8/19/20233525닷넷: 2136. .NET 5+ 환경에서 P/Invoke의 성능을 높이기 위한 SuppressGCTransition 특성 [1]
13400정성태8/10/20233351오류 유형: 874. 파이썬 - pymssql을 윈도우 환경에서 설치 불가
13399정성태8/9/20233373닷넷: 2135. C# - 지역 변수로 이해하는 메서드 매개변수의 값/참조 전달
13398정성태8/3/20234135스크립트: 55. 파이썬 - pyodbc를 이용한 SQL Server 연결 사용법
1  2  3  4  5  6  7  [8]  9  10  11  12  13  14  15  ...