# GDS resources and cancellation

[Wiki](../README.md) / [Graph data science](README.md)

**On this page**

- [Memory estimates and cancellation](#memory-estimates-and-cancellation)
- [Storage compatibility and execution budgets](#storage-compatibility-and-execution-budgets)
- [Parallel execution and result memory](#parallel-execution-and-result-memory)

## Memory estimates and cancellation

Every algorithm supports `<algorithm>.<mode>.estimate(graphName, config)` for
stream/stats/write/mutate, using an existing projection. Estimate calls are
read-only and do not run the algorithm. They return `nodeCount`,
`relationshipCount`, `bytesMin`, `bytesMax`, `requiredMemory` and null heap
percentages (GDB has no JVM heap). Estimates model the full projection even
when labels/types filter the computation, include materialised output and
allowance for projection cloning, and are deliberately conservative.
They are planning estimates, not measured allocator peaks or reserved memory;
algorithm-specific data constraints are still validated when executing.

All algorithms accept two GDB extensions: `memoryLimitBytes` rejects a run when
its estimated `bytesMax` exceeds the supplied budget; `timeoutMillis` cancels
computation at cooperative checkpoints. Zero, the default, disables each
control. These are not process-wide memory limits or strict wall-clock
termination deadlines. Concurrent jobs can each consume their own budget.
The timeout covers algorithm setup/computation and result publication, not
query prefixes or downstream Cypher clauses.

```cypher
CALL gds.fastRP.stream.estimate('people', {embeddingDimension:128})
YIELD bytesMin, bytesMax, requiredMemory;
CALL gds.fastRP.write('people', {
  embeddingDimension:128, randomSeed:42, writeProperty:'embedding',
  memoryLimitBytes:536870912, timeoutMillis:30000
});
```

No remote cancellation endpoint or named-job catalogue is provided; remote
queries can use `timeoutMillis`. Interrupted computations return errors;
write/mutate changes use normal statement rollback and publish no partial
algorithm result. Cooperative interruption can lag during large individual
vector operations, sorting or allocation.

Unfiltered, unweighted natural adjacency is cached once per immutable
projection and shared by subsequent algorithms and property-only mutations.
Filtered, reoriented and weighted views are rebuilt. Relationship mutation
invalidates the cache; rolled-back catalogue changes restore the old snapshot.

## Storage compatibility and execution budgets

GDS execution contexts, projections and worker state remain transient. The new
algorithms write existing scalar/list property types through normal constraints,
indexes, undo and WAL. Written properties survive restart, while projections must be recreated.

Worker contexts inherit the parent job's cancellation generation and deadline;
workers do not register as additional jobs. Explicit FastRP/PageRank buffer
reservations share a per-job memory counter. Planning estimates still gate all
algorithms. Neither mechanism is a process-wide memory ceiling: worker stacks,
allocator overhead, live database state, other queries and transaction/WAL
buffers are not fully charged by that counter. Cancellation remains cooperative.

## Parallel execution and result memory

FastRP and PageRank accept `concurrency` in `1..64`, default **1**. The effective
worker count is capped by available logical CPUs; small workloads use a direct
serial path even when more threads are requested. Workers are scoped to each
computation and never mutate live data. Floating-point contributions retain
their serial order within each row: seeded FastRP and PageRank results are
identical across worker counts in the same build. Parallelism competes with
other queries for CPU/memory bandwidth; it is opt-in. KNN accepts only
`concurrency:1`; other algorithms remain serial.

`stats`, `mutate` and `write` skip unused stream-row construction. Dijkstra
summary modes also skip path reconstruction and use tree distances directly.
The public `.stream` result is still materialised, including all returned paths.

## Related articles

[Graph projections and catalogue](projections.md) · [GDS algorithms and execution modes](algorithms.md) · [Graph data science](README.md)
