Repository navigation
fix(engine): use long affinity masks and limit workers to 64 - #3317
Merged
Merged
Conversation
Tuning computed the default affinity mask as (1 << count) - 1 in int arithmetic, so a worker count of 32, 64 or 96 produced mask 0 (startup failed with "affinity mask must specify at least one bit") and counts 33..63 produced a truncated mask. The mask is now a long: count bits for counts below 64 and all 64 bits otherwise, matching the single long the tuning file stores per binding. EngineManager limited a binding's worker bits with ~(1 << bitindex), the same int shift applied to a long mask, which cleared the wrong bits from bit 31 upward. It now shifts a long, via a testable limitAffinity. Fixes #3304 Co-Authored-By: Claude Sonnet 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01SiHVoWjcXhPwwz4JasA4BL
Worker indexes address bits of a single long (the tuning affinity mask) and index fixed 64-entry stream dispatch tables, so an engine with more than 64 workers cannot run: with 96 workers, workers 64 and above fail with ArrayIndexOutOfBoundsException when streams cross workers. The default worker count is now min(availableProcessors, 64) and an explicit count above 64 is rejected with a clear message at startup. Co-Authored-By: Claude Sonnet 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01SiHVoWjcXhPwwz4JasA4BL
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Tuningcomputed the default affinity mask as(1 << count) - 1inintarithmetic. Java masks the shift distance to 5 bits, so 32, 64 and 96 workers gave mask 0 andEngineWorker.resolveAffinitythrewaffinity mask must specify at least one bit; 33..63 workers gave a truncated mask that silently pinned default-affinity bindings to fewer workers.Changes:
Tuning: the available mask is along:count >= Long.SIZE ? -1L : (1L << count) - 1L. Explicit masks using bits 31, 32 and 63 round-trip.EngineManager: the same int-shift idiom inaffinity &= ~(1 << bitindex)cleared the wrong bits from bit 31 upward; extractedlimitAffinityand shifted along. It was the only other instance in the engine (DefaultBudgetDebitorand the watcher loop already use1L <<).EngineConfiguration: worker indexes address bits of one long and index fixed 64-entry stream dispatch tables (EngineWorker.initDispatcher), so more than 64 workers cannot run (with-w 96, workers 64+ fail withArrayIndexOutOfBoundsExceptionwhen streams cross workers). The default is nowmin(availableProcessors, 64)and an explicit count above 64 is rejected at startup withzilla.engine.workers=N exceeds the maximum of 64 workers.Fixes #3304
Tests first (failed before, pass after)
Before the fix, on unfixed code:
TuningTest: default mask 0 for 32 workers, mask 1 for 65 workers; explicit high-bit masks failed the assertion.EngineManagerTest.shouldLimitAffinityToLowestBits: expected bit 63, was 0.EngineAffinityIT.shouldPreferLocalWorkerForBindingWithDefaultAffinity(engine now runs 32 workers):IllegalStateException: affinity mask must specify at least one bit: test.net0 0.EngineConfigurationTest.shouldRejectWorkersAboveLongSize: nothing was thrown.After the fix:
mvn clean verify -pl runtime/enginepasses (347 unit tests, 268 ITs, checkstyle and jacoco check included).Note: in one earlier full
verifyrun on a 4-core sandbox, the JVM crashed (SIGSEGV inEventReader.readon an exporter thread, preceded by anArrayIndexOutOfBoundsException: Index 19 out of bounds for length 10inNamespaceTask) duringEngineAffinityITwith its 32 workers. It did not reproduce in 3 isolated runs or in the next full run, but a 32-worker engine under load may be flaky; reviewers may want CI to confirm.Real start
Unmodified
examples/mqtt.kafka.proxy/etc/zilla.yaml,KAFKA_BOOTSTRAP_SERVER=localhost:9092(Kafka unreachable), launched from a classpath built from this branch, not the Docker image:start -e -wdevelopENGINE_STARTEDaffinity mask must specify at least one bit, exit 1ENGINE_STARTEDENGINE_STARTEDaffinity mask must specify at least one bit, exit 1exceeds the maximum of 64 workers, exit 1exceeds the maximum of 64 workers, exit 1affinity mask must specify at least one bit, exit 1ENGINE_STARTEDNot delivered
Generated by Claude Code