Microsoft MVP성태의 닷넷 이야기
개발 환경 구성: 535. Wireshark + C#으로 확인하는 TCP 통신의 MIN RTO [링크 복사], [링크+제목 복사]
조회: 9959
글쓴 사람
정성태 (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)
13474정성태12/6/20232133개발 환경 구성: 690. 닷넷 코어/5+ 버전의 ilasm/ildasm 실행 파일 구하는 방법 - 두 번째 이야기
13473정성태12/5/20232325닷넷: 2179. C# - 값 형식(Blittable)을 메모리 복사를 이용해 바이트 배열로 직렬화/역직렬화파일 다운로드1
13472정성태12/4/20232155C/C++: 164. Visual C++ - InterlockedCompareExchange128 사용 방법
13471정성태12/4/20232183Copilot - To enable GitHub Copilot, authorize this extension using GitHub's device flow
13470정성태12/2/20232484닷넷: 2178. C# - .NET 8부터 COM Interop에 대한 자동 소스 코드 생성 도입파일 다운로드1
13469정성태12/1/20232193닷넷: 2177. C# - (Interop DLL 없이) CoClass를 이용한 COM 개체 생성 방법파일 다운로드1
13468정성태12/1/20232175닷넷: 2176. C# - .NET Core/5+부터 달라진 RCW(Runtime Callable Wrapper) 대응 방식파일 다운로드1
13467정성태11/30/20232170오류 유형: 882. C# - Unhandled exception. System.Runtime.InteropServices.COMException (0x800080A5)파일 다운로드1
13466정성태11/29/20232376닷넷: 2175. C# - DllImport 메서드의 AOT 지원을 위한 LibraryImport 옵션
13465정성태11/28/20232109개발 환경 구성: 689. MSBuild - CopyToOutputDirectory가 "dotnet publish" 시에는 적용되지 않는 문제파일 다운로드1
13464정성태11/28/20232228닷넷: 2174. C# - .NET 7부터 UnmanagedCallersOnly 함수 export 기능을 AOT 빌드에 통합파일 다운로드1
13463정성태11/27/20232144오류 유형: 881. Visual Studio - NU1605: Warning As Error: Detected package downgrade
13462정성태11/27/20232209오류 유형: 880. Visual Studio - error CS0246: The type or namespace name '...' could not be found
13461정성태11/26/20232258닷넷: 2173. .NET Core 3/5+ 기반의 COM Server를 registry 등록 없이 사용하는 방법파일 다운로드1
13460정성태11/26/20232224닷넷: 2172. .NET 6+ 기반의 COM Server 내에 Type Library를 내장하는 방법파일 다운로드1
13459정성태11/26/20232207닷넷: 2171. .NET Core 3/5+ 기반의 COM Server를 기존의 regasm처럼 등록하는 방법파일 다운로드1
13458정성태11/26/20232212닷넷: 2170. .NET Core/5+ 기반의 COM Server를 tlb 파일을 생성하는 방법(tlbexp)
13457정성태11/25/20232163VS.NET IDE: 187. Visual Studio - 16.9 버전부터 추가된 "Display inline type hints" 옵션
13456정성태11/25/20232459닷넷: 2169. C# - OpenAI를 사용해 PDF 데이터를 대상으로 OpenAI 챗봇 작성 [1]파일 다운로드1
13455정성태11/25/20232339닷넷: 2168. C# - Azure.AI.OpenAI 패키지로 OpenAI 사용파일 다운로드1
13454정성태11/23/20232681닷넷: 2167. C# - Qdrant Vector DB를 이용한 Embedding 벡터 값 보관/조회 (Azure OpenAI) [1]파일 다운로드1
13453정성태11/23/20232217오류 유형: 879. docker desktop 설치 시 "Invalid JSON string. (Exception from HRESULT: 0x83750007)"
13452정성태11/22/20232296닷넷: 2166. C# - Azure OpenAI API를 이용해 사용자가 제공하는 정보를 대상으로 검색하는 방법파일 다운로드1
13451정성태11/21/20232431닷넷: 2165. C# - Azure OpenAI API를 이용해 ChatGPT처럼 동작하는 콘솔 응용 프로그램 제작파일 다운로드1
13450정성태11/21/20232253닷넷: 2164. C# - Octokit을 이용한 GitHub Issue 검색파일 다운로드1
13449정성태11/21/20232351개발 환경 구성: 688. Azure OpenAI 서비스 신청 방법
1  2  3  4  5  [6]  7  8  9  10  11  12  13  14  15  ...