slawlor / ractor

Rust actor framework
MIT License
1.38k stars 69 forks source link

Actor MailBox - Bounded Channel #84

Closed theduke closed 1 year ago

theduke commented 1 year ago

The actor mailbox is currently implemented with an unbounded mpsc channel.

This seems to allow an actor input port to get filled up with lots of messages and does not provide any backpressure mechanism.

It would be nice to have a configuration option to use a bounded channel instead, with message delivery either blocking until capacity is available, or failing immediately . (with different methods)

Motiviation: both providing back pressure and preventing infinite buildup of messages are important design properties that are easy to do by just using regular channels.

This could be emulated by a top level actor that delegates to child actors and keeps track of in-flight messages being processed, but that's a lot more complicated.

slawlor commented 1 year ago

This could be emulated by a top level actor that delegates to child actors and keeps track of in-flight messages being processed, but that's a lot more complicated.

That's exactly a factory with a queue'ing strategy which is implemented in the core ractor crate. Backpressure is not implemented for specific Erlang gen_servers which is what we stuck to here, and like you said you can abstract it through a parent/supervising actor which maintains the message queue and doesn't spend time processing requests.

slawlor commented 1 year ago

Closing, please feel free to re-open if you feel this doesn't solve your need.