sofa-jraft icon indicating copy to clipboard operation
sofa-jraft copied to clipboard

RFC: custom thread pool

Open killme2008 opened this issue 3 years ago • 6 comments

RPC: custom thread pool

Right now, jraft use global thread pool to execute callback closures or send log entries as below:

  • https://github.com/sofastack/sofa-jraft/blob/4f9f779988243bbe80c5a18b920807c320b67f3c/jraft-core/src/main/java/com/alipay/sofa/jraft/rpc/impl/core/DefaultRaftClientService.java#L63
  • https://github.com/sofastack/sofa-jraft/blob/4f9f779988243bbe80c5a18b920807c320b67f3c/jraft-core/src/main/java/com/alipay/sofa/jraft/util/Utils.java#L108

The users can't change the thread pool behaviour by themself except setting enviroment variable such as -Djraft.closure.threadpool.size.max=xxx etc. And when using multi raft group in one java process, the global thread pool can't provide any isolations between groups and make the service not robust enough.

So i think we can provide a way to let users custom thread pool for every raft group just like StorageOptionsFactory. If the users doesn't provide a custom thread pool, we use the global one as before.

  • Main goals:
    • Let user custom closure execution and sending entries thread pools
    • Provides isolation between raft groups in one java process.

killme2008 avatar Jun 23 '22 02:06 killme2008

hi, i want to perform this task

shihuili1218 avatar Jun 23 '22 03:06 shihuili1218

@farawayliu Sure! Feel free to try it.

killme2008 avatar Jun 23 '22 03:06 killme2008

i have finished send AppendEntries, i have a question, why shutdown programs can't share CLOSURE_EXECUTOR?
https://github.com/sofastack/sofa-jraft/pull/855

shihuili1218 avatar Jun 24 '22 02:06 shihuili1218

i have finished send AppendEntries, i have a question, why shutdown programs can't share CLOSURE_EXECUTOR? #855

hah, i misunderstood the meaning of CLOSURE_EXECUTOR

shihuili1218 avatar Jun 24 '22 03:06 shihuili1218

@killme2008 hi, i have completed this task, please review. https://github.com/sofastack/sofa-jraft/pull/855

shihuili1218 avatar Jun 27 '22 01:06 shihuili1218

@farawayliu Cool, i will review it today.

killme2008 avatar Jun 27 '22 03:06 killme2008