distributed-process-0.7.6: Cloud Haskell: Erlang-style concurrency in Haskell
Copyright(c) Well-Typed / Tim Watson
LicenseBSD3 (see the file LICENSE)
MaintainerTim Watson <watson.timothy@gmail.com>
Stabilityexperimental
Portabilitynon-portable (requires concurrency)
Safe HaskellNone
LanguageHaskell2010

Control.Distributed.Process.UnsafePrimitives

Description

Unsafe Variants of Cloud Haskell's Messaging Primitives

Cloud Haskell's semantics do not mention evaluation/strictness properties at all; Only the promise (or lack) of signal/message delivery between processes is considered. For practical purposes, Cloud Haskell optimises communication between (intra-node) local processes by skipping the network-transport layer. In order to ensure the same strictness semantics however, messages still undergo binary serialisation before (internal) transmission takes place. Thus we ensure that in both (the local and remote) cases, message payloads are fully evaluated. Whilst this provides the user with unsurprising behaviour, the resulting performance overhead is quite severe. Communicating data between Haskell threads without forcing binary serialisation reduces (intra-node, inter-process) communication overheads by several orders of magnitude.

This module provides variants of Cloud Haskell's messaging primitives (send, sendChan, nsend and wrapMessage) which do not force binary serialisation in the local case, thereby offering superior intra-node messaging performance. The catch is that any evaluation problems lurking within the passed data structure (e.g., fields set to undefined and so on) will show up in the receiver rather than in the caller (as they would with the normal strategy).

Use of the functions in this module can potentially change the runtime behaviour of your application. In addition, messages passed between Cloud Haskell processes are written to a tracing infrastructure on the local node, to provide improved introspection and debugging facilities for complex actor based systems. This module makes no attempt to force evaluation in these cases either, thus evaluation problems in passed data structures could not only crash your processes, but could also bring down critical internal services on which the node relies to function correctly.

If you wish to repudiate such issues, you are advised to consider the use of NFSerialisable in the distributed-process-extras package, which type class brings NFData into scope along with Serializable, such that we can force evaluation. Intended for use with modules such as this one, this approach guarantees correct evaluatedness in terms of NFData. Please note however, that we cannot guarantee that an NFData instance will behave the same way as a Binary one with regards evaluation, so it is still possible to introduce unexpected behaviour by using unsafe primitives in this way.

You have been warned!

This module is exported so that you can replace the use of Cloud Haskell's safe messaging primitives. If you want to use both variants, then you can take advantage of qualified imports, however Control.Distributed.Process also re-exports these functions under different names, using the unsafe prefix.

Synopsis

Unsafe Basic Messaging

send :: Serializable a => ProcessId -> a -> Process () Source #

Send a message

sendChan :: Serializable a => SendPort a -> a -> Process () Source #

Send a message on a typed channel

nsend :: Serializable a => String -> a -> Process () Source #

Named send to a process in the local registry (asynchronous)

nsendRemote :: Serializable a => NodeId -> String -> a -> Process () Source #

Named send to a process in a remote registry (asynchronous)

usend :: Serializable a => ProcessId -> a -> Process () Source #

Send a message unreliably.

Unlike send, this function is insensitive to reconnect. It will try to send the message regardless of the history of connection failures between the nodes.

Message passing with usend is ordered for a given sender and receiver if the messages arrive at all.

wrapMessage :: Serializable a => a -> Message Source #

Create an unencoded Message for any Serializable type.