ThreadTargetFrameTimeInSeconds
ThreadTargetFrameTimeInSeconds
#Overview
name: ThreadTargetFrameTimeInSeconds
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 ThreadTargetFrameTimeInSeconds is to control the frame rate of the WebSockets thread in Unreal Engine 5’s WebSockets module. It specifically targets the LibWebSockets implementation.
This setting variable is primarily used by the WebSockets module, particularly in the LibWebSockets (LWS) implementation. It’s part of the Online subsystem of Unreal Engine.
The value of this variable is initially set to 1.0f / 30.0f (approximately 0.0333 seconds), which corresponds to a 30Hz frame rate. However, it can be overridden by a configuration value in the engine’s INI file. The code reads this value from the “WebSockets.LibWebSockets” section of the engine configuration.
ThreadTargetFrameTimeInSeconds interacts with another variable called ThreadMinimumSleepTimeInSeconds. These two variables work together to control the timing of the WebSockets thread’s execution loop.
Developers should be aware that this variable directly affects the responsiveness and performance of WebSocket connections. Setting it too high might result in slower response times, while setting it too low could unnecessarily consume CPU resources.
Best practices when using this variable include:
-
Adjusting it based on the specific needs of your application. If you need more responsive WebSocket communication, you might want to increase the frequency (lower the value).
-
Consider the trade-off between responsiveness and resource usage. A higher frequency (lower value) will use more CPU time.
-
Always test the impact of changes to this value in your specific use case and on target hardware.
-
Use the configuration file to set this value rather than hardcoding it, allowing for easier adjustments without recompilation.
-
Be mindful of how this interacts with ThreadMinimumSleepTimeInSeconds, ensuring that the minimum sleep time doesn’t prevent achieving the target frame time.
#Setting Variables
#References In INI files
Location: <Workspace>/Engine/Config/BaseEngine.ini:78, section: [WebSockets.LibWebSockets]
- INI Section:
WebSockets.LibWebSockets
- Raw value:
0.0333
- Is Array:
False
#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:50
Scope: file
Source code excerpt:
, Thread(nullptr)
{
ThreadTargetFrameTimeInSeconds = 1.0f / 30.0f; // 30Hz
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);
#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:105
Scope (from outer to inner):
file
class class FLwsWebSocketsManager : public IWebSocketsManager , public FRunnable , public FSingleThreadRunnable
Source code excerpt:
/** Target frame time for our thread's tick */
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;