0
votes

In our pipeline, when we log, we need to put data in the current thread's MDC so that our log parsing service picks up the log correctly.

I'm under the impression that Netty will pin a connection/channel to a single thread, but that threads are used for multiple connections.

My question is, do threads in Netty complete work for one connection before being pinned to another, or are they pinned to multiple connections and skip around from a connection's handlers at random.

Example Interleaved Handling Timeline:

Connection1.Handler1.onRead()
Connection2.Handler2.onWrite()
Connection1.Handler1.onRead()
Connection1.Handler2.onRead()

Example Non-Interleaved Handling Timeline:

Connection1.Handler1.onRead()
Connection1.Handler2.onRead()
Connection1.Handler3.onRead()
Connection2.Handler1.onRead()
Connection2.Handler2.onRead()
Connection2.Handler3.onRead()

Which of these two timelines accurately portrays Netty's mode of operation?

If the former is correct, then does anyone have a suggestion on how best to make sure thread context is maintained per connection?

1

1 Answers

1
votes

There is no guarantee that all the events for one Channel (which is a connection in your example) are processed before processing of events for another Channel is started.