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

... 61  62  63  64  65  66  67  68  69  70  71  72  [73]  74  75  ...
NoWriterDateCnt.TitleFile(s)
11827정성태2/26/201912647오류 유형: 521. Visual Studio - Could not start the 'rsync' command on the remote host, please install it using your system package manager.
11826정성태2/26/201912568오류 유형: 520. 우분투에 .NET Core SDK 설치 시 패키지 의존성 오류
11825정성태2/25/201917427개발 환경 구성: 428. Visual Studio 2019 - CMake를 이용한 리눅스 빌드 환경 설정 [1]
11824정성태2/25/201912156오류 유형: 519. The SNMP Service encountered an error while accessing the registry key SYSTEM\CurrentControlSet\Services\SNMP\Parameters\TrapConfiguration. [1]
11823정성태2/21/201913666오류 유형: 518. IIS 관리 콘솔이 뜨지 않는 문제
11822정성태2/20/201911844오류 유형: 517. docker에 설치한 MongoDB 서버로 연결이 안 되는 경우
11821정성태2/20/201912298오류 유형: 516. Visual Studio 2019 - This extension uses deprecated APIs and is at risk of not functioning in a future VS update. [1]
11820정성태2/20/201915462오류 유형: 515. 윈도우 10 1809 업데이트 후 "User Profiles Service" 1534 경고 발생
11819정성태2/20/201914112Windows: 158. 컴퓨터와 사용자의 SID(security identifier) 확인 방법
11818정성태2/20/201913016VS.NET IDE: 131. Visual Studio 2019 Preview의 닷넷 프로젝트 빌드가 20초 이상 걸리는 경우 [2]
11817정성태2/17/201910129오류 유형: 514. WinDbg Preview 실행 오류 - Error : DbgX.dll : WindowsDebugger.WindowsDebuggerException: Could not load dbgeng.dll
11816정성태2/17/201912642Windows: 157. 윈도우 스토어 앱(Microsoft Store App)을 명령행에서 직접 실행하는 방법
11815정성태2/14/201911507오류 유형: 513. Visual Studio 2019 - VSIX 설치 시 "The extension cannot be installed to this product due to prerequisites that cannot be resolved." 오류 발생
11814정성태2/12/201910358오류 유형: 512. VM(가상 머신)의 NT 서비스들이 자동 시작되지 않는 문제
11813정성태2/12/201911991.NET Framework: 809. C# - ("Save File Dialog" 등의) 대화 창에 확장 속성을 보이는 방법
11812정성태2/11/20199788오류 유형: 511. Windows Server 2003 VM 부팅 후 로그인 시점에 0xC0000005 BSOD 발생
11811정성태2/11/201913580오류 유형: 510. 서버 운영체제에 NVIDIA GeForce Experience 실행 시 wlanapi.dll 누락 문제
11810정성태2/11/201911695.NET Framework: 808. .NET Profiler - GAC 모듈에서 GAC 비-등록 모듈을 참조하는 경우의 문제
11809정성태2/11/201913168.NET Framework: 807. ClrMD를 이용해 메모리 덤프 파일로부터 특정 인스턴스를 참조하고 있는 소유자 확인
11808정성태2/8/201914254디버깅 기술: 123. windbg - 닷넷 응용 프로그램의 메모리 누수 분석
11807정성태1/29/201912544Windows: 156. 가상 디스크의 용량을 복구 파티션으로 인해 늘리지 못하는 경우 [4]
11806정성태1/29/201912431디버깅 기술: 122. windbg - 덤프 파일로부터 PID와 환경 변수 등의 정보를 구하는 방법
11805정성태1/28/201914153.NET Framework: 806. C# - int []와 object []의 차이로 이해하는 제네릭의 필요성 [4]파일 다운로드1
11804정성태1/24/201912187Windows: 155. diskpart - remove letter 이후 재부팅 시 다시 드라이브 문자가 할당되는 경우
11803정성태1/10/201911621디버깅 기술: 121. windbg - 닷넷 Finalizer 스레드가 멈춰있는 현상
11802정성태1/7/201913067.NET Framework: 805. 두 개의 윈도우를 각각 실행하는 방법(Windows Forms, WPF)파일 다운로드1
... 61  62  63  64  65  66  67  68  69  70  71  72  [73]  74  75  ...