[prev in list] [next in list] [prev in thread] [next in thread] 

List:       asterisk-dev
Subject:    Re: [asterisk-dev] [Code Review] 4193: Stasis: allow for subscriptions to dictate message delivery o
From:       "Matt Jordan" <reviewboard () asterisk ! org>
Date:       2014-11-24 18:07:53
Message-ID: 20141124180753.24568.27213 () sonic ! digium ! api
[Download RAW message or body]

[Attachment #2 (multipart/alternative)]


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

(Updated Nov. 24, 2014, 12:07 p.m.)


Review request for Asterisk Developers.


Changes
-------

Addressed Josh's finding and added configuration options. This is partly a backport \
of the existing stasis.conf from Asterisk 13 (minus the actual 'settings'), and \
partly a pull-in of the original stasis.conf configuration parsing provided on \
https://reviewboard.asterisk.org/r/2881.

Addressed Mark's finding by removing the unneeded option and by making the message \
routers in app_queue use the threadpool as well.


Bugs: ASTERISK-24533
    https://issues.asterisk.org/jira/browse/ASTERISK-24533


Repository: Asterisk


Description
-------

Note: don't be fooled by the size of this review. Most of the changes are small and \
are in stasis.c/stasis_message_router.c.

Rob (and CDR on the asterisk-users list, although he never followed up when we asked \
for more information) discovered that we were creating two additional threads per SIP \
peer in chan_sip. This actually would occur for a large variety of 'endpoints' in \
Asterisk, regardless of the channel driver. The two threads were stasis \
subscriptions, specifically for MWI and for endpoints detecting the destruction of \
related channels.

Stasis subscriptions currently get a dedicated thread. In contrast, prior to r400178 \
(see review https://reviewboard.asterisk.org/r/2881/), the subscriptions shared a \
thread pool. It was discovered that for a low subscription count with high message \
throughput, the threadpool was not as performant as simply having a dedicated thread \
per subscriber.

Since then, our subscription pattern has changed slightly. While we still have plenty \
of subscriptions that would follow the model just described (AMI, CDRs, CEL, etc.) - \
                there are plenty that also fall into the following two categories:
* Large number of subscriptions, specifically those tied to endpoints/peers.
* Low number of messages. Some subscriptions exist specifically to coordinate a \
single message - the subscription is created, a message is published, the delivery is \
synchronized, and the subscription is destroyed. In both of the latter two cases, \
creating a dedicated thread is wasteful (and in the case of a large number of \
peers/endpoints, harmful).

This patch adds the ability of a subscriber to Stasis to choose whether or not their \
messages are dispatched on a dedicated thread or on a threadpool. The threadpool is \
currently hard coded in this patch; if configuration is necessary, we could re-add \
the configuration options in r2881. Pre-mature optimization and all that led me to \
simply go with a simpler model for now.

Note that the approach taken here was to add additional API calls rather than modify \
existing ones. If we'd rather the thread dispatch model be dictated by a parameter, \
the new API calls can be removed in trunk and the old API calls modified \
appropriately.


Diffs (updated)
-----

  /team/mjordan/12-threadpool/tests/test_stasis.c 428600 
  /team/mjordan/12-threadpool/res/res_xmpp.c 428600 
  /team/mjordan/12-threadpool/res/res_stasis_device_state.c 428600 
  /team/mjordan/12-threadpool/res/res_pjsip_refer.c 428600 
  /team/mjordan/12-threadpool/res/res_pjsip_pubsub.c 428600 
  /team/mjordan/12-threadpool/res/res_pjsip_mwi.c 428600 
  /team/mjordan/12-threadpool/res/res_jabber.c 428600 
  /team/mjordan/12-threadpool/res/parking/parking_bridge_features.c 428600 
  /team/mjordan/12-threadpool/res/parking/parking_applications.c 428600 
  /team/mjordan/12-threadpool/main/stasis_message_router.c 428600 
  /team/mjordan/12-threadpool/main/stasis_channels.c 428600 
  /team/mjordan/12-threadpool/main/stasis_cache.c 428600 
  /team/mjordan/12-threadpool/main/stasis.c 428600 
  /team/mjordan/12-threadpool/main/endpoints.c 428600 
  /team/mjordan/12-threadpool/include/asterisk/stasis_message_router.h 428600 
  /team/mjordan/12-threadpool/include/asterisk/stasis_internal.h 428600 
  /team/mjordan/12-threadpool/include/asterisk/stasis.h 428600 
  /team/mjordan/12-threadpool/configs/stasis.conf.sample PRE-CREATION 
  /team/mjordan/12-threadpool/channels/sig_pri.c 428600 
  /team/mjordan/12-threadpool/channels/chan_skinny.c 428600 
  /team/mjordan/12-threadpool/channels/chan_sip.c 428600 
  /team/mjordan/12-threadpool/channels/chan_mgcp.c 428600 
  /team/mjordan/12-threadpool/channels/chan_iax2.c 428600 
  /team/mjordan/12-threadpool/channels/chan_dahdi.c 428600 
  /team/mjordan/12-threadpool/apps/app_queue.c 428600 

Diff: https://reviewboard.asterisk.org/r/4193/diff/


Testing (updated)
-------

New unit tests were written to cover the new subscription types. This tests receiving \
messages sent using the threadpool.

The MWI tests and channel driver tests in the Test Suite were run and passed.

For the new configuration options:
* Tested under valgrind; confirmed no memory leaks with/without the config file
* Tested that the lack of stasis.conf did not preclude loading and that the defaults \
                were applied
* Tested with an invalid config file; defaults still applied
* Tested with a valid config file; custom values applied


Thanks,

Matt Jordan


[Attachment #5 (text/html)]

<html>
 <body>
  <div style="font-family: Verdana, Arial, Helvetica, Sans-Serif;">
   <table bgcolor="#f9f3c9" width="100%" cellpadding="8" style="border: 1px #c9c399 \
solid;">  <tr>
     <td>
      This is an automatically generated e-mail. To reply, visit:
      <a href="https://reviewboard.asterisk.org/r/4193/">https://reviewboard.asterisk.org/r/4193/</a>
  </td>
    </tr>
   </table>
   <br />




<table bgcolor="#fefadf" width="100%" cellspacing="0" cellpadding="8" \
style="background-image: \
url('https://reviewboard.asterisk.org/static/rb/images/review_request_box_top_bg.ab6f3b1072c9.png'); \
background-position: left top; background-repeat: repeat-x; border: 1px black \
solid;">  <tr>
  <td>

<div>Review request for Asterisk Developers.</div>
<div>By Matt Jordan.</div>


<p style="color: grey;"><i>Updated Nov. 24, 2014, 12:07 p.m.</i></p>



<h1 style="color: #575012; font-size: 10pt; margin-top: 1.5em;">Changes</h1>
<table width="100%" bgcolor="#ffffff" cellspacing="0" cellpadding="10" style="border: \
1px solid #b8b5a0">  <tr>
  <td>
   <pre style="margin: 0; padding: 0; white-space: pre-wrap; white-space: \
-moz-pre-wrap; white-space: -pre-wrap; white-space: -o-pre-wrap; word-wrap: \
break-word;">Addressed Josh&#39;s finding and added configuration options. This is \
partly a backport of the existing stasis.conf from Asterisk 13 (minus the actual \
&#39;settings&#39;), and partly a pull-in of the original stasis.conf configuration \
parsing provided on https://reviewboard.asterisk.org/r/2881.

Addressed Mark&#39;s finding by removing the unneeded option and by making the \
message routers in app_queue use the threadpool as well.</pre>  </td>
 </tr>
</table>





<div style="margin-top: 1.5em;">
 <b style="color: #575012; font-size: 10pt; margin-top: 1.5em;">Bugs: </b>


 <a href="https://issues.asterisk.org/jira/browse/ASTERISK-24533">ASTERISK-24533</a>


</div>



<div style="margin-top: 1.5em;">
 <b style="color: #575012; font-size: 10pt;">Repository: </b>
Asterisk
</div>


<h1 style="color: #575012; font-size: 10pt; margin-top: 1.5em;">Description </h1>
 <table width="100%" bgcolor="#ffffff" cellspacing="0" cellpadding="10" \
style="border: 1px solid #b8b5a0">  <tr>
  <td>
   <pre style="margin: 0; padding: 0; white-space: pre-wrap; white-space: \
-moz-pre-wrap; white-space: -pre-wrap; white-space: -o-pre-wrap; word-wrap: \
break-word;">Note: don&#39;t be fooled by the size of this review. Most of the \
changes are small and are in stasis.c/stasis_message_router.c.

Rob (and CDR on the asterisk-users list, although he never followed up when we asked \
for more information) discovered that we were creating two additional threads per SIP \
peer in chan_sip. This actually would occur for a large variety of \
&#39;endpoints&#39; in Asterisk, regardless of the channel driver. The two threads \
were stasis subscriptions, specifically for MWI and for endpoints detecting the \
destruction of related channels.

Stasis subscriptions currently get a dedicated thread. In contrast, prior to r400178 \
(see review https://reviewboard.asterisk.org/r/2881/), the subscriptions shared a \
thread pool. It was discovered that for a low subscription count with high message \
throughput, the threadpool was not as performant as simply having a dedicated thread \
per subscriber.

Since then, our subscription pattern has changed slightly. While we still have plenty \
of subscriptions that would follow the model just described (AMI, CDRs, CEL, etc.) - \
                there are plenty that also fall into the following two categories:
* Large number of subscriptions, specifically those tied to endpoints/peers.
* Low number of messages. Some subscriptions exist specifically to coordinate a \
single message - the subscription is created, a message is published, the delivery is \
synchronized, and the subscription is destroyed. In both of the latter two cases, \
creating a dedicated thread is wasteful (and in the case of a large number of \
peers/endpoints, harmful).

This patch adds the ability of a subscriber to Stasis to choose whether or not their \
messages are dispatched on a dedicated thread or on a threadpool. The threadpool is \
currently hard coded in this patch; if configuration is necessary, we could re-add \
the configuration options in r2881. Pre-mature optimization and all that led me to \
simply go with a simpler model for now.

Note that the approach taken here was to add additional API calls rather than modify \
existing ones. If we&#39;d rather the thread dispatch model be dictated by a \
parameter, the new API calls can be removed in trunk and the old API calls modified \
appropriately.</pre>  </td>
 </tr>
</table>


<h1 style="color: #575012; font-size: 10pt; margin-top: 1.5em;">Testing \
(updated)</h1> <table width="100%" bgcolor="#ffffff" cellspacing="0" cellpadding="10" \
style="border: 1px solid #b8b5a0">  <tr>
  <td>
   <pre style="margin: 0; padding: 0; white-space: pre-wrap; white-space: \
-moz-pre-wrap; white-space: -pre-wrap; white-space: -o-pre-wrap; word-wrap: \
break-word;">New unit tests were written to cover the new subscription types. This \
tests receiving messages sent using the threadpool.

The MWI tests and channel driver tests in the Test Suite were run and passed.

For the new configuration options:
* Tested under valgrind; confirmed no memory leaks with/without the config file
* Tested that the lack of stasis.conf did not preclude loading and that the defaults \
                were applied
* Tested with an invalid config file; defaults still applied
* Tested with a valid config file; custom values applied</pre>
  </td>
 </tr>
</table>


<h1 style="color: #575012; font-size: 10pt; margin-top: 1.5em;">Diffs</b> \
(updated)</h1> <ul style="margin-left: 3em; padding-left: 0;">

 <li>/team/mjordan/12-threadpool/tests/test_stasis.c <span style="color: \
grey">(428600)</span></li>

 <li>/team/mjordan/12-threadpool/res/res_xmpp.c <span style="color: \
grey">(428600)</span></li>

 <li>/team/mjordan/12-threadpool/res/res_stasis_device_state.c <span style="color: \
grey">(428600)</span></li>

 <li>/team/mjordan/12-threadpool/res/res_pjsip_refer.c <span style="color: \
grey">(428600)</span></li>

 <li>/team/mjordan/12-threadpool/res/res_pjsip_pubsub.c <span style="color: \
grey">(428600)</span></li>

 <li>/team/mjordan/12-threadpool/res/res_pjsip_mwi.c <span style="color: \
grey">(428600)</span></li>

 <li>/team/mjordan/12-threadpool/res/res_jabber.c <span style="color: \
grey">(428600)</span></li>

 <li>/team/mjordan/12-threadpool/res/parking/parking_bridge_features.c <span \
style="color: grey">(428600)</span></li>

 <li>/team/mjordan/12-threadpool/res/parking/parking_applications.c <span \
style="color: grey">(428600)</span></li>

 <li>/team/mjordan/12-threadpool/main/stasis_message_router.c <span style="color: \
grey">(428600)</span></li>

 <li>/team/mjordan/12-threadpool/main/stasis_channels.c <span style="color: \
grey">(428600)</span></li>

 <li>/team/mjordan/12-threadpool/main/stasis_cache.c <span style="color: \
grey">(428600)</span></li>

 <li>/team/mjordan/12-threadpool/main/stasis.c <span style="color: \
grey">(428600)</span></li>

 <li>/team/mjordan/12-threadpool/main/endpoints.c <span style="color: \
grey">(428600)</span></li>

 <li>/team/mjordan/12-threadpool/include/asterisk/stasis_message_router.h <span \
style="color: grey">(428600)</span></li>

 <li>/team/mjordan/12-threadpool/include/asterisk/stasis_internal.h <span \
style="color: grey">(428600)</span></li>

 <li>/team/mjordan/12-threadpool/include/asterisk/stasis.h <span style="color: \
grey">(428600)</span></li>

 <li>/team/mjordan/12-threadpool/configs/stasis.conf.sample <span style="color: \
grey">(PRE-CREATION)</span></li>

 <li>/team/mjordan/12-threadpool/channels/sig_pri.c <span style="color: \
grey">(428600)</span></li>

 <li>/team/mjordan/12-threadpool/channels/chan_skinny.c <span style="color: \
grey">(428600)</span></li>

 <li>/team/mjordan/12-threadpool/channels/chan_sip.c <span style="color: \
grey">(428600)</span></li>

 <li>/team/mjordan/12-threadpool/channels/chan_mgcp.c <span style="color: \
grey">(428600)</span></li>

 <li>/team/mjordan/12-threadpool/channels/chan_iax2.c <span style="color: \
grey">(428600)</span></li>

 <li>/team/mjordan/12-threadpool/channels/chan_dahdi.c <span style="color: \
grey">(428600)</span></li>

 <li>/team/mjordan/12-threadpool/apps/app_queue.c <span style="color: \
grey">(428600)</span></li>

</ul>

<p><a href="https://reviewboard.asterisk.org/r/4193/diff/" style="margin-left: \
3em;">View Diff</a></p>







  </td>
 </tr>
</table>




  </div>
 </body>
</html>



-- 
_____________________________________________________________________
-- Bandwidth and Colocation Provided by http://www.api-digital.com --

asterisk-dev mailing list
To UNSUBSCRIBE or update options visit:
   http://lists.digium.com/mailman/listinfo/asterisk-dev

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic