Skip to content
Development preview · 2.0.0-SNAPSHOT

Performance and Scalability Guide

This guide covers ProcessEngine.execute and trigger under high request rates: which threads execute work, how to size queues and caches, and what to measure. For operational procedures and deployment configuration, see the Operations playbook and hot-deploy integration. Durable Worker and lease settings are covered by Durable configuration.

Separate runtime preparation, queue waiting, and Action execution before changing limits. For slow first calls, inspect source reads, preparation, and warm-up. For slow calls under sustained load, inspect queues, rejections, and downstream response times together. More threads or a larger cache may not help requests that are waiting for a database or remote service.

  • For frequent calls managed by CompileFlow Deploy, use a published ProcessRef.Version or ProcessRef.Alias. Direct ProcessDefinition execution is also suitable for production, but reads the source bytes before matching the exact runtime cache. Keep the source immutable and measure this cost at the expected request rate.
  • When a replay or job already knows its version, pass it explicitly to skip version selection.
  • Keep targeting policies free of remote I/O and large allocations. Use DEBUG for detailed per-request logs.

Share one long-lived, prewarmed engine across request threads. In both runtime modes, serial Actions without a timeout run on the caller’s thread. A gateway that selects only one branch also runs it directly. Actions with an explicit timeout use the action-timeout executor; gateways with several concurrent branches use the parallel executor. These executors do not cap the total number of untimed serial invocations. Concurrent gateways also use compileflow.engine.executor.parallel.coordinator-max-concurrency, which defaults to min(64, max(4, CPUs)) with zero pending groups. It bounds independent coordination groups, not branches within a group; nested groups share the outer group’s admission. An excess independent group is rejected before its branches run.

If a flow can block, call it from a host thread that permits blocking, not a network event loop.

Setting Default and sizing decision
Runtime mode COMPILED is the default. Compare preparation cost and steady-state latency with INTERPRETED under the intended workload.
Action timeout and retries No implicit engine timeout and one attempt. Set connection-acquisition and operation timeouts for HTTP, RPC, and JDBC calls.
Action-timeout concurrency max(4, CPUs) is a conservative helper limit. Size explicitly when timed actions are common, using their arrival rate, worker occupancy and downstream capacity.
Action-timeout pending 0: reject when no worker is available. A measured burst may justify a small explicit queue if its waiting time fits the request budget.
Runtime loading CPU-derived 1..2 concurrent loads, 4 pending, 10s caller wait. Prepare hot versions before admitting traffic; this wait is not a business-request deadline.
Events Asynchronous, 2 concurrent deliveries and 16 pending. Keep listener time and resource use bounded; delivery is best-effort. Measure drops and listener processing time.
Cancellation After requesting cancellation, wait up to 2s for timed actions or remaining parallel branches to stop. This extra wait can extend return latency beyond the action timeout.
Shutdown The caller waits up to 15s by default for engine shutdown. After that wait expires, cleanup continues once active work exits. Stop accepting new requests first and allow enough container grace time for work and cleanup to finish.

Find the corresponding properties under executor tuning, cache, and observability in the configuration reference.

Estimate the average number of occupied workers for timed Actions as:

timed attempts per second × mean worker occupancy in seconds

Include retries and work that continues after cancellation. For example, 1,000 attempts per second at 20ms each occupy 20 workers on average. If you try a limit of 32, check that the downstream service and CPU budget can support it. Neither 20 nor 32 guarantees a tail-latency target. If the required concurrency exceeds downstream capacity, reduce the accepted load, shorten service time, or add downstream capacity before raising the limit. Count all replicas and application pools that share the dependency.

A queue can absorb a burst; it cannot increase sustained throughput. With four saturated workers taking 50ms per task and 32 tasks waiting, the last queued task may wait about 400ms. Actual tail latency depends on arrival patterns and service-time variation. A zero-length queue can reject short scheduling bursts even when average capacity is sufficient.

Compare completed requests, rejection rate, and p99 latency under steady traffic, bursts, and sustained overload. Use a test that keeps offering work on its planned schedule when the server slows down. A test that waits for each response before sending more work can hide queue growth.

An imperative Spring transaction belongs to its thread. Design transaction handling explicitly for timed Actions and parallel branches. Propagating MDC does not carry the transaction or make a shared JDBC connection safe. The engine may report failure through ProcessResult; handle it inside the transactional method according to the application’s rollback rules, for example with orElseThrow().

Timeout and interruption do not undo external side effects. Before enabling retries, define which failures can be retried, make the operation idempotent, and set a total deadline. Turning retries on uses the policy defaults; it does not by itself make a transaction safe to repeat.

For the underlying concurrency and transaction semantics, see JDK queue policies and Spring transaction boundaries. The numerical examples above illustrate capacity calculations, not measured CompileFlow performance.

Concurrent requests for the same runtime share one in-flight load. Set compileflow.engine.executor.runtime-load.max-concurrency for active loads and compileflow.engine.executor.runtime-load.max-pending for loads waiting for a slot. Set pending to zero if a full loader should reject new work immediately.

Size compileflow.engine.max-resident-runtimes for hot exact versions, their ProcessCall dependencies, and versions that coexist during release or rollback. Its default of 2048 limits the number of cache-managed runtimes; it does not preallocate them or limit their total bytes.

Measure heap, metaspace, evictions, and reloads before changing the limit. Runtimes explicitly retained by runtime().load(...) or Deploy also consume capacity. If those retained runtimes fill every slot, another load fails rather than evicting them.

An active invocation keeps its own strong references. An unretained runtime can leave the cache while that invocation continues, so this setting does not bound every runtime object still reachable in the JVM. Avoid manually invalidating the cache during request processing.

Stagger traffic or warm up definitions to avoid many cold loads at once. Evicting an unretained runtime removes its cache entry and associated bindings, releasing the cache’s strong reference to it. The JVM can reclaim its class loader after active executions and application references are gone. Cache capacity is fixed when the engine is created. Use load tests and runtime metrics to size it and avoid frequent eviction, recompilation, and class loading.

The engine creates ProcessAliasTargetingContext only when the route has a candidate and names a policy. Keep routing keys and attributes in ProcessExecutionOptions, outside process variables. Policies should make bounded, deterministic decisions using local data; refresh external policy state asynchronously.

Declare a public no-argument ProcessAliasTargetingPolicy implementation with @ExtensionRealization and list it in the standard Extension service file. Configure a custom ProcessAliasRouteSource only if the application supplies its own serving routes.

Targeting policy declaration and route binding

Section titled “Targeting policy declaration and route binding”

See the targeting example in the extension guide for the implementation declaration and route binding. A declaration alone does not activate the policy; bind its name in the Alias route. An empty result uses the default deterministic selector, based on the routing key and configured weights.

compileflow.engine.observability.mdc-propagation-enabled defaults to false. Enable it when diagnostics need MDC, and include the propagation cost in load tests.

Use DEBUG for per-request overload logs and alert on executor rejection and event-drop counters. Measure request outcomes and latency where the application receives and completes requests. Best-effort asynchronous events cannot supply an exact count of completed requests.

Refresh immutable local routing snapshots asynchronously, so request-time route selection does not query the database. Cache immutable artifact reads only when measurements justify it. Use (namespace, code, version) as the key, and start with a small cache and an expiry of a few seconds. Any cached route must include the revision returned by the routing Store.

Prepare hot definitions with the startup warmup example, and finish startup preparation before admitting traffic.

warmUp prepares only the supplied definitions; it does not recursively prepare child processes. Include classpath child definitions explicitly. It caches runtimes locally without binding a Version, and warmed entries remain subject to eviction, so successful warmup does not guarantee a preparation-free first request. For Deploy-managed Version or Alias requests, first let Deploy finish installing the required versions and route. For locally managed Versions, load the root and every referenced child Version through the runtime manager before accepting traffic.