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

Do heartbeat on clients #9798

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Do heartbeat on clients #9798

wants to merge 1 commit into from

Conversation

xjules
Copy link
Contributor

@xjules xjules commented Jan 17, 2025

Issue
Resolves #9782

Approach
Heartbeat task sends HEARTBEAT to all the clients (ie. Monitor) at client.HEARTBEAT_TIMEOUT intervals.
Clients do not reply, just process the message. If client detects a longer delay between two heartbeats, the client will send CONNECT to evaluator in addition; ie. getting the connection re-established after a break. This is to simulate re-connection. Each CONNECT_MSG will then trigger sending FullSnapshot from the ensemble evaluator.

Initially HEARTBEAT_TIMEOUT is set to 5 seconds while Monitor accepts 10 seconds at max as a delay. Additionally, initial connection will now undergo same amount of retries as standard messages.

(Screenshot of new behavior in GUI if applicable)

  • PR title captures the intent of the changes, and is fitting for release notes.
  • Added appropriate release note label
  • Commit history is consistent and clean, in line with the contribution guidelines.
  • Make sure unit tests pass locally after every commit (git rebase -i main --exec 'pytest tests/ert/unit_tests -n auto -m "not integration_test"')

When applicable

  • When there are user facing changes: Updated documentation
  • New behavior or changes to existing untested code: Ensured that unit tests are added (See Ground Rules).
  • Large PR: Prepare changes in small commits for more convenient review
  • Bug fix: Add regression test for the bug
  • Bug fix: Create Backport PR to latest release

@xjules xjules self-assigned this Jan 17, 2025
Copy link

codspeed-hq bot commented Jan 17, 2025

CodSpeed Performance Report

Merging #9798 will not alter performance

Comparing xjules:fix_monitor (841a7d0) with main (3f61abe)

Summary

✅ 24 untouched benchmarks

@xjules
Copy link
Contributor Author

xjules commented Jan 19, 2025

Tested with bigpoly on LSF (400 reals, 200 max running) and all was successfully reconnected.

image

@xjules xjules force-pushed the fix_monitor branch 2 times, most recently from 887d748 to bcd8563 Compare January 20, 2025 07:47
@jonathan-eq jonathan-eq self-requested a review January 20, 2025 11:12
await client.send("start", retries=1)

await mock_server.do_ping()
await asyncio.sleep(1)
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we sleep here to force the monitor to reconnect?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, that is correct. PING_TIMEOUT is 0.1 so sleeping 1 seconds guarantees re-connection.

if (
last_ping_time
and (asyncio.get_running_loop().time() - last_ping_time)
> 2 * PING_TIMEOUT
Copy link
Contributor

Choose a reason for hiding this comment

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

I guess the 2* here is for the ping to be received and returned, but do we need it if we are not returning the ping? Maybe in our case it should be added in the PING_TIMEOUT directly?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This 2 * PING_TIMEOUT is to account for a potential delay, which can happen if the ee is very busy.

@xjules xjules changed the title Implement task for pinging clients Do heartbeat on clients Jan 20, 2025
@xjules xjules requested a review from jonathan-eq January 20, 2025 15:07
@@ -93,11 +95,23 @@ async def process_message(self, msg: str) -> None:
raise NotImplementedError("Only monitor can receive messages!")

async def _receiver(self) -> None:
last_beat_time: float | None = None
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe last_heartbeat_time?

Copy link
Contributor

@jonathan-eq jonathan-eq left a comment

Choose a reason for hiding this comment

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

Change last_beat_time -> last_heartbeat_time, and it's good to go! 🚢

@@ -342,6 +360,7 @@ async def _start_running(self) -> None:
raise ValueError("no config for evaluator")
self._ee_tasks = [
asyncio.create_task(self._server(), name="server_task"),
asyncio.create_task(self._do_heartbeat_clients(), name="beat_task"),
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
asyncio.create_task(self._do_heartbeat_clients(), name="beat_task"),
asyncio.create_task(self._do_heartbeat_clients(), name="heartbeat_task"),

@xjules
Copy link
Contributor Author

xjules commented Jan 21, 2025

Change last_beat_time -> last_heartbeat_time, and it's good to go! 🚢

That has been changed, just the hearbeat_task not yet.

Copy link
Collaborator

@sondreso sondreso left a comment

Choose a reason for hiding this comment

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

Apart from my small comment this LGTM!

@@ -51,7 +57,7 @@ def __init__(self, ensemble: Ensemble, config: EvaluatorServerConfig):
self._ensemble: Ensemble = ensemble

self._events: asyncio.Queue[Event] = asyncio.Queue()
self._events_to_send: asyncio.Queue[Event] = asyncio.Queue()
self._events_to_send: asyncio.Queue[Event | bytes] = asyncio.Queue()
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could we be more specific here?

@xjules xjules force-pushed the fix_monitor branch 2 times, most recently from dac0c07 to 467c276 Compare January 21, 2025 14:20
Heartbeat task sends HEARTBEAT to all the clients (ie. Monitor) at client.HEARTBEAT_TIMEOUT intervals.
Clients do not reply, just process the message. If client detects longer delay between two heartbeats,
the client will send CONNECT to evaluator in addition; ie. getting the connection re-established after a break.
This is to simulate re-connection. Each CONNECT_MSG will then trigger sending FullSnapshot from the ensemble evaluator.
Initially HEARTBEAT_TIMEOUT is set to 5 seconds while Monitor accepts 10 seconds at max as a delay.
Additionally, initial connection will now undergo same amount of retries as standard messages.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

zmq: Implement ACK or re-connection for Monitor
3 participants