You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@doris.apache.org by GitBox <gi...@apache.org> on 2020/02/13 13:59:07 UTC

[GitHub] [incubator-doris] chaoyli edited a comment on issue #2895: Import new ThreadPool framework

chaoyli edited a comment on issue #2895: Import new ThreadPool framework
URL: https://github.com/apache/incubator-doris/pull/2895#issuecomment-585766207
 
 
   Thread pool design point:
   All tasks submitted directly to the thread pool enter a FIFO queue and are
   dispatched to a worker thread when one becomes free. Tasks may also be
   submitted via ThreadPoolTokens. The token wait() and shutdown() functions
   can then be used to block on logical groups of tasks.
   
   A token operates in one of two ExecutionModes, determined at token
   construction time:
   1. SERIAL: submitted tasks are run one at a time.
   2. CONCURRENT: submitted tasks may be run in parallel. This isn't unlike
       tasks submitted without a token, but the logical grouping that tokens
       impart can be useful when a pool is shared by many contexts (e.g. to
       safely shut down one context, to derive context-specific metrics, etc.).
   
   Tasks submitted without a token or via ExecutionMode::CONCURRENT tokens are
   processed in FIFO order. On the other hand, ExecutionMode::SERIAL tokens are
   processed in a round-robin fashion, one task at a time. This prevents them
   from starving one another. However, tokenless (and CONCURRENT token-based)
   tasks can starve SERIAL token-based tasks.
   
   ```
   Usage Example:
   std::unique_ptr<ThreadPool> thread_pool;
   CHECK_OK(
         ThreadPoolBuilder("my_pool")
               .set_min_threads(0)
               .set_max_threads(5)
               .set_max_queue_size(10)
               .set_idle_timeout(MonoDelta::FromMilliseconds(2000))
               .build(&thread_pool));
        thread_pool->submit(shared_ptr<Runnable>(new Task()));
   ```

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org