net.IpNetDriverReceiveThreadPollTimeMS
net.IpNetDriverReceiveThreadPollTimeMS
#Overview
name: net.IpNetDriverReceiveThreadPollTimeMS
This variable is created as a Console Variable (cvar).
- type:
Var
- help:
If net.IpNetDriverUseReceiveThread is true, the number of milliseconds to use as the timeout value for FSocket::Wait on the receive thread. A negative value means to wait indefinitely (FSocket::Shutdown should cancel it though).
It is referenced in 3
C++ source files.
#Summary
#Usage in the C++ source code
The purpose of net.IpNetDriverReceiveThreadPollTimeMS is to control the timeout value for socket waiting operations in the receive thread of the IP Network Driver in Unreal Engine 5.
This setting variable is primarily used in the networking system, specifically within the IP Network Driver subsystem. It is part of the OnlineSubsystemUtils plugin, which is responsible for handling network-related functionality.
The value of this variable is set through a console variable (CVar) system. It is initialized with a default value of 250 milliseconds but can be modified at runtime through console commands or configuration files.
The variable interacts closely with another setting, net.IpNetDriverUseReceiveThread. The polling time is only relevant when the receive thread is enabled.
Developers should be aware that:
- This setting only takes effect when net.IpNetDriverUseReceiveThread is set to true.
- A negative value for this setting means the socket will wait indefinitely, which could potentially lead to blocking behavior if not handled correctly.
- The value directly affects how responsive the network receive operations are and how much CPU time is used for polling.
Best practices when using this variable include:
- Adjusting the value based on the specific needs of the game or application. Lower values increase responsiveness but may increase CPU usage.
- Monitoring network performance and adjusting this value in conjunction with other network-related settings for optimal results.
- Considering the target platforms and their network characteristics when setting this value.
Regarding the associated variable CVarNetIpNetDriverReceiveThreadPollTimeMS:
This is the actual CVar object that represents the net.IpNetDriverReceiveThreadPollTimeMS setting in the code. It’s used to get the current value of the setting within the engine’s code.
The purpose of CVarNetIpNetDriverReceiveThreadPollTimeMS is to provide a programmatic interface to access and modify the net.IpNetDriverReceiveThreadPollTimeMS setting.
This variable is used in the UIpNetDriver::FReceiveThreadRunnable::Run function, which is part of the IP Network Driver’s receive thread implementation. It determines the timeout for the socket wait operation in this thread.
Developers should be aware that:
- Changes to this CVar will directly affect the behavior of the receive thread.
- The value can be accessed from any thread using the GetValueOnAnyThread() method, which is important for thread-safe operations.
Best practices when using this variable include:
- Using the GetValueOnAnyThread() method to retrieve the current value, especially in multi-threaded contexts.
- Considering performance implications when frequently accessing or modifying this value.
- Using this variable in conjunction with other network-related CVars for comprehensive network tuning.
#References in C++ code
#Callsites
This variable is referenced in the following C++ source code:
#Loc: <Workspace>/Engine/Plugins/Online/OnlineSubsystemUtils/Source/OnlineSubsystemUtils/Private/IpNetDriver.cpp:66
Scope: file
Source code excerpt:
TAutoConsoleVariable<int32> CVarNetIpNetDriverReceiveThreadPollTimeMS(
TEXT("net.IpNetDriverReceiveThreadPollTimeMS"),
250,
TEXT("If net.IpNetDriverUseReceiveThread is true, the number of milliseconds to use as the timeout value for FSocket::Wait on the receive thread. A negative value means to wait indefinitely (FSocket::Shutdown should cancel it though)."));
TAutoConsoleVariable<int32> CVarNetUseRecvMulti(
TEXT("net.UseRecvMulti"),
0,
#Associated Variable and Callsites
This variable is associated with another variable named CVarNetIpNetDriverReceiveThreadPollTimeMS
. They share the same value. See the following C++ source code.
#Loc: <Workspace>/Engine/Plugins/Online/OnlineSubsystemUtils/Source/OnlineSubsystemUtils/Private/IpNetDriver.cpp:65
Scope: file
Source code excerpt:
TEXT("If net.IpNetDriverUseReceiveThread is true, the maximum number of packets that can be waiting in the queue. Additional packets received will be dropped."));
TAutoConsoleVariable<int32> CVarNetIpNetDriverReceiveThreadPollTimeMS(
TEXT("net.IpNetDriverReceiveThreadPollTimeMS"),
250,
TEXT("If net.IpNetDriverUseReceiveThread is true, the number of milliseconds to use as the timeout value for FSocket::Wait on the receive thread. A negative value means to wait indefinitely (FSocket::Shutdown should cancel it though)."));
TAutoConsoleVariable<int32> CVarNetUseRecvMulti(
TEXT("net.UseRecvMulti"),
#Loc: <Workspace>/Engine/Plugins/Online/OnlineSubsystemUtils/Source/OnlineSubsystemUtils/Private/IpNetDriver.cpp:2025
Scope (from outer to inner):
file
function uint32 UIpNetDriver::FReceiveThreadRunnable::Run
Source code excerpt:
using namespace UE::Net::Private;
const int32 PollTimeMS = CVarNetIpNetDriverReceiveThreadPollTimeMS.GetValueOnAnyThread();
const FTimespan Timeout = FTimespan::FromMilliseconds(PollTimeMS);
const float SleepTimeForWaitableErrorsInSec = CVarRcvThreadSleepTimeForWaitableErrorsInSeconds.GetValueOnAnyThread();
const int32 ActionForLongRecvErrors = CVarRcvThreadShouldSleepForLongRecvErrors.GetValueOnAnyThread();
UE_LOG(LogNet, Log, TEXT("UIpNetDriver::FReceiveThreadRunnable::Run starting up."));