Skip to content

Commit f1c7de0

Browse files
committed
Documentation : Rest and Transport Action Threading Model
1 parent e659a25 commit f1c7de0

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

docs/internal/GeneralArchitectureGuide.md

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,6 @@ were left unconsumed.
4242
6. The response is written to the `RestChannel`, either as a [single payload][RestToXContentListener] or a
4343
[stream of chunks][RestChunkedToXContentListener].
4444

45-
A Netty channel eventLoop thread executes step 1 to 3. The [RestChannelConsumer] delegates execution to a task manager thread, which processes
46-
the request and eventually returns control to the original event loop thread to write the response back to the Netty channel.
47-
4845
### Request interceptor
4946

5047
The [RestController] accepts a [RestInterceptor] that can intercept [RestRequest]s and add additional pre-handling. A single
@@ -104,6 +101,16 @@ are coordinated.
104101
> does not hold, in those cases you can locate the transport action for a REST action by looking at the `NodeClient` invocation in the
105102
> `Rest*Action`'s `prepareRequest` implementation, it should specify the `ActionType` being invoked which can then be used to locate
106103
> the `Transport*Action` class that handles it.
104+
>
105+
> A netty [EventLoop] thread handles the initial steps of a Rest*Action request lifecycle such as decoding, validation and routing.
106+
> Upon entry into the "transport layer", [NodeClient] delegates the remaining processing to its [TaskManager] thread. The [TaskManager]
107+
> thread eventually returns control to the original [EventLoop] thread to write the response back to the Netty channel.
108+
>
109+
> [TransportAction] can also be initiated through peer-to-peer communication between nodes. In such cases, the [InboundHandler]
110+
> locates the appropriate [TransportAction] by consulting the [NamedRegistry], then invokes its handleExecution() method. When a [TransportAction]
111+
> is registered, it can specify an executor to control how the action is run. One option is the DIRECT_EXECUTOR_SERVICE, which executes the
112+
> action on the calling thread. However, this should be used with caution—it's only appropriate when the action is lightweight.
113+
> Otherwise, it risks blocking the peer-to-peer I/O thread, potentially degrading responsiveness and causing the node to become unresponsive.
107114
108115
### Action registration
109116
Elasticsearch contains many [TransportAction]s, configured statically in [ActionModule#setupActions]. [ActionPlugin]s can
@@ -182,6 +189,10 @@ capabilities.
182189
[TransportService]:https://github.com/elastic/elasticsearch/blob/v9.0.1/server/src/main/java/org/elasticsearch/transport/TransportService.java
183190
[TransportSingleShardAction]:https://github.com/elastic/elasticsearch/blob/v9.0.1/server/src/main/java/org/elasticsearch/action/support/single/shard/TransportSingleShardAction.java
184191
[Transport]:https://github.com/elastic/elasticsearch/blob/v9.0.1/server/src/main/java/org/elasticsearch/transport/Transport.java
192+
[EventLoop]:https://github.com/netty/netty/blob/4.2/transport/src/main/java/io/netty/channel/EventLoop.java
193+
[TaskManager]:https://github.com/elastic/elasticsearch/blob/main/server/src/main/java/org/elasticsearch/tasks/TaskManager.java
194+
[InboundHandler]:https://github.com/elastic/elasticsearch/blob/main/server/src/main/java/org/elasticsearch/transport/InboundHandler.java
195+
[NamedRegistry]:https://github.com/elastic/elasticsearch/blob/main/server/src/main/java/org/elasticsearch/common/NamedRegistry.java
185196

186197
## Serializations
187198

0 commit comments

Comments
 (0)