...or Mobile Agents with Python.
What Are Mobile Agents?
"A mobile agent is a process that can transport its state from one environment to another, with its data intact, and be capable of performing appropriately in the new environment." — Wikipedia: Mobile agent
Why Mobile Agents — Dealing with Data Gravity
The phrase "with its data" most likely refers to the agent's state data (rather than all types of data), since one of the nicest properties of mobile agents is that they can move to where potentially huge amounts of data already live.
By plotting the "data gravity" curve — a rough estimate of how long it takes to empty, fill, or process a hard drive over a network connection (hard disk size divided by typical Ethernet network speed over 20 years) — the motivation for moving code to data (rather than data to code) has clearly been increasing, making mobile agents an appealing model.
Mobile Agent Runtime Environment
A basic requirement for a mobile agent runtime is the ability to receive and run the agent's code — typically supporting one or more of the following (with Python examples):
- Receive and run binary code — e.g., receive Python compiled to native binary with Shedskin and
g++. - Receive and compile source code, then run it — e.g., receive C source code and compile/integrate it with Python using Cinpy, or compile received Python with Shedskin/
g++. - Receive and interpret source code — e.g., receive Python code and interpret it using
eval().
Bandwidth
If mobile agents move around frequently, you want their representation as compact as possible to minimize bandwidth — favoring compact source code (options 2 or 3) over larger compiled binaries (option 1).
Processing
Compiled (or JIT-compiled) code is usually far more efficient than interpreted code (which can be thought of as the "gas-guzzling cars" of computing with respect to resource utilization), so option 2 is generally preferable to option 3. With cinpy, compilation overhead is negligible — a few milliseconds to compile a short C function and make it callable from Python — which matters when dispatching many distributed mobile agents.
The Pareto principle applies here as well: keeping 80–99% of the logic in interpreted Python while compiling the performance-critical hotspots in C via cinpy can be an effective balance.
Example of a Cinpy-Wrapped C Function in Python
fibc = cinpy.defc(
"fib",
ctypes.CFUNCTYPE(ctypes.c_int, ctypes.c_int),
"""
int fib(int x) {
if (x <= 1) return 1;
return fib(x - 1) + fib(x - 2);
}
"""
)Security
When mobile agents move across machines in the cloud, it is important to verify that an agent comes from a trusted source (yourself). For example, you can use ezPyCrypto's signString() to sign the agent source code and verifyString() on the receiving side (using the signer's public key) to authenticate the agent's origin before execution.
Disclaimer: this posting (and all others on this blog) only represents my personal views.