[asterisk-dev] [Code Review] Threadpool Support

David Lee reviewboard at asterisk.org
Wed Jan 16 14:44:05 CST 2013


-----------------------------------------------------------
This is an automatically generated e-mail. To reply, visit:
https://reviewboard.asterisk.org/r/2242/#review7670
-----------------------------------------------------------


Excellent. Aside from the need for a max_size attribute on the threadpool, everything can be addressed by adding or fixing comments.


/trunk/include/asterisk/taskprocessor.h
<https://reviewboard.asterisk.org/r/2242/#comment14612>

    I would also add a note here that the taskprocessor has no associated thread, and it's up to the given listener to dispatch work (call ast_taskprocessor_execute) however it sees fit.



/trunk/include/asterisk/taskprocessor.h
<https://reviewboard.asterisk.org/r/2242/#comment14607>

    There is no alloc() callback any more.



/trunk/include/asterisk/threadpool.h
<https://reviewboard.asterisk.org/r/2242/#comment14610>

    2013



/trunk/include/asterisk/threadpool.h
<https://reviewboard.asterisk.org/r/2242/#comment14608>

    typo



/trunk/include/asterisk/threadpool.h
<https://reviewboard.asterisk.org/r/2242/#comment14620>

    In addition to the auto_increment, you should have a max_size. Otherwise, you will grow without bounds.



/trunk/include/asterisk/threadpool.h
<https://reviewboard.asterisk.org/r/2242/#comment14609>

    Can multiple threadpools have the same name? What happens if they do?



/trunk/include/asterisk/threadpool.h
<https://reviewboard.asterisk.org/r/2242/#comment14611>

    What's the significance of the int returned by the task?



/trunk/main/threadpool.c
<https://reviewboard.asterisk.org/r/2242/#comment14614>

    2013



/trunk/main/threadpool.c
<https://reviewboard.asterisk.org/r/2242/#comment14613>

    Add note that this should be prime.



/trunk/main/threadpool.c
<https://reviewboard.asterisk.org/r/2242/#comment14615>

    typo - missing end quote for "live"



/trunk/tests/test_taskprocessor.c
<https://reviewboard.asterisk.org/r/2242/#comment14616>

    2013



/trunk/tests/test_threadpool.c
<https://reviewboard.asterisk.org/r/2242/#comment14617>

    2013



/trunk/tests/test_threadpool.c
<https://reviewboard.asterisk.org/r/2242/#comment14618>

    You should make threadpool_shutdown NULL safe. That would make it useful for RAII_VAR's.



/trunk/tests/test_threadpool.c
<https://reviewboard.asterisk.org/r/2242/#comment14619>

    It's probably worth a note that timing-related tests such as these can be brittle on heavily loaded systems. For example, a build machine running several builds in parallel may fail this test, simply because a thread was starved and didn't receive its update in a timely fashion.



/trunk/tests/test_threadpool.c
<https://reviewboard.asterisk.org/r/2242/#comment14621>

    typo - leftover


- David


On Jan. 15, 2013, 3:28 p.m., Mark Michelson wrote:
> 
> -----------------------------------------------------------
> This is an automatically generated e-mail. To reply, visit:
> https://reviewboard.asterisk.org/r/2242/
> -----------------------------------------------------------
> 
> (Updated Jan. 15, 2013, 3:28 p.m.)
> 
> 
> Review request for Asterisk Developers.
> 
> 
> Summary
> -------
> 
> This review adds a generic threadpool for Asterisk.
> 
> The threadpool implementation here is very similar to the one implemented in Asterisk SCF. Since this is implemented in C, the "is a" semantics offered by C++ are not available, so that had to be worked around.
> 
> The threadpool, when created, creates a taskprocessor. The threadpool itself exists as the private data on a taskprocessor listener. In this way, the threadpool can react to changes on the taskprocessor by informing its threadpool listener.
> 
> The threadpool informs its listeners of various changes:
> - When a task gets pushed into the threadpool
> - When the threadpool's task list has become empty
> - When the state of the threadpool's threads has changed, such as when an active thread goes idle or an idle thread is destroyed.
> 
> The threadpool listener can react to these changes as it sees fit. This allows for different policies to be adopted by different modules.
> 
> The offers some options for automatic behavior for common forms of operation. At allocation, an idle timeout can be specified in order to allow for idle threads to automatically get removed from the threadpool once they have been idle for a certain amount of time. Also, an automatic increment can be specified if the threadpool has tasks added to it and no idle threads are available to handle the task. With these, it may be possible for listeners only to intervene in certain situations. More options can possibly be added if they are not too policy-specific.
> 
> This set of changes is dependent on the set of taskprocessor changes introduced in https://reviewboard.asterisk.org/r/2200 . Since these changes were developed in the same branch as the taskprocessor changes, it means that all the taskprocessor changes are also included in this review. While there are minor changes in the taskprocessor code here as compared to the code in review 2200, they are very minor changes, and so close scrutiny of the taskprocessor changes is not as important as the threadpool code itself.
> 
> 
> This addresses bug ASTERISK-20691.
>     https://issues.asterisk.org/jira/browse/ASTERISK-20691
> 
> 
> Diffs
> -----
> 
>   /trunk/main/taskprocessor.c 379127 
>   /trunk/include/asterisk/threadpool.h PRE-CREATION 
>   /trunk/include/asterisk/taskprocessor.h 379127 
>   /trunk/main/threadpool.c PRE-CREATION 
>   /trunk/tests/test_taskprocessor.c PRE-CREATION 
>   /trunk/tests/test_threadpool.c PRE-CREATION 
> 
> Diff: https://reviewboard.asterisk.org/r/2242/diff
> 
> 
> Testing
> -------
> 
> A suite of unit tests have been added to ensure that the threadpool works as expected. They all pass.
> 
> 
> Thanks,
> 
> Mark
> 
>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-dev/attachments/20130116/de02f681/attachment-0001.htm>


More information about the asterisk-dev mailing list