NetEmulation.PktJitter

NetEmulation.PktJitter

#Overview

name: NetEmulation.PktJitter

This variable is created as a Console Variable (cvar).

It is referenced in 7 C++ source files.

#Summary

#Usage in the C++ source code

The purpose of NetEmulation.PktJitter is to simulate outgoing packet jitter in network communication for Unreal Engine’s networking system. It is used to introduce artificial variability in packet transmission times, which can help test and simulate real-world network conditions.

This setting variable is primarily used by the Unreal Engine’s networking subsystem, specifically within the NetDriver and NetConnection modules. It’s part of the network emulation features that allow developers to simulate various network conditions for testing and debugging purposes.

The value of this variable is set through several means:

  1. It can be configured in the .ini file and loaded via the LoadConfig function.
  2. It can be set through console commands, as evidenced by the BUILD_NETEMULATION_CONSOLE_COMMAND macro.
  3. It can be modified programmatically through the FPacketSimulationSettings struct.

The PktJitter variable interacts closely with other network simulation settings, particularly PktLagMin and PktLagVariance. Together, these variables determine the amount of artificial delay added to outgoing packets.

Developers should be aware that:

  1. Setting PktJitter to a non-zero value will cause packets to be sent out of order, which can significantly impact network performance and game behavior.
  2. The actual jitter applied is calculated using PktJitter in combination with PktLagMin and PktLagVariance.
  3. This setting is primarily for testing and should not be used in production builds unless absolutely necessary.

Best practices when using this variable include:

  1. Use it in conjunction with other network simulation settings for comprehensive network condition testing.
  2. Reset it to 0 for normal operation or production builds.
  3. Be cautious when setting high values, as it can severely impact gameplay and may not accurately represent real-world conditions.

Regarding the associated variable PktJitter, it appears to be the same variable used in different contexts. It’s defined in the NetDriver.h file as a member of the FPacketSimulationSettings struct and is used throughout the networking code to apply the jitter simulation. The usage and considerations for this variable are the same as described above for NetEmulation.PktJitter.

#References in C++ code

#Callsites

This variable is referenced in the following C++ source code:

#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/Net/NetEmulationHelper.cpp:357

Scope (from outer to inner):

file
namespace    UE::Net::Private::NetEmulationHelper

Source code excerpt:

	BUILD_NETEMULATION_CONSOLE_COMMAND(PktIncomingLagMax, "Sets maximum incoming packet latency");
	BUILD_NETEMULATION_CONSOLE_COMMAND(PktIncomingLoss, "Simulates incoming packet loss");
	BUILD_NETEMULATION_CONSOLE_COMMAND(PktJitter, "Simulates outgoing packet jitter");


} // end namespace UE::Net::Private::NetEmulationHelper

#endif //#if DO_ENABLE_NET_TEST

#Associated Variable and Callsites

This variable is associated with another variable named PktJitter. They share the same value. See the following C++ source code.

#Loc: <Workspace>/Engine/Source/Runtime/Engine/Classes/Engine/NetDriver.h:550

Scope: file

Source code excerpt:


	/**
	 * Causes sent packets to have a variable latency that fluctuates from [PktLagMin] to [PktLagMin+PktJitter]
	 * Note that this will cause packet loss on the receiving end.
	 */
	UPROPERTY(EditAnywhere, Category = "Simulation Settings")
	int32	PktJitter = 0;

	/** reads in settings from the .ini file 
	 * @note: overwrites all previous settings
	 */
	ENGINE_API void LoadConfig(const TCHAR* OptionalQualifier = nullptr);
	

#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/Net/NetEmulationHelper.cpp:357

Scope (from outer to inner):

file
namespace    UE::Net::Private::NetEmulationHelper

Source code excerpt:

	BUILD_NETEMULATION_CONSOLE_COMMAND(PktIncomingLagMax, "Sets maximum incoming packet latency");
	BUILD_NETEMULATION_CONSOLE_COMMAND(PktIncomingLoss, "Simulates incoming packet loss");
	BUILD_NETEMULATION_CONSOLE_COMMAND(PktJitter, "Simulates outgoing packet jitter");


} // end namespace UE::Net::Private::NetEmulationHelper

#endif //#if DO_ENABLE_NET_TEST

#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/NetConnection.cpp:2321

Scope (from outer to inner):

file
function     bool UNetConnection::CheckOutgoingPacketEmulation

Source code excerpt:

		return true;
	}
	else if (PacketSimulationSettings.PktJitter != 0)
	{
		bSendDelayedPacketsOutofOrder = true;

		FDelayedPacket& B = *(new(Delayed)FDelayedPacket(SendBuffer.GetData(), SendBuffer.GetNumBits(), Traits));

		// In order to cause jitter, send one packet at min latency and the next packet at high latency

#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/NetConnection.cpp:2339

Scope (from outer to inner):

file
function     bool UNetConnection::CheckOutgoingPacketEmulation

Source code excerpt:

		else
		{
			// ExtraLag goes from [PktLagMin+PktJitter, PktLagMin+PktJitter+PktLagVariance]
			const double LagVariance = 2.0f * (FMath::FRand() - 0.5f) * double(PacketSimulationSettings.PktLagVariance);
			const double ExtraLag = (double(PacketSimulationSettings.PktLagMin + PacketSimulationSettings.PktJitter) + LagVariance) / 1000.f;
			B.SendTime = FPlatformTime::Seconds() + ExtraLag;
		}
	}
	else if (PacketSimulationSettings.PktLag)
	{
		FDelayedPacket& B = *(new(Delayed)FDelayedPacket(SendBuffer.GetData(), SendBuffer.GetNumBits(), Traits));

#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/NetDriver.cpp:4474

Scope (from outer to inner):

file
function     void FPacketSimulationSettings::LoadConfig

Source code excerpt:

	ConfigHelperInt(TEXT("PktIncomingLoss"), PktIncomingLoss, OptionalQualifier);

	ConfigHelperInt(TEXT("PktJitter"), PktJitter, OptionalQualifier);

	ValidateSettings();
#endif
}

bool FPacketSimulationSettings::LoadEmulationProfile(const TCHAR* ProfileName)

#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/NetDriver.cpp:4667

Scope (from outer to inner):

file
function     bool FPacketSimulationSettings::ParseSettings

Source code excerpt:

		UE_LOG(LogNet, Log, TEXT("PktIncomingLoss set to %d"), PktIncomingLoss);
	}
	if (ParseHelper(Cmd, TEXT("PktJitter="), PktJitter, OptionalQualifier))
	{
		bParsed = true;
		UE_LOG(LogNet, Log, TEXT("PktJitter set to %d"), PktJitter);
	}

	ValidateSettings();
#endif
	return bParsed;
}