net.UseRecvMulti
net.UseRecvMulti
#Overview
name: net.UseRecvMulti
This variable is created as a Console Variable (cvar).
- type:
Var
- help:
If true, and if running on a Unix/Linux platform, multiple packets will be retrieved from the socket with one syscall, improving performance and also allowing retrieval of timestamp information.
It is referenced in 4
C++ source files.
#Summary
#Usage in the C++ source code
The purpose of net.UseRecvMulti is to enable a performance optimization for network packet retrieval on Unix/Linux platforms. This setting variable is used to improve the efficiency of network communication in Unreal Engine 5.
This setting variable is primarily used in the Online Subsystem Utils module, specifically within the IpNetDriver component. It affects the network driver’s behavior when receiving packets.
The value of this variable is set through a console variable (CVarNetUseRecvMulti) with a default value of 0 (disabled). It can be changed at runtime through console commands or programmatically.
The associated variable CVarNetUseRecvMulti interacts directly with net.UseRecvMulti, as they share the same value. This console variable is used to access the setting’s value in the C++ code.
Developers must be aware that:
- This optimization is only applicable on Unix/Linux platforms.
- It affects how packets are retrieved from the socket, potentially improving performance and allowing access to timestamp information.
- It should be used in conjunction with the receive thread (net.IpNetDriverUseReceiveThread) for optimal performance.
Best practices when using this variable include:
- Enable it on Unix/Linux platforms for potential performance gains.
- Test thoroughly to ensure it doesn’t introduce any unexpected behavior in your specific network setup.
- Monitor performance metrics to confirm the optimization is beneficial for your use case.
Regarding the associated variable CVarNetUseRecvMulti:
- Its purpose is to provide programmatic access to the net.UseRecvMulti setting within the C++ code.
- It is used in the IpNetDriver to determine whether to use the optimized packet retrieval method.
- The value is typically accessed using the GetValueOnAnyThread() method, which allows for thread-safe retrieval of the current setting.
- Developers should use this variable when they need to check the state of the net.UseRecvMulti setting in their code, particularly within the networking subsystem.
#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:71
Scope: file
Source code excerpt:
TAutoConsoleVariable<int32> CVarNetUseRecvMulti(
TEXT("net.UseRecvMulti"),
0,
TEXT("If true, and if running on a Unix/Linux platform, multiple packets will be retrieved from the socket with one syscall, ")
TEXT("improving performance and also allowing retrieval of timestamp information."));
TAutoConsoleVariable<int32> CVarRecvMultiCapacity(
TEXT("net.RecvMultiCapacity"),
#Associated Variable and Callsites
This variable is associated with another variable named CVarNetUseRecvMulti
. They share the same value. See the following C++ source code.
#Loc: <Workspace>/Engine/Plugins/Online/OnlineSubsystemUtils/Source/OnlineSubsystemUtils/Private/IpNetDriver.cpp:70
Scope: file
Source code excerpt:
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,
TEXT("If true, and if running on a Unix/Linux platform, multiple packets will be retrieved from the socket with one syscall, ")
TEXT("improving performance and also allowing retrieval of timestamp information."));
TAutoConsoleVariable<int32> CVarRecvMultiCapacity(
#Loc: <Workspace>/Engine/Plugins/Online/OnlineSubsystemUtils/Source/OnlineSubsystemUtils/Private/IpNetDriver.cpp:238
Scope (from outer to inner):
file
class class FPacketIterator
function FPacketIterator
Source code excerpt:
#endif
, RMState(InRMState)
, bUseRecvMulti(CVarNetUseRecvMulti.GetValueOnAnyThread() != 0 && InRMState != nullptr)
, RecvMultiIdx(0)
, RecvMultiPacketCount(0)
, StartReceiveTime(InStartReceiveTime)
, bCheckReceiveTime(bInCheckReceiveTime)
, CheckReceiveTimePacketCount(bInCheckReceiveTime ? InDriver->NbPacketsBetweenReceiveTimeTest : 0)
, NumIterationUntilTimeTest(CheckReceiveTimePacketCount)
#Loc: <Workspace>/Engine/Plugins/Online/OnlineSubsystemUtils/Source/OnlineSubsystemUtils/Private/IpNetDriver.cpp:940
Scope (from outer to inner):
file
function bool UIpNetDriver::InitBase
Source code excerpt:
SetSocketAndLocalAddress(Resolver->GetFirstSocket());
bool bRecvMultiEnabled = CVarNetUseRecvMulti.GetValueOnAnyThread() != 0;
bool bRecvThreadEnabled = CVarNetIpNetDriverUseReceiveThread.GetValueOnAnyThread() != 0;
if (bRecvMultiEnabled && !bRecvThreadEnabled)
{
bool bSupportsRecvMulti = SocketSubsystem->IsSocketRecvMultiSupported();