Performance Tuning
This page documents the operator-tunable knobs that affect Fleans throughput. For provider selection and full configuration reference, see Streaming and Persistence.
Stream provider sizing
Section titled “Stream provider sizing”Two sizing knobs on KafkaStreamingOptions:
| Knob | Default | What it controls |
|---|---|---|
Fleans:Streaming:Kafka:QueueCount | 8 | Orleans-side pulling-agent count — one consumer per queue, each subscribed to one single-partition topic. Matches Redis:TotalQueueCount semantics. Same value on every host; see the rehash caveat before changing it on a live cluster. |
Fleans:Streaming:Kafka:ReplicationFactor | 3 | Per-topic broker replication, capped at the live broker count (1 on a single broker). |
Production deployments: SASL / TLS brokers are configured as in Kafka security; see Production-readiness gaps for what the adapter still leaves to you. Poison records can be routed to a dead-letter topic — see Streaming.
Two knobs:
| Knob | Default | What it controls |
|---|---|---|
Fleans:Streaming:Redis:TotalQueueCount | 8 | Orleans-side queue count for the Redis stream provider. Each silo’s pulling agents spread across this many queues. FIFO is guaranteed per stream; cross-instance traffic distributes across TotalQueueCount Redis queues. Same value on every host. Helm: streaming.redis.totalQueueCount. |
Fleans:Streaming:Redis:MaxStreamLength | 100000 | Entries kept per Redis stream. Redis trims by length whether or not an entry was delivered, so size it above your largest expected backlog — see Delivery window and Redis trimming. |
Redis streaming (the default provider) uses a third-party Orleans stream-provider package that ships in the Fleans images.
AzureQueue
Section titled “AzureQueue”QueueNames list length (default 8 entries). Tune by populating Fleans__Streaming__AzureQueue__QueueNames__0..N environment variables.
Persistence query pagination
Section titled “Persistence query pagination”User-task list query
Section titled “User-task list query”The user-task list query is paginated via Sieve and applies the assignee/candidate-group filter at the SQL level on PostgreSQL (via FromSqlInterpolated + JSON-text LIKE). The PostgreSQL path (PostgresUserTaskFilterStrategy) avoids materializing the full table. SQLite users with similar-scale workloads should switch to PostgreSQL (Persistence__Provider=Postgres plus a ConnectionStrings__fleans connection string — see Persistence).
Event store reads
Section titled “Event store reads”EfCoreEventStore.ReadEventsAsync honors a configurable row limit. The default is MaxEventsPerLoad = 1000 (from FleansPersistenceOptions).
| Knob | Default | What it controls |
|---|---|---|
Persistence:MaxEventsPerLoad | 1000 | Maximum number of events loaded per grain-activation replay. A load past this limit throws, so the instance cannot activate until the limit is raised. Reading an instance’s full history is not limited: it reads the event log this many events at a time. The error says: “Increase Persistence:MaxEventsPerLoad if this is intentional.” |
Persistence:SnapshotInterval | 500 | A workflow instance snapshot (its state, without finished activities it no longer needs) is written every this many events. Activation loads the snapshot and replays at most about this many events after it. Lower it for faster reactivation, raise it to write less. |
For typical workflow volumes, the defaults are appropriate. MaxEventsPerLoad must be greater than SnapshotInterval; the silo refuses to start otherwise. A failed snapshot write (log EventId 1131) is retried for about 8.5 minutes (1145 per failed retry, 1143 on success, 1144 when the retries give up); after that the instance’s next activation writes it. If snapshot writes keep failing, the event history after the last snapshot keeps growing. Fix the cause before it passes MaxEventsPerLoad, or raise the limit.
Long-running instances
Section titled “Long-running instances”When a snapshot is written, the instance drops the finished activities it no longer needs from its state. A long loop at the top level of a process therefore keeps a small, constant snapshot, however long it runs. The event log keeps every event, and the full history is rebuilt from it when you ask for it.
Measured with a task and a gateway in a loop, almost no variables, on a development machine with in-memory SQLite:
| Steps | Events | Snapshot size | Reading the details of the running instance |
|---|---|---|---|
| 13 | 111 | 304 bytes | about 1 ms |
| 125 | 1,007 | 304 bytes | about 3 ms |
| 1,000 | 8,007 | 304 bytes | 25–40 ms |
| 2,250 | 18,007 | 304 bytes | 65–140 ms |
An instance that has written no snapshot yet, about the first 500 events, answers details from memory. After that, each details read of a running instance replays its event log, so a client that polls GET /instances/{id}/state on a very long instance pays that cost on every call. The admin UI’s instance page reads once per load or Refresh. Once the instance finishes, its details come from the read model, and reading them costs the same however long it ran.
History still builds up while a scope stays open, because the engine reads it when the scope closes:
- A loop inside a sub-process or transaction keeps its entries until that sub-process ends.
- A loop on a branch of a parallel fork keeps its entries until the join.
Compensation records and transaction outcomes are also kept for the life of the instance.
If yours loops thousands of times inside a scope, you can:
- Move the repeated work into a Call Activity, because each child instance has its own state.
- Raise
Persistence:SnapshotIntervalto write less often. It must stay belowPersistence:MaxEventsPerLoad.
Related
Section titled “Related”- Streaming — provider selection and config matrix.
- Persistence — SQLite vs Postgres trade-offs.
docs/conventions/streaming.md— contributor-side tuning guide.