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

Merged
merged 1 commit into from
Jan 23, 2025
Merged

Do heartbeat on clients #9798

merged 1 commit into from
Jan 23, 2025

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 improve performances by 10.2%

Comparing xjules:fix_monitor (d2980a2) with main (905fb9a)

Summary

⚡ 1 improvements
✅ 23 untouched benchmarks

Benchmarks breakdown

Benchmark BASE HEAD Change
test_direct_dark_performance_with_storage[gen_x: 20, sum_x: 20 reals: 10-summary-get_record_observations] 1.4 ms 1.2 ms +10.2%

@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
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 5 times, most recently from d2afc2a to 8589c06 Compare January 22, 2025 14:27
@xjules xjules requested a review from sondreso January 22, 2025 14:43
@@ -45,13 +51,17 @@
EVENT_HANDLER = Callable[[list[Event]], Awaitable[None]]


class HeartbeatEvent(Enum):
event = b"BEAT"
Copy link
Contributor

Choose a reason for hiding this comment

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

Rather than hardcoding b"BEAT", can we import it from client?

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.
@xjules xjules requested a review from jonathan-eq January 23, 2025 11:43
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.

Very good! 🚢

@xjules xjules merged commit 299289f into equinor:main Jan 23, 2025
33 checks passed
@xjules xjules deleted the fix_monitor branch January 23, 2025 11:52
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