ammachado opened a new pull request, #28760:
URL: https://github.com/apache/camel/pull/28760

   # Description
   
   [CAMEL-26393](https://issues.apache.org/jira/browse/CAMEL-26393), tier 1 
item #1, ideas (a), of 
[CAMEL-25132](https://issues.apache.org/jira/browse/CAMEL-25132).
   
   With the default statistics level, `ManagedPerformanceCounter` runs for 
every node of every exchange, for the processor, route and context counters. 
Each pass updates several shared atomics, so throughput did not grow with the 
number of threads.
   
   Changes:
   
   1. **`StatisticCounter` uses a `LongAdder`**, so updates are striped and the 
value is summed on read.
   2. **`StatisticValue` and `StatisticDelta` write only when the value 
changes.** `StatisticDelta` still moves `lastValue` to the current value, so 
two equal updates report a delta of 0.
   3. **The mean is computed on read.** Keeping it per exchange would sum two 
`LongAdder`s on every exchange. It stays `-1` until an exchange completes and 
after a reset. The `meanProcessingTime` field is removed.
   4. **`LastExchangeCompletedExchangeId` is updated at most once per 
millisecond,** because `getExchangeId()` generates the id of an exchange that 
has none yet. This is a behavior change, documented in the 4.24 upgrade guide. 
`LastExchangeFailureExchangeId` stays exact.
   5. **The inflight getters are clamped at 0,** because the sum of a 
`LongAdder` can see a decrement before its increment.
   
   Deviation from the ticket: inflight is **not** derived as started - 
completed - failed. `reset()` clears completed and failed but deliberately not 
inflight, so deriving it would need extra counters that are never reset. A 
single `LongAdder` keeps the same meaning.
   
   Not in this PR: the per-node `StopWatch` and double `nanoTime` (idea c), the 
striped design (idea b), and the default statistics level (idea d).
   
   ## Measurements
   
   10-processor route through a `ProducerTemplate`, default JMX statistics, 
Linux arm64 container with 9 CPUs on a Podman VM, JDK 21, ParallelGC, 10 s 
warm-up and 10 s measure, a new JVM per run, before and after alternating. 
Average of 2 rounds, ops/s:
   
   | threads | before | after | change |
   |---|---|---|---|
   | 1 | 554k | 539k | about -3% |
   | 4 | 555k | 967k | 1.7x |
   | 8 | 553k | 1.33M | 2.4x |
   
   Each run confirmed that the route MBean counted every sent exchange. The 
harness is not the ticket's and the machine differs, so these numbers are not 
directly comparable with the ticket's 1.87M. Two rounds is a small sample. The 
single-thread cost appeared in both rounds. The extra memory of contended 
`LongAdder` cells was not measured.
   
   ## Tests
   
   New `ManagedPerformanceCounterTest`. These two failed before the change:
   - 50000 exchanges do not generate an id each (before: 50000 ids);
   - inflight does not go below 0 (before: -1).
   
   The others protect behavior that the change could break: the mean of `-1` 
without data, a delta of 0 for equal times, inflight surviving a reset, the id 
being updated in a later millisecond and cleared by a reset, an exact failure 
id, and exact counts with 8 concurrent threads.
   
   `ManagedStatisticsTest` now accepts the id of any of its five exchanges, as 
they can complete within the same millisecond.
   
   Verified: the `camel-management` test suite, 586 tests, 0 failures, 1 
skipped (`DynamicRouterConvertBodyToIssueManualTest`, a manual test). Other 
modules were not run; `camel-console` reads these getters but is not changed.
   
   # Target
   
   - [x] I checked that the commit is targeting the correct branch (Camel 4 
uses the `main` branch)
   
   # Tracking
   - [x] If this is a large change, bug fix, or code improvement, I checked 
there is a [JIRA issue](https://issues.apache.org/jira/browse/CAMEL) filed for 
the change (usually before you start working on it).
   
   # Apache Camel coding standards and style
   
   - [x] I checked that each commit in the pull request has a meaningful 
subject line and body.
   
   - [ ] I have run `mvn clean install -DskipTests` locally from root folder 
and I have committed all auto-generated changes.
   
   Not run from the root folder: `mvn install` was run in 
`core/camel-management` only, and `git status` was clean afterwards.
   
   # AI-assisted contributions
   
   - [x] If this PR includes AI-generated code, commits have proper 
co-authorship attribution (e.g., `Co-authored-by` trailers) and the PR 
description identifies the AI tool used.
   
   🤖 Generated with [Claude Code](https://claude.com/claude-code) on behalf of 
Adriano Machado (@ammachado)
   
   _This was generated by an AI agent and may contain inaccuracies. Please 
verify before relying on it._


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to