goodboy / tractor

A distributed, structured concurrent runtime for Python (and friends)
GNU Affero General Public License v3.0
271 stars 12 forks source link

Spec out the async-ipc protocol #36

Open goodboy opened 6 years ago

goodboy commented 6 years ago

tractor utilizes a simple multiplexed protocol for conducting inter-process-task-communication (IPTC)?

Each per-process trio task can invoke tasks in other processes and received responses depending on the type of the remote callable. All packets are encoded as msgpack serialized dictionaries which I'll refer to as messages.

How it works

When an actor wants to invoke a remote routine it sends a cmd packet: {'cmd': (ns, func, kwargs, uid, cid)} of type Dict[str, Tuple[str, str, Dict[str, Any], Tuple[str, str], str]] Where:

The first response is a function type notifier msg: {'functype': functype, 'cid': cid} of type Dict[str, str]. Where functype can take one of:

Depending on the value of functype then the following message(s) are sent back to the caller:

A remote task which is streaming over a channel can indicate completion using a ''stop'` message:

If a remote task errors it should capture it's error output (still working on what output) and send it in a message back to its caller:

A remote actor must have a system in place to cancel tasks spawned from the caller. The system to do this should be invoke-able using the existing protocol defined above and thus no extra "cancel" message should be required (I think).

What should be done

goodboy commented 3 years ago

Pretty interested in using msgspec for the first draft of this. I've made https://github.com/jcrist/msgspec/issues/25 to see what we can do about getting nested msgpec.Structs which would be most ideal for defining our internal message set.

This also ties in heavily with #196 since we'll likely want to offer a system for automatically inferring schema from target remote task functions and/or allowing for an explicit declaration system of some sort.

Also of note is how we could also possibly tie this in with capnproto schemas