Transport protocol¶
Available transports¶
Although the default transport protocol is IPC for operating systems that provide UNIX domain sockets and TCP for the rest, there are other transport protocols that can be used in osBrain:
tcp
: common TCP. Can always be used, and must be used to communicate agents running in different machines.ipc
: common IPC. It is the default and the best suited for communication between agents that run on the same machineinproc
: for in-process communication (between threads). The fastest protocol, although it is limited to communication between threads that share the sameAgent.context
The transport protocol can be changed on a per-socket basis, per-agent basis and also globally.
Changing the transport¶
It is possible to change the default global transport protocol by setting
the osbrain.config['TRANSPORT']
configuration variable. So, for example, to
set TCP as the default transport, we could set:
osbrain.config['TRANSPORT'] = 'tcp'
We can also set the default transport that a particular agent should use by
default by passing the transport
parameter to
run_agent
:
agent = run_agent('a0', transport='tcp')
If we do not want to change the global default nor any agent’s default, then
we can still change the transport protocol when binding, passing the
transport
parameter again:
agent = run_agent('a0')
agent.bind('PULL', transport='inproc')
Note
It is also possible to change the global default transport protocol
setting the OSBRAIN_DEFAULT_TRANSPORT
environment variable.