Skip to content

About

Share CPU between your own devices over Tailscale: run commands on the least-loaded device, fan out tasks, live dashboard

Topics

Resources

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

25 Commits

Folders and files

Repository files navigation

compute-pool

OpenSSF Scorecard

Share CPU between your own devices over Tailscale. Each device runs an agent; any allowed device can send it a command and get the output streamed back.

pool agent --allow desktop               # on each worker; allow only where you submit from
pool nodes                               # load, power and status of every device
pool run -- go test ./...                # run on the least-loaded device
pool run --node laptop -- go test ./...  # or pick the device yourself
pool map --inputs 'data/*.csv' --ship analyze.py --collect out -- python analyze.py {}
                                         # one task per file, spread over every device
The pool dashboard: five devices with their status, CPU load, idle CPUs, job slots and power, followed by running and recent jobs

Status: early. Works on Windows (tested on two machines); Linux and macOS build and pass the test suite in CI. See SECURITY.md before running an agent.

This README describes main. The latest published release is v0.1.4, which predates pool setup, pool advise, pool report, pool map --dry-run, the live job limit (CPU and memory) and the log an agent serves at /v1/log. Until the next release, build from source (see Build) to get them.

Install

Download the binary for your platform from Releases, verify it against SHA256SUMS, rename it to pool (pool.exe on Windows) and put it on your PATH. Release binaries are built by GitHub Actions from the tagged commit. They aren't code-signed yet, so Windows may warn before running them, and on a PC with Smart App Control turned on it may refuse to run them at all. Smart App Control judges each file separately, so one release can run while the next is blocked. Application control covers signing your own builds and trusting them with an App Control policy.

Releases after v0.1.0 also carry build provenance: a signed record that each binary was built by this repository's release workflow. Check it with the GitHub CLI:

gh attestation verify pool-0.1.4-windows-amd64.exe --repo montjeffrey/compute-pool

Release tags from v0.1.1 on are signed, and show as Verified on GitHub.

Splitting work with pool map

pool map runs one task per item, using every free job slot on every device. Choose the items with exactly one of:

Flag One task per… {} becomes
--range 1..100 number the number
--items list.txt (or - for stdin) non-empty line the line
--inputs 'data/*.csv' matching local file (shipped with its task) the file's name

{#} becomes the task number. Each task also gets POOL_TASK_INDEX and POOL_TASK_ITEM in its environment.

  • --ship FILE_OR_DIR (repeatable) sends files with every task. A shipped program can be run by name: --ship tool.exe -- tool.exe {}.
  • --collect PATTERN (repeatable) brings back matching files (a matching folder comes back whole) into pool-out/<task#>/.
  • Output prints as one block per task; --keep-order prints in input order; -v adds a line per task showing where it ran and how long it took.
  • If a device fails mid-task, the task is retried elsewhere (--retries 2). If a device pauses (battery, busy), its tasks go to the others.
  • Near the end, slow tasks get a backup copy on a faster device; the first to finish wins and the other is canceled. Turn this off with --speculate=false for tasks that do more than produce output (send email, write to a shared database, and so on).
  • Agents cache shipped files by SHA-256 (--cache-mb 2048), so a program shipped with 1,000 tasks crosses the network once per device, and later runs reuse it. Content is verified against its hash before it is cached. A shipped program runs as a hard link to its cached copy, which is re-verified before each use, so antivirus scans it once rather than once per task (Windows Defender adds about half a second to each new copy of a program). Other shipped files are copied, so a task that writes to its input doesn't change the cached copy. Running tasks share an account, though; see SECURITY.md.

Paths are checked on both sides: inputs and collected files can't use .., absolute paths, drive letters, Windows device names (CON, NUL, …) or control characters, and a matched symbolic link is skipped rather than followed. The client never writes a returned file through an existing link. Limits per task: about 180 MiB and 10,000 shipped files; 256 MiB and 10,000 collected files; 16 MiB of buffered output each for stdout and stderr in pool map.

Measured speedup

scripts/bench.ps1 runs the same CPU-bound tasks (cmd/poolbench, ~1.7s each on the desktop) on one device and on all devices. Here a desktop lending 10 slots is paired with a laptop:

Laptop lends Power Tasks Desktop alone Both Speedup Laptop's time per task
8 slots plugged in 96 18.5s 14.1s 1.31× ~3.1s
8 slots battery (--lend-on-battery) 96 19.0s 16.7s 1.14× ~3.4s
2 slots plugged in 48 10.1–10.5s 9.5–9.7s 1.05–1.10× ~2.3s
2 slots battery (--lend-on-battery) 48 9.7s 9.9s 0.98× ~2.75s

With 8 slots plugged in, the best possible result is about 1.45× (desktop ~5.9 tasks/s, laptop ~2.6 tasks/s); the pool gets ~90% of it, and the laptop does a third of the work. The laptop's tasks slow down when it runs many at once or runs on battery, which is most of the difference between the rows.

  • Lend a meaningful share of the cores. Two laptop slots add ~15% capacity, and the slower last tasks on the laptop can cancel that out.
  • Pooling a laptop on battery helps little, which is why agents pause on battery unless started with --lend-on-battery.
  • Longer tasks gain more, since the fixed cost of a run (~1s to start) and of each task (~0.1s) matters less.

Windows Smart App Control: when it is on, Windows may refuse to start unsigned programs that were just shipped to a device ("An Application Control policy has blocked this file"). Shipping scripts to an installed interpreter (--ship job.py -- python job.py) avoids this.

Assessing real use (pool report)

pool report reads every device's agent log (fetched from its agent, or --log FILE for a copy) and assesses each command that ran at least --min-jobs times:

  1. Speed by jobs at once: time per task and throughput at each number of jobs running together, next to what pool setup's measurement predicts.
  2. Consistency between runs: how far runs at the same load differ, which is the smallest change a benchmark can claim, and the same by agent version.
  3. Slot use: how much of each run the job slots were busy, and how much the slowest task lagged the median.
  4. Reliability: how jobs ended, agent restarts, and time spent taking no jobs.

On the desktop above, 4,051 poolbench tasks over three days ran at 5.56 tasks/s with 10 jobs at once and 6.71 with 15, within 0–3% of what pool setup predicted. Runs with 10 jobs at once differed by up to ±12%, so gains of a few percent, like the 1.05–1.10× rows above, can't be told apart from noise. Slots were busy 85% of a run (median).

Agents from 0.1.5 log microseconds and serve their log at /v1/log. Older logs have whole-second times, which pool report narrows using each job's duration; an older agent elsewhere can't serve its log, so copy it and use --log.

How placement works

Every agent samples its CPU load every 2 seconds and checks its power source. It pauses (refuses new jobs, with a reason) when:

  • the device is on battery, unless started with --lend-on-battery;
  • CPU use is at or above --busy-threshold (default 80%), whether from the owner's own work or from jobs already running;
  • free memory is low: an agent keeps a reserve for you (the larger of 1 GB and a tenth of the device's memory; there is no flag for it) and divides what is left among jobs, each assumed to need --job-memory MB until the agent has measured finished ones. The agent's job limit drops with free memory, and at zero it takes no jobs, even for --node;
  • all --max-jobs slots are taken (--max-jobs is a ceiling: CPU use by other programs and free memory can lower the limit further, live).

pool run without --node asks every agent for its status, ranks the ready ones by idle CPUs (then by free job slots), and sends the job to the best one. If that agent declines in the meantime, the next one is tried. When no device can take the job, the error lists why for each device. pool map stops the same way when every agent is paused, rather than waiting, so run it again once memory or CPU is free.

DEVICE                 OS             CPUS  IDLE  LOAD  JOBS  POWER        STATUS
desktop (this device)  windows/amd64  20    17.2  14%   0/10  AC           ready
laptop                 windows/amd64  16    13.4  16%   0/2   battery 65%  paused: on battery

Owner activity is judged from total CPU load, not keyboard or mouse input: an agent started over SSH or as a service can't see the desktop session's input. Jobs already running are not paused; they keep below-normal priority.

How it stays safe

An agent runs whatever an allowed device sends it, as the user the agent runs as. Deciding who is allowed is therefore the whole job, and it is done in layers:

  • The agent listens only on the device's Tailscale address, never on LAN or public interfaces (unless you pass --listen, which logs a warning).
  • Every request is identified with tailscale whois. A caller must be owned by the same Tailscale user and be named in --allow. Addresses outside Tailscale's ranges are refused before any lookup. Anything else gets 403. If the lookup fails or is slow (on a busy device), the request is refused with 503 instead, so your own devices try again rather than being told they aren't allowed; successful lookups are cached for a minute.
  • Web pages can't reach it. Requests carrying browser headers (Origin, cross-site Sec-Fetch-Site) are refused, jobs must be sent as JSON (which a page can't do without a preflight the agent never answers), and the Host header must name the agent, which stops DNS rebinding.
  • The client only sends jobs, files and --env values to devices you own, so a device shared into your tailnet can't pose as an idle agent to receive them.
  • Traffic is encrypted by Tailscale's WireGuard tunnel.
  • Jobs run at below-normal priority in a fresh scratch folder (deleted afterwards). Canceling (Ctrl+C) or --timeout kills the whole process tree.

SECURITY.md has the full threat model, the known limits, and how to report a vulnerability.

Secure deployment

An allowed device can run anything on an agent, so most of the work is keeping that set small and the agent's reach narrow.

  1. Verify what you install. Check the binary against SHA256SUMS and its build provenance (see Install):
    gh attestation verify pool-0.1.4-windows-amd64.exe --repo montjeffrey/compute-pool
  2. Point allow lists one way. Workers allow only the machines that submit jobs, never each other. A job counts as its own device to every other agent, so two agents that allow each other share whatever reaches either one.
  3. Lend machines where the agent's account has little to lose. The agent and its jobs run as the user the agent runs as (on Windows, whoever ran pool install) and can read that user's files, credentials and environment. Identity is per device, so don't run an agent, or name a device in --allow, where people you don't trust are logged on: their processes count as that device. On Windows, run pool install from an elevated shell logged on as the account the agent should run as, so the agent runs at startup, outside your desktop session, from that account's own folder.
  4. Replace your tailnet's default allow-all policy. A new tailnet lets every device reach every port. This ACL rule, also in the hardening checklist, limits port 7470 to your own devices:
    {"action": "accept", "src": ["autogroup:member"], "dst": ["autogroup:self:7470"]}
    If all your devices sign in as one user, that still opens 7470 on every one of them. To open it only on the workers, name devices by their tailnet IP and use grants, with a tests block so the policy editor refuses a change that breaks it:
    {
      "hosts": {
        "workstation": "100.64.0.1",
        "worker": "100.64.0.2"
      },
      "grants": [
        { "src": ["workstation"], "dst": ["worker"], "ip": ["tcp:7470"] }
      ],
      "tests": [
        { "src": "workstation", "accept": ["worker:7470"] },
        { "src": "worker", "deny": ["workstation:7470"] }
      ]
    }
    Replace the addresses with your devices' (tailscale ip -4), and keep any other grants you rely on: once allow-all is gone, anything not granted is blocked.
  5. Harden the tailnet itself. Turn on Tailnet Lock and device approval, leave key expiry on, and use MFA on the identity provider you sign in to Tailscale with. Whoever controls that account can add a device that passes every check.
  6. Pass secrets with --env, never as arguments, which are logged and shown on the dashboard. Jobs running at the same time can still read each other's environment.

Build

Requires Go 1.24 or newer and Tailscale signed in on every device. go.mod pins the go1.27.4 toolchain, which an older Go downloads on its own (GOTOOLCHAIN=auto, the default) unless it is already installed.

go build -trimpath -o bin/pool.exe ./cmd/pool
go test ./...

-trimpath keeps your local folder paths out of the binary; use it for anything you share. Cross-compile for other devices: $env:GOOS='linux'; go build -trimpath -o bin/pool-linux ./cmd/pool.

Set up a device

  1. Copy bin/pool.exe to the device (Go isn't needed there).
  2. Install the agent so it starts by itself (same flags as pool agent). On a laptop, lend only part of the CPU:
    pool install --allow desktop --max-jobs 2
  3. From another device: pool nodes should list it as ready.

If Windows Firewall blocks inbound connections on that device, allow them from the tailnet only, in an admin PowerShell:

New-NetFirewallRule -DisplayName "compute-pool agent" -Direction Inbound -Action Allow `
  -Program "$env:LOCALAPPDATA\compute-pool\bin\pool.exe" -Protocol TCP -LocalPort 7470 -RemoteAddress 100.64.0.0/10

Running in the background (pool install)

pool install copies pool.exe to %LOCALAPPDATA%\compute-pool\bin and registers a Task Scheduler task, "compute-pool agent", that runs it as you, never as SYSTEM, and stores no password:

  • From an elevated shell it runs at startup, before anyone logs in, with no window. Otherwise it runs at logon (a console window flashes once and hides).
  • A watchdog trigger relaunches the agent within a minute if it dies. Task Scheduler's own restart-on-failure only covers launch failures.
  • It keeps running on battery; the agent's own policy decides whether to lend CPU.
  • The log is %LOCALAPPDATA%\compute-pool\agent.log (rotated at 10 MB).
  • Re-run pool install to upgrade or change flags; pool uninstall removes it.

The agent waits for Tailscale instead of exiting when it isn't up yet (at boot, or after waking). It checks its own listener every 30 seconds and binds again if sleep or a network change broke it. On Windows, every job runs inside a job object tied to the agent, so if the agent is stopped or crashes, its jobs end too.

On Linux or macOS, run the pool agent command that pool setup prints from a systemd user service or a launchd agent; pool install is Windows-only so far. Keep its --log-file (~/.cache/compute-pool/agent.log on Linux, ~/Library/Caches/compute-pool/agent.log on macOS): pool report reads each device's log through its agent, and an agent logging to the console has none to share.

Application control (Windows)

Smart App Control has no exceptions, and pool's binaries aren't signed by a publicly trusted certificate, so it can block pool.exe, including an agent that already runs (it is blocked the next time it starts). scripts/appcontrol/ sets up your own allow list instead: sign your pool builds with a certificate only you hold, and deploy an App Control for Business policy that trusts it.

The policy doesn't add an exception to Smart App Control. It is built from Microsoft's Smart App Control template, so it keeps the same rules (Windows, reputable and publicly signed code) and adds your certificate, but Windows runs a program only if every enforced policy allows it. The documented path is to turn Smart App Control off and let the policy take its place. That is a Windows security setting, so it is your decision. Check whether your Windows version lets you turn Smart App Control back on later before you turn it off; older versions only allowed it after a reinstall. (One Windows 11 desktop, build 26300, also ran signed builds with the audit policy deployed and Smart App Control still on. Microsoft doesn't document that, so don't rely on it.)

  1. Certificate. Under a local account that runs nothing else (never the account the agent runs as), run pwsh scripts/appcontrol/new-cert.ps1 -Subject 'CN=Your Name' -RequireTpm. The key is made in the TPM, so it can't be copied off the device, but anything running as that account can sign with it. The certificate isn't added to trusted roots; only the policy trusts it. It prints the thumbprint and where it saved the public part (.cer).
  2. Policy. pwsh scripts/appcontrol/build-policy.ps1 -CertificatePath <.cer> -OutDir out writes compute-pool-policy.xml and an audit and an enforced .cip. It needs Windows Pro, Enterprise or Education; on Home, build it on another PC and copy the folder.
  3. Sign every build before you install it, from the signing account: pwsh scripts/appcontrol/sign.ps1 pool.exe -Thumbprint <from step 1> -ExpectedSha256 <hash> -TimestampServer http://timestamp.digicert.com. The hash is the one from SHA256SUMS or your own build. The script signs a private copy of the file, so the bytes it checked are the bytes it signs.
  4. Audit, from an elevated PowerShell 7, running copies of the scripts and of out\ that only administrators can change (an elevated script that anyone else can edit is theirs to run): scripts\appcontrol\deploy-policy.ps1 out\compute-pool-policy.xml -Mode audit. It copies the XML into a folder only administrators can write, builds the .cip from that copy and deploys it. The policy blocks nothing and logs what it would block. Run your signed pool.exe, and the programs your jobs use.
  5. Check: pwsh scripts/appcontrol/check-audit.ps1 -Since '<time printed in step 4>' lists App Control's decisions about matching files, with the signer Windows saw, and exits 1 if there are any. A signed pool.exe should have none; an unsigned one gets "would block (audit)".
  6. Enforce: scripts\appcontrol\deploy-policy.ps1 out\compute-pool-policy.xml -Mode enforce -Program pool.exe. It refuses unless this script deployed the same policy in audit mode and CiTool still lists it, -Program is signed by the very certificate the policy trusts, and nothing since the audit deployment shows the policy would block a program (any program, not only pool). No events can also mean a program never ran, so run them in step 4. It prints the command that removes the policy: deploy-policy.ps1 out\compute-pool-policy.xml -Remove.

Programs that jobs ship (--ship, poolbench) are checked too, and unsigned ones are blocked; sign them, or ship scripts to an installed interpreter. The policy is unsigned, so any administrator can remove it. A signed policy resists that, but a mistake with one can leave Windows unable to boot, so these scripts don't make one.

Dashboard (pool dashboard)

pool dashboard --open serves a live view of every device (status, load, idle CPUs, job slots, power) and of running and recent jobs. It refreshes every 2 seconds. By default it listens on 127.0.0.1:7471, reachable only from this device, and rejects requests whose Host header doesn't match, which blocks DNS-rebinding attacks. It refuses any other --listen address unless you pass --tailnet, because only --tailnet checks who is asking. --tailnet --allow phone,laptop serves it on the Tailscale address so those devices can open it, with the same identity check the agents use.

Command reference

Command Flags
pool setup Measures this device, recommends agent settings and, once you confirm, installs the agent with them (on Linux and macOS it prints the pool agent command instead). --json print the recommendation and change nothing · --yes apply without asking · --no-measure use the saved measurement or the specs · --measure-time 2s · --allow a,b · --keep N threads to keep free for you · --job-memory 512 MB per job
pool agent --allow a,b devices that may submit jobs (this device is always allowed) · --max-jobs N (default: half the logical CPUs) · --lend-on-battery · --busy-threshold 80 (0 = never pause) · --cache-mb 2048 · --job-memory 512 MB to assume each job needs until jobs have been measured · --port 7470 · --work-dir · --listen · --log-file FILE log to a file instead of stderr · --hide-console detach from the console window (the startup task uses it)
pool run [--node N] -- cmd args... --node auto (default) or a device name/IP · --shell run via cmd.exe or /bin/sh · --ship · --collect · --out pool-out · --timeout D (0 = no limit) · --env K=V (repeatable) · -v shows where the job went · --probe-timeout 1s · --port 7470
pool map (--range A..B | --items F | --inputs GLOB) -- cmd {} --ship · --collect · --out pool-out · --nodes a,b · --jobs N · --retries 2 · --speculate · --keep-order · --shell · --timeout · --env K=V · -v · --dry-run predict how the tasks would spread over the devices and run nothing · --task-time D with --dry-run, how long one task takes alone on this device · --probe-timeout 1s · --port 7470
pool nodes --timeout 1s · --port 7470
pool advise Compares every device: capacity, expected speedup, what to change. --json · --timeout 1s · --port 7470
pool report --log FILE (repeatable; logs read from files, measurements still asked of the agents) · --nodes a,b · --min-jobs 30 · --run-gap 2s · --json · --timeout 1s · --port 7470
pool dashboard --open · --listen 127.0.0.1:7471 (a non-loopback address needs --tailnet) · --tailnet · --allow a,b · --port 7470 (the agents' port, not the dashboard's)
pool install / pool uninstall pool install takes the same flags as pool agent (Windows)
pool version Prints the version and platform.

pool run exits with the remote program's exit code. The agent itself reports 127 (couldn't start), 124 (timed out) and 130 (canceled). If the program succeeded but its --collect results could not be brought back (an unsafe path, or a pattern that matched nothing), pool run exits 1 instead of 0, so a script doesn't carry on without them. Jobs see POOL_JOB_ID and POOL_NODE in their environment.

Development

Work happens on branches merged into main through pull requests. CI (.github/workflows/ci.yml) checks formatting, runs go vet, runs the tests on Windows, Linux and macOS (with the race detector on Linux), and runs govulncheck. scripts/bench.ps1 measures speedup on real devices.

To see the dashboard without any devices, serve it with made-up data (this is what the screenshot shows):

POOL_DEMO_DASHBOARD=127.0.0.1:7472 go test ./cmd/pool -run TestDemoDashboard -timeout 0

Releases: pushing a tag such as v0.2.0 runs .github/workflows/release.yml, which tests the tagged commit, builds binaries for Windows, Linux and macOS (x64 and Arm) with the version stamped in, and publishes them with checksums, build provenance attestations and the notes in docs/releases/<tag>.md. Tag releases with git tag -s so the tag is signed.

License

MIT.

Roadmap and test plan

Milestone Scope How it's verified
1. Remote run ✅ pool run on a named device, streaming, cancel/timeout, allow list Unit + end-to-end tests (go test ./...), live run over Tailscale
2. Scheduling ✅ Pick the least-loaded device automatically; laptops lend CPU only on AC power; pause when CPU is busy Unit tests for ranking, power and load parsing, and agent policy; live: laptop on battery paused itself, busy desktop → job auto-placed on laptop
3. Fan-out ✅ pool map across devices; ship and collect files; content cache; retry on device failure; backup copies of slow tasks Unit tests for scheduling, retries, backups, cache, path safety; live benchmark 1.31× (90% of the possible 1.45× for these two machines)
4. Hardening ✅ Runs in the background and restarts itself; survives sleep and network changes; jobs die with the agent; pool run moves past unreachable devices; dashboard Unit tests for job history, unreachable agents, log rotation, health check, dashboard state and Host check, task argument quoting; live on both devices: agents killed → both back within 56s; agent killed mid-job → job process gone

About

Share CPU between your own devices over Tailscale: run commands on the least-loaded device, fan out tasks, live dashboard

Topics

Resources

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages