Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HITL: server-side helpers to measure client latency #1796

Merged
merged 1 commit into from
Feb 10, 2024

Conversation

eundersander
Copy link
Contributor

Motivation and Context

Add ClientMessageManager.set_server_keyframe_id and RemoteGuiInput.pop_recent_server_keyframe_id to help the server measure client latency.

This feature will require follow-up work in the Unity client. stub_client.html provides a reference implementation.

In the example code below, roughly speaking, this is the latency between something happening in a sim_step on the server and the client's reaction (as GuiInput) being available in a later sim_step.

Usage: consider a server AppState that maintains a frame counter. It uses ClientMessageManager.set_server_keyframe_id on every frame. The client receives and renders a frame with serverKeyframeID=k. It should include recentServerKeyframeId=k in the next clientState it sends to the server. (See stub_client.html for an example.). In the server AppState, it can check RemoteGuiInput.pop_recent_server_keyframe_id() and compare it to its current frame counter.

Example usage in an AppState:

def __init__(...):
    self._frame_counter = 0

def sim_update(...):
    ...
    if self._app_service.remote_gui_input:
        recent_server_keyframe_id = self._app_service.remote_gui_input.pop_recent_server_keyframe_id()
        if recent_server_keyframe_id:
            print(f"client frame latency: {self._frame_counter - recent_server_keyframe_id}")

    if self._app_service.client_message_manager:
        self._app_service.client_message_manager.set_server_keyframe_id(self._frame_counter)
    self._frame_counter += 1

How Has This Been Tested

Local testing with rearrange and pick_throw_vr AppStates. With stub HTML client. Regression testing with Unity in-editor client (although it doesn't yet implement the required client-side functionality for this feature).

Types of changes

[HITL]

Checklist

  • My code follows the code style of this project.
  • I have updated the documentation if required.
  • I have read the CONTRIBUTING document.
  • I have completed my CLA (see CONTRIBUTING)
  • I have added tests to cover my changes if required.

…p_recent_server_keyframe_id to help the server measure client latency
@facebook-github-bot facebook-github-bot added the CLA Signed Do not delete this pull request or issue due to inactivity. label Feb 8, 2024
Copy link
Contributor Author

@eundersander eundersander left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some comments.

message_key
]
# add/update all messages
for message_key in inc_message:
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems like a good general rule that consolidating messages simply means updating to the latest message in the latest incremental keyframe. Let's beware a future situation where a client must absolutely receive an entire sequence of messages (not just the latest one).

@@ -48,6 +50,18 @@
document.getElementById('serverPort').disabled = true;
document.getElementById('sendButton').disabled = false;
ws.send('client ready!'); // Send "client ready!" to the server

// Start sending messages at 10 Hz
sendIntervalId = setInterval(function() {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As part of this PR, the stub HTML client now sends client states at 10 Hz.

Copy link
Contributor

@0mdc 0mdc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@@ -12,6 +12,7 @@
from habitat_hitl.core.gui_input import GuiInput


# todo: rename to RemoteClientState
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@eundersander eundersander merged commit cf94ffb into main Feb 10, 2024
4 checks passed
@eundersander eundersander deleted the eundersander/hitl_server_keyframe_id branch February 10, 2024 02:19
eundersander added a commit that referenced this pull request Feb 10, 2024
…p_recent_server_keyframe_id to help the server measure client latency (#1796)
henrysamer pushed a commit that referenced this pull request Feb 21, 2024
…p_recent_server_keyframe_id to help the server measure client latency (#1796)
dannymcy pushed a commit to dannymcy/habitat-lab that referenced this pull request Jul 8, 2024
…p_recent_server_keyframe_id to help the server measure client latency (facebookresearch#1796)
HHYHRHY pushed a commit to SgtVincent/habitat-lab that referenced this pull request Aug 31, 2024
…p_recent_server_keyframe_id to help the server measure client latency (facebookresearch#1796)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed Do not delete this pull request or issue due to inactivity.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants