clusterio

clusterio gives a group of hosts one shared dict, list and file system, and functions that run atomically on all of them. You write a Python script; three environment variables make it a distributed application.

python
import clusterio

users = clusterio.dict("users")          # a MutableMapping, the same on every host
users["ada"] = {"lang": "python"}

jobs = clusterio.list("jobs")            # a MutableSequence
jobs.append({"id": 1})

with clusterio.open("reports/today.txt", "w") as f:
    f.write("hello")

Underneath, the nodes keep one log with Raft and apply it to SQLite. There is no server to install: each process that imports clusterio is a node.

Why clusterio#

  • Familiar. dict, list, open, threading.Lock: the types you already use, shared across hosts. No client library, query language or schema to learn.
  • Pure Python, easy to run. pip install clusterio. No ZooKeeper, etcd or Redis to operate; with nothing configured, it is a one-node cluster on disk.
  • Peer-to-peer and low latency. Every node holds the whole state, so a read is a local SQLite query. A write takes about a millisecond on a LAN.
  • Coordination, not just storage. Transactions and leased locks are enough to build an etcd, a job queue or a cron scheduler in an afternoon.
  • Checked, not just tested. The Raft core is written as a Temporal Typing specification that Tanny model-checks against the five safety properties of the Raft paper. The node that runs carries its own specification, and Tanny checks its method bodies against it. See Correctness.

The whole API#

clusterio.dict(name)A shared dict: str keys, JSON values
clusterio.list(name)A shared list of JSON values
clusterio.open(path, mode="r", encoding=None)A shared file
clusterio.listdir(path=""), clusterio.remove(path)As os.listdir and os.remove
@clusterio.transactionRun a function atomically on every node
clusterio.lock(name, ttl=10)A lock with a lease, used as threading.Lock
clusterio.now()The time; in a transaction, the same on every node
clusterio.Cluster(node, peers, data)The node behind all of these, for use as a library

Where next#

Note

clusterio is alpha: the API may change before 1.0. Membership is fixed, the log is not compacted, and traffic between nodes is neither authenticated nor encrypted, so run it on a network you trust.