knot.pool
The knot.pool library manages space pools. A pool keeps a desired count of identical spaces (created from the same template) running and ready, so the server can hand out method, HTTP, and TCP traffic across healthy members. Pools are useful for scaling stateless services and for method backends that need more capacity than a single space.
Execution Environment
| Environment | Behaviour |
|---|---|
Embedded (MCP tool execution, event sinks, remote/space scripts, knot run-script) |
Available; authenticated automatically via the Go-provided knot.apiclient transport. |
| Health check scripts | Not available. |
| External (standalone scripts) | Python implementation; configure knot.apiclient first (or set the KNOT_* environment variables). |
Functions
| Function | Description |
|---|---|
list() |
List visible pools with current utilization |
get(name) |
Get pool details and utilization by name or ID |
create(name, template_name, startup_script_id='', desired_count=1, active=True) |
Create a pool and return its ID |
update(name, desired_count=None, active=None) |
Update the pool’s desired count or active state |
delete(name) |
Delete a stopped pool and all its spaces |
set_size(name, desired_count) |
Set the pool’s desired space count |
start(name) |
Start a stopped pool (starts all members, creates any missing) |
stop(name) |
Stop a running pool (stops all members without deleting them) |
Usage
import knot.pool as pool
# List pools
for p in pool.list():
print(f"{p['name']}: {p['alive_members']}/{p['desired_count']} alive")
# Create a pool of 3 spaces from a template
pool_id = pool.create(
"api-pool",
"my-service",
desired_count=3,
active=True,
)
# Scale the pool up
pool.set_size("api-pool", 5)
# Stop and later start the pool
pool.stop("api-pool")
pool.start("api-pool")
# Delete the pool (must be stopped first)
pool.delete("api-pool")Pool Properties
get() and list() return pool dicts containing:
id- Pool IDname- Pool nametemplate_id- Template the pool’s spaces are created fromstartup_script_id- Startup script applied to membersdesired_count- Target number of spacesalive_members- Number of currently healthy membersactive- Whether the pool is active (members are started as they are created)utilization- Aggregate utilization across members:combined_rps- Total requests per second (method + HTTP + TCP)method_rps- Method requests per secondhttp_rps- HTTP requests per secondtcp_rps- TCP requests per secondmethod_inflight- In-flight method requestsavg_cpu_percent- Average CPU usage across membersavg_memory_percent- Average memory usage across members
members- List of member space dicts (see below)
Member Properties
Each member in members contains:
id- Space IDname- Space namestate- Member statecombined_rps,method_rps,http_rps,tcp_rps- Per-member request ratesmethod_inflight- In-flight method requestscpu_percent- CPU usagememory_percent- Memory usagehealthy- Whether the member is healthyis_pending- Whether the member is pending creationis_deleting- Whether the member is being deletedis_deployed- Whether the member is deployed (running)
Lifecycle Notes
create()accepts a template name (resolved to an ID internally). The template, startup script, and pool name are immutable after creation; onlydesired_countandactiveare mutable viaupdate().delete()requires the pool to be stopped first.set_size(),start(), andstop()are asynchronous: the server’s sweep loop creates, drains, or deletes member spaces to reach the desired state.