-
-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implements NetworkPerformance autoload, that provides custom monitors for networking performance measurements. Refs #173
- Loading branch information
1 parent
1526d26
commit a1253dc
Showing
9 changed files
with
178 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
extends Node | ||
|
||
const NETWORK_LOOP_DURATION_MONITOR: StringName = "netfox/Network loop duration (ms)" | ||
const ROLLBACK_LOOP_DURATION_MONITOR: StringName = "netfox/Rollback loop duration (ms)" | ||
const NETWORK_TICKS_MONITOR: StringName = "netfox/Network ticks simulated" | ||
const ROLLBACK_TICKS_MONITOR: StringName = "netfox/Rollback ticks simulated" | ||
const ROLLBACK_TICK_DURATION_MONITOR: StringName = "netfox/Rollback tick duration (ms)" | ||
|
||
var _network_loop_start: float = 0 | ||
var _network_loop_duration: float = 0 | ||
|
||
var _network_ticks: int = 0 | ||
var _network_ticks_accum: int = 0 | ||
|
||
var _rollback_loop_start: float = 0 | ||
var _rollback_loop_duration: float = 0 | ||
|
||
var _rollback_ticks: int = 0 | ||
var _rollback_ticks_accum: int = 0 | ||
|
||
static var _logger: _NetfoxLogger = _NetfoxLogger.for_netfox("NetworkPerformance") | ||
|
||
func is_enabled(): | ||
if OS.has_feature("netfox_noperf"): | ||
return false | ||
|
||
if OS.has_feature("netfox_perf"): | ||
return true | ||
|
||
# This returns true in the editor too | ||
return OS.is_debug_build() | ||
|
||
## Get time spent in the last network tick loop, in millisec. | ||
## [br] | ||
## Note that this also includes time spent in the rollback tick loop. | ||
func get_network_loop_duration_ms() -> float: | ||
return _network_loop_duration * 1000 | ||
|
||
## Get the number of ticks simulated in the last network tick loop. | ||
func get_network_ticks() -> int: | ||
return _network_ticks | ||
|
||
## Get time spent in the last rollback tick loop, in millisec. | ||
func get_rollback_loop_duration_ms() -> float: | ||
return _rollback_loop_duration * 1000 | ||
|
||
## Get the number of ticks resimulated in the last rollback tick loop. | ||
func get_rollback_ticks() -> int: | ||
return _rollback_ticks | ||
|
||
## Get the average amount of time spent in a rollback tick during the last | ||
## rollback loop, in millisec. | ||
func get_rollback_tick_duration_ms() -> float: | ||
return _rollback_loop_duration * 1000 / maxi(_rollback_ticks, 1) | ||
|
||
func _ready(): | ||
if not is_enabled(): | ||
_logger.debug("Network performance disabled") | ||
return | ||
|
||
_logger.debug("Network performance enabled, registering performance monitors") | ||
Performance.add_custom_monitor(NETWORK_LOOP_DURATION_MONITOR, get_network_loop_duration_ms) | ||
Performance.add_custom_monitor(ROLLBACK_LOOP_DURATION_MONITOR, get_rollback_loop_duration_ms) | ||
Performance.add_custom_monitor(NETWORK_TICKS_MONITOR, get_network_ticks) | ||
Performance.add_custom_monitor(ROLLBACK_TICKS_MONITOR, get_rollback_ticks) | ||
Performance.add_custom_monitor(ROLLBACK_TICK_DURATION_MONITOR, get_rollback_tick_duration_ms) | ||
|
||
NetworkTime.before_tick_loop.connect(_before_tick_loop) | ||
NetworkTime.on_tick.connect(_on_network_tick) | ||
NetworkTime.after_tick_loop.connect(_after_tick_loop) | ||
|
||
NetworkRollback.before_loop.connect(_before_rollback_loop) | ||
NetworkRollback.on_process_tick.connect(_on_rollback_tick) | ||
NetworkRollback.after_loop.connect(_after_rollback_loop) | ||
|
||
func _before_tick_loop(): | ||
_network_loop_start = _time() | ||
_network_ticks_accum = 0 | ||
|
||
func _on_network_tick(_dt, _t): | ||
_network_ticks_accum += 1 | ||
|
||
func _after_tick_loop(): | ||
_network_loop_duration = _time() - _network_loop_start | ||
_network_ticks = _network_ticks_accum | ||
|
||
func _before_rollback_loop(): | ||
_rollback_loop_start = _time() | ||
_rollback_ticks_accum = 0 | ||
|
||
func _on_rollback_tick(_t): | ||
_rollback_ticks_accum += 1 | ||
|
||
func _after_rollback_loop(): | ||
_rollback_loop_duration = _time() - _rollback_loop_start | ||
_rollback_ticks = _rollback_ticks_accum | ||
|
||
func _time() -> float: | ||
return Time.get_unix_time_from_system() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
# NetworkPerformance | ||
|
||
Provides [custom monitors] for measuring networking performance. Included as an | ||
autoload. | ||
|
||
## Enabling monitoring | ||
|
||
By default, network performance monitoring is only enabled in debug builds and | ||
when running from the editor. | ||
|
||
Use the `netfox_noperf` feature tag to force disable network performance | ||
monitors. | ||
|
||
Use the `netfox_perf` feature tag to force enable network performance monitors. | ||
|
||
These feature tags enable customization for each export preset. | ||
|
||
## Performance monitors | ||
|
||
### Network loop duration | ||
|
||
*Network loop duration* measures the time spent in the [network tick loop]. | ||
Note that this includes time spent on the [rollback loop] as well. | ||
|
||
This value is updated once for every tick loop, it is not reset to zero after | ||
the loop has run. This means that you may get a non-zero reading, even if the | ||
tick loop is currently not running. | ||
|
||
### Rollback loop duration | ||
|
||
*Rollback loop duration* measures the time spent in the last [rollback loop]. | ||
This includes all of its steps. | ||
|
||
The value of this monitor may be zero, if no players have joined, no nodes use | ||
rollback, or rollback is disabled. | ||
|
||
### Network ticks simulated | ||
|
||
*Network ticks simulated* measures the number of ticks run in the last [network | ||
tick loop]. If the game runs at a higher FPS than the network tickrate, this | ||
value should be consistently one. | ||
|
||
Higher, stable values mean that the game itself runs slower than the network | ||
tickrate, and needs to catch up by running multiple ticks on each frame. | ||
|
||
### Rollback ticks simulated | ||
|
||
*Rollback ticks simulated* measures the number of rollback ticks run in the | ||
last [rollback loop]. Generally, this denotes the age of the oldest input *or* | ||
state received, depending on whether the game is running as a server or client. | ||
|
||
The measurement is strongly correlated to network latency - the higher the | ||
latency, the older the state and input packets will be upon arrival. | ||
|
||
The more rollback ticks need to be simulated, the more work the rollback tick | ||
has to do, which can negatively affect performance. | ||
|
||
### Rollback tick duration | ||
|
||
*Rollback tick duration* provides the average time spent simulating a single | ||
tick in the last [rollback loop]. | ||
|
||
This can be useful to determine if the rollback tick duration comes from too | ||
many ticks being simulated, or the individual ticks being expensive to | ||
simulate ( or both ). | ||
|
||
[custom monitors]: https://docs.godotengine.org/en/latest/classes/class_performance.html#class-performance-method-add-custom-monitor | ||
[network tick loop]: ./network-time.md | ||
[rollback loop]: ./network-rollback.md |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters