davsclaus opened a new pull request, #29878: URL: https://github.com/apache/camel/pull/29878
## What CAMEL-26938, a sub-task of CAMEL-26935 (make the Camel CLI faster for AI agents). A `camel cmd` action, a runtime tool of the MCP server, `camel ask` and the TUI talk to a running integration through files in `~/.camel`. Both sides polled every 100 millis, and the client slept 100 millis before it first looked, so an action took about 110 millis even when the integration answered at once. - `ActionClient` looks for the answer after 5 millis, and then waits a tenth of the time it has waited so far, from 5 to 100 millis. An answer is read at most about a tenth later than it is there, and an action that takes long, such as a message sent to a slow route, is not looked for 200 times a second. - The connector looks for action files every 20 millis (was 100). Listing `~/.camel` costs far more than looking at its modification time, so between two status updates it only lists the directory when that time has changed, which it does when a file is added to it. The status update every second lists it anyway. - A file added within the same tick of the file system clock as the change before it leaves the time as it was (Windows ticks about every 16 millis, and `File.lastModified` is in millis), so a time is only remembered once it is 20 millis old: until then the next poll lists again. - An action file that cannot be read yet, such as one a Camel CLI before 4.21 writes in place in the shared `<pid>-action.json`, makes the next poll list again, as finishing it in place leaves the directory as it is. - `ActionBaseCommand.getJsonObject` (the route structure and topology of source files) looks before it sleeps, as the dump is usually there already. - `ActionClient.executeText` takes an answer that is not JSON, of an integration of an earlier Camel version, once it has not changed for 100 millis. It was: the same at two polls, which were 100 millis apart. - The unused `RuntimeHelper.POLL_INTERVAL_MS` is removed. The protocol is the same, so a new client is faster with an older integration, and the other way round. ## Measured macOS (M4 Pro), JDK 25. The client and the connector run in one warm JVM, with a home of their own, and send 100 actions with a pause of 37-86 millis between them (both runs shown): | client | connector | median | p90 | |---|---|---|---| | main | main | 112 ms | 114 ms | | this PR | this PR | 23 / 26 ms | 33 / 34 ms | | main | this PR | 111 ms | 114 ms | | this PR | main | 41 ms | 62 ms | CPU of an idle file transport over 15 seconds, the JVM included, with 67 other files in `.camel`, on a machine with other load: | other integrations writing their status every second | main | this PR | |---|---|---| | 0 | 1.56 / 1.57 % | 1.55 / 1.24 % | | 5 | 1.53 / 1.46 % | 2.09 / 2.19 % | The status of another integration is moved in place every second, which changes the directory too, so with more integrations the poll lists more often. Listing at every poll, every 20 millis, would cost about 3 % of a core in a separate benchmark. ## Tests - `FileCliConnectorTransportTest`: between two status updates the directory is listed less than 15 times a second (the poll runs about 50 times), and a half-written action makes every poll list it again (10 times within a second). Each test fails without its change. - `ActionClientTest`: how long the client waits between two looks, and an answer that is not JSON is taken once it has not changed for 100 millis. - The tests of `camel-cli-connector` and `camel-jbang-core` pass. _Claude Code on behalf of Claus Ibsen (davsclaus)_ 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_012nJsFsjqqFiwroeHRWaKbS -- 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]
