Skip to content

New output port#369

Merged
slawlor merged 12 commits intoslawlor:mainfrom
Kannen:new-output-port
Aug 19, 2025
Merged

New output port#369
slawlor merged 12 commits intoslawlor:mainfrom
Kannen:new-output-port

Conversation

@Kannen
Copy link
Copy Markdown
Contributor

@Kannen Kannen commented Jul 18, 2025

With the current implementation of OutputPort, if an actor send more than 10 messages on an output port before the runtime has the opportunity to preempt it, only the 10 last messages may be received by subscribers.
Moreover, it is not guaranteed that those last 10 messages will be received either.

This new implementation ensures that all messages are sent and will be received by subscribers.

It also open the opportunity to implement more advanced subscriber strategy, to remove subscriber, to ensure that subscription is not duplicated and to clone the OutputPort. For now this pull request only provide the insurance that all messages will be delivered, and does not add anymore feature.

@slawlor
Copy link
Copy Markdown
Owner

slawlor commented Jul 30, 2025

Given OutputPort is a pretty standalone functionality, it probably makes sense to fork this behind an opt-in/out feature? This way someone can take the "new" vs "old" functionality if they don't want to impact their production functionality (or don't have time to test the change in their environments).

So I'd request that we add a feature that toggles on these changes, and that can control which functionality would run.

Comment thread ractor/src/port/output.rs Outdated
} else {
subscribers.push((subscriber.id(), subscriber));
}
} //OutportMessage::RemoveSubscriber(id) => {
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

is this needed?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

With this implementation it is possible to unsubscribe and to get a list of subscriber to a port. We plan to use it soon. I remove it for now, and I will propose

Comment thread ractor/src/port/output.rs Outdated
} else {
subscribers.push((subscriber.id(), subscriber));
}
} //OutportMessage::RemoveSubscriber(id) => {
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

why is all this commented logic here?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This implementation open the door to knew features I have implemented and that I plan to use. I remove it for now and I will propose a new pull request for their addition latter.

@Kannen
Copy link
Copy Markdown
Contributor Author

Kannen commented Jul 30, 2025 via email

@codecov
Copy link
Copy Markdown

codecov Bot commented Aug 11, 2025

Codecov Report

❌ Patch coverage is 91.48936% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 82.48%. Comparing base (a5e0c65) to head (b847fb4).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
ractor/src/port/output.rs 91.48% 4 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main     #369   +/-   ##
=======================================
  Coverage   82.48%   82.48%           
=======================================
  Files          71       71           
  Lines       12919    12919           
=======================================
  Hits        10656    10656           
  Misses       2263     2263           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@Kannen
Copy link
Copy Markdown
Contributor Author

Kannen commented Aug 11, 2025

The failing test is unrelated to output ports, it is due to a race condition in the implementation of pg.

@Kannen Kannen requested a review from slawlor August 13, 2025 18:43
Copy link
Copy Markdown
Owner

@slawlor slawlor left a comment

Choose a reason for hiding this comment

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

Thanks for adding the gate, the approach seems reasonable, and when there's more opt-in validation in prod, we can probably swap out the underlying implementations

Comment thread ractor/src/port/output.rs Outdated
continue 'subs;
} else {
coop_count = coop_count.wrapping_add(1);
#[cfg(feature = "tokio_runtime")]
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

what happens here in non-tokio environments?

@slawlor slawlor merged commit 995f4d6 into slawlor:main Aug 19, 2025
25 checks passed
slawlor pushed a commit that referenced this pull request Aug 19, 2025
* OuputPort use a single task to dispatch messages

The previous implementation did not ensured that all messages arrived to
subscribers. Now message send to the output port are guarenteed to be
delivered.

* bench OutputPort

* change outport bench msg and receiver numbers

* fix unused warning

* fix new output port implementation to suport async-std

* reduce outport message dispatch time by 60%!

* removed extra ouput port feature, provides previous ouputport implementation by default, the new is accessible with a feature

* update ci to test feature output-port-v2

* change clippy lint name

* added  feature documentation
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants