--- AnyEvent-Fork-RPC/README 2013/09/25 11:06:11 1.4 +++ AnyEvent-Fork-RPC/README 2016/05/12 16:54:43 1.5 @@ -172,7 +172,7 @@ Example 2: Asynchronous Backend This example implements multiple count-downs in the child, using - AnyEvent timers. While this is a bit silly (one could use timers in te + AnyEvent timers. While this is a bit silly (one could use timers in the parent just as well), it illustrates the ability to use AnyEvent in the child and the fact that responses can arrive in a different order then the requests. @@ -437,7 +437,7 @@ By overriding this you can prolong the life of a RPC process after e.g. the parent has exited by running the event loop in the provided function (or simply calling it, for example, when - your child process uses EV you could provide EV::loop as "done" + your child process uses EV you could provide EV::run as "done" function). Of course, in that case you are responsible for exiting at the @@ -471,7 +471,8 @@ By default, only octet strings can be passed between the processes, which is reasonably fast and efficient and requires - no extra modules. + no extra modules (the "AnyEvent::Fork::RPC" distribution does + not provide these extra serialiser modules). For more complicated use cases, you can provide your own freeze and thaw functions, by specifying a string with perl source @@ -485,13 +486,19 @@ add a "use" or "require" statement into the serialiser string. Or both. - Here are some examples - some of them are also available as + Here are some examples - all of them are also available as global variables that make them easier to use. - octet strings - $AnyEvent::Fork::RPC::STRING_SERIALISER - This serialiser concatenates length-prefixes octet strings, - and is the default. That means you can only pass (and - return) strings containing character codes 0-255. + $AnyEvent::Fork::RPC::STRING_SERIALISER - octet strings only + This serialiser (currently the default) concatenates + length-prefixes octet strings, and is the default. That + means you can only pass (and return) strings containing + character codes 0-255. + + The main advantages of this serialiser are the high speed + and that it doesn't need another module. The main + disadvantage is that you are very limited in what you can + pass - only octet strings. Implementation: @@ -500,7 +507,30 @@ sub { unpack "(w/a*)*", shift } ) - json - $AnyEvent::Fork::RPC::JSON_SERIALISER + $AnyEvent::Fork::RPC::CBOR_XS_SERIALISER - uses CBOR::XS + This serialiser creates CBOR::XS arrays - you have to make + sure the CBOR::XS module is installed for this serialiser to + work. It can be beneficial for sharing when you preload the + CBOR::XS module in a template process. + + CBOR::XS is about as fast as the octet string serialiser, + but supports complex data structures (similar to JSON) and + is faster than any of the other serialisers. If you have the + CBOR::XS module available, it's the best choice. + + The encoder enables "allow_sharing" (so this serialisation + method can encode cyclic and self-referencing data + structures). + + Implementation: + + use CBOR::XS (); + ( + sub { CBOR::XS::encode_cbor_sharing \@_ }, + sub { @{ CBOR::XS::decode_cbor shift } } + ) + + $AnyEvent::Fork::RPC::JSON_SERIALISER - uses JSON::XS or JSON This serialiser creates JSON arrays - you have to make sure the JSON module is installed for this serialiser to work. It can be beneficial for sharing when you preload the JSON @@ -518,7 +548,7 @@ sub { @{ JSON::decode_json shift } } ) - storable - $AnyEvent::Fork::RPC::STORABLE_SERIALISER + $AnyEvent::Fork::RPC::STORABLE_SERIALISER - Storable This serialiser uses Storable, which means it has high chance of serialising just about anything you throw at it, at the cost of having very high overhead per operation. It @@ -533,7 +563,7 @@ sub { @{ Storable::thaw shift } } ) - portable storable - $AnyEvent::Fork::RPC::NSTORABLE_SERIALISER + $AnyEvent::Fork::RPC::NSTORABLE_SERIALISER - portable Storable This serialiser also uses Storable, but uses it's "network" format to serialise data, which makes it possible to talk to different perl binaries (for example, when talking to a @@ -615,7 +645,7 @@ it listens for another request by the parent, it might detect that the socket was closed (e.g. because the parent exited). It will sotp listening for new requests and instead try to write out any - remaining data (if any) or simply check whether the socket cna be + remaining data (if any) or simply check whether the socket can be written to. After this, the RPC process is effectively done - no new requests are incoming, no outstanding request data can be written back. @@ -690,7 +720,8 @@ mechanism if this causes problems. Alternatively, the parent could limit the amount of rpc calls that are outstanding. - Blocking use of condvars is not supported. + Blocking use of condvars is not supported (in the main thread, + outside of e.g. Coro threads). Using event-based modules such as IO::AIO, Gtk2, Tk and so on is easy. @@ -762,7 +793,7 @@ EXCEPTIONS There are no provisions whatsoever for catching exceptions at this time - - in the child, exeptions might kill the process, causing calls to be + - in the child, exceptions might kill the process, causing calls to be lost and the parent encountering a fatal error. In the parent, exceptions in the result callback will not be caught and cause undefined behaviour.