dubbo threading model

If the logic of event processing can be completed quickly and no new IO requests are initiated, such as just recording an identifier in memory, processing directly on the IO thread is faster because thread pool scheduling is reduced.

However, if the event processing logic is slow, or new IO requests need to be initiated, such as querying the database, it must be dispatched to the thread pool, otherwise the IO thread will be blocked and other requests will not be received.

If an IO thread is used to process an event, and a new IO request is initiated during the event processing, for example, a login request is initiated in a connection event, an exception of "may cause a deadlock" will be reported, but it will not be deadlocked.

dubbo-protocol

Therefore, it is necessary to deal with different scenarios through a combination of different dispatch strategies and different thread pool configurations:

<dubbo:protocol name="dubbo" dispatcher="all" threadpool="fixed" threads="100" />

Dispatcher

  • allAll messages are dispatched to the thread pool, including requests, responses, connect events, disconnect events, heartbeats, etc.
  • Corresponding class: com.alibaba.dubbo.remoting.transport.dispatcher.all.AllChannelHandler
  • directAll messages are not dispatched to the thread pool, and all are executed directly on the IO thread.
  • Corresponding class: com.alibaba.dubbo.remoting.transport.dispatcher.direct.DirectDispatcher
  • messageOnly the request response message is dispatched to the thread pool, other connection disconnection events, heartbeat and other messages are directly executed on the IO thread.
  • Corresponding class: com.alibaba.dubbo.remoting.transport.dispatcher.message.MessageOnlyDispatcher
  • executionOnly the request message is dispatched to the thread pool, without the response, response and other connection disconnection events, heartbeat and other messages, which are executed directly on the IO thread.
  • Corresponding class: com.alibaba.dubbo.remoting.transport.dispatcher.execution.ExecutionDispatcher
  • connectionOn the IO thread, the connection disconnection events are put into the queue, executed one by one in an orderly manner, and other messages are dispatched to the thread pool.
  • Corresponding class: com.alibaba.dubbo.remoting.transport.dispatcher.connection.ConnectionOrderedDispatcher

ThreadPool

  • fixedFixed-size thread pool. Threads are created at startup, not closed, and held all the time. (default)
  • cachedThe cached thread pool is automatically deleted after one minute of idle time, and rebuilt when needed.
  • limitedScalable thread pool, but the number of threads in the pool will only grow and not shrink. The purpose of only growing and not shrinking is to avoid performance problems caused by sudden large traffic when shrinking.
  • eagerCreate a Workerthread pool first. When the number of tasks is greater than corePoolSizebut less than maximumPoolSizethat, priority is created Workerto process tasks. When the number of tasks is greater than maximumPoolSizethat, put the task into the blocking queue. Thrown when the blocking queue is full RejectedExecutionException. (Compared to cached: throwing an exception directly when cachedthe number of tasks exceeds maximumPoolSizeinstead of putting tasks into a blocking queue)

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324541829&siteId=291194637