ThreadMinimumSleepTimeInSeconds

ThreadMinimumSleepTimeInSeconds

#Overview

name: ThreadMinimumSleepTimeInSeconds

The value of this variable can be defined or overridden in .ini config files. 1 .ini config file referencing this setting variable.

It is referenced in 3 C++ source files.

#Summary

#Usage in the C++ source code

The purpose of ThreadMinimumSleepTimeInSeconds is to set a minimum sleep time for the WebSockets thread in the LibWebSockets implementation of Unreal Engine’s WebSockets module.

This setting variable is primarily used in the WebSockets module, specifically in the LibWebSockets (Lws) implementation. It’s part of the online subsystem of Unreal Engine, which handles network communications.

The value of this variable is set by reading from the engine configuration file (GEngineIni) in the “WebSockets.LibWebSockets” section. If not specified in the config file, it defaults to 0.0f.

ThreadMinimumSleepTimeInSeconds interacts with ThreadTargetFrameTimeInSeconds. Together, these variables control the timing of the WebSockets thread’s execution loop.

Developers should be aware that this variable sets a lower bound on the sleep time of the WebSockets thread. Even if the thread completes its work faster than the target frame time, it will still sleep for at least this amount of time.

Best practices when using this variable include:

  1. Setting it to a small, non-zero value to prevent the thread from consuming too much CPU time when idle.
  2. Balancing it with ThreadTargetFrameTimeInSeconds to achieve optimal performance and resource utilization.
  3. Considering the specific needs of the application’s WebSocket communication when adjusting this value.
  4. Testing thoroughly after changing this value to ensure it doesn’t negatively impact the WebSocket performance or overall application responsiveness.

#Setting Variables

#References In INI files

Location: <Workspace>/Engine/Config/BaseEngine.ini:79, section: [WebSockets.LibWebSockets]

#References in C++ code

#Callsites

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

#Loc: <Workspace>/Engine/Source/Runtime/Online/WebSockets/Private/Lws/LwsWebSocketsManager.cpp:53

Scope: file

Source code excerpt:

	GConfig->GetDouble(TEXT("WebSockets.LibWebSockets"), TEXT("ThreadTargetFrameTimeInSeconds"), ThreadTargetFrameTimeInSeconds, GEngineIni);

	ThreadMinimumSleepTimeInSeconds = 0.0f;
	GConfig->GetDouble(TEXT("WebSockets.LibWebSockets"), TEXT("ThreadMinimumSleepTimeInSeconds"), ThreadMinimumSleepTimeInSeconds, GEngineIni);

	GConfig->GetBool(TEXT("LwsWebSocket"), TEXT("bDisableDomainAllowlist"), bDisableDomainAllowlist, GEngineIni);
	GConfig->GetBool(TEXT("LwsWebSocket"), TEXT("bDisableCertValidation"), bDisableCertValidation, GEngineIni);
}

FLwsWebSocketsManager& FLwsWebSocketsManager::Get()

#Loc: <Workspace>/Engine/Source/Runtime/Online/WebSockets/Private/Lws/LwsWebSocketsManager.cpp:241

Scope (from outer to inner):

file
function     uint32 FLwsWebSocketsManager::Run

Source code excerpt:


		double TotalTime = EndTime - BeginTime;
		double SleepTime = FMath::Max(ThreadTargetFrameTimeInSeconds - TotalTime, ThreadMinimumSleepTimeInSeconds);
		FPlatformProcess::SleepNoStats(SleepTime);
	}

	return 0;
}

#Loc: <Workspace>/Engine/Source/Runtime/Online/WebSockets/Private/Lws/LwsWebSocketsManager.h:107

Scope (from outer to inner):

file
class        class FLwsWebSocketsManager : public IWebSocketsManager , public FRunnable , public FSingleThreadRunnable

Source code excerpt:

	double ThreadTargetFrameTimeInSeconds;
	/** Minimum time to sleep in our thread's tick, even if the sleep makes us exceed our target frame time */
	double ThreadMinimumSleepTimeInSeconds;

	bool bDisableDomainAllowlist = false;
	bool bDisableCertValidation = false;

	friend class FLwsWebSocket;
};