<div dir="ltr">Hi Daniel,<div><br></div><div>Thanks for your responses.  This discussion has been very useful.  </div><div><br></div><div>Our code is along the lines that you suggest in which we are using some database ops prior to the dialog calls to gather if the user is call limited and if so, the provisioned users "max calls allowed" per billing party.  Then, we check their current active profile size:</div><div>get_profile_size("prepaid", "$avp(s:billing_party)", "$avp(profile_size)");<br></div><div><br></div><div>If they have available calls, we are using a dialog profile called "prepaid" with a limit set per user (aka billing_party):   <br></div><div>set_dlg_profile("prepaid", "$avp(s:billing_party)");<br></div><div><br></div><div>So, it sounds like from what you describe, I will set my hash size to be a few times larger than my forecasted profile size to keep matching operations to a minimal.  And since dialogs timeout anyway if they are not cleared by a proper BYE, a memory leak of uncleared dialogs is highly unlikely.<br></div><div><br></div><div>Thank you for your assistance.  Hopefully we will meet again soon, and I can share how the solution turns out.</div><div>Mark Blackford</div><div>Digium Cloud Services</div><div><br></div><div><br></div><div><br></div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Dec 4, 2017 at 2:56 PM, Daniel-Constantin Mierla <span dir="ltr"><<a href="mailto:miconda@gmail.com" target="_blank">miconda@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
  
    
  
  <div text="#000000" bgcolor="#FFFFFF">
    <p>The hash_size has no relevance on how many dialogs can be
      handled. It is only related to the lookup performance. So even
      with hash_size=1 you can have same number of dialogs as with
      hash_size=4096 or higher.</p>
    <p>The difference is that with hash_size=1, all the dialogs are in a
      single linked list, so if you have 2000 active dialog, you may
      have the worse case that it requires 2000 matching operations to
      lookup a specific dialog.</p>
    <p>If the hash_size is 2048, the at 2000 active calls and a fair
      distribution, then looking up a specific dialog will be done in a
      single matching operation. Fair distribution cannot be ensure, but
      it is quite good, so typically the difference between the list
      loaded slot and most loaded slot is not that high. I expect that
      worse case situation won't require more that 5 matching operations
      on a hash table with 2048 slots when having 2000 active calls.<br>
    </p>
    To put limit on active calls, the simplest solution is to do a test
    on $stat(active_dialogs)>=limit then reject the initial invite:<br>
    <br>
      -
<a class="m_-5367002523642773269moz-txt-link-freetext" href="https://www.kamailio.org/docs/modules/stable/modules/dialog.html#idp34022668" target="_blank">https://www.kamailio.org/docs/<wbr>modules/stable/modules/dialog.<wbr>html#idp34022668</a><br>
    <br>
    You may need statistics module to get the $stat(...) var:<br>
    <br>
      -
    <a class="m_-5367002523642773269moz-txt-link-freetext" href="https://www.kamailio.org/docs/modules/stable/modules/statistics.html" target="_blank">https://www.kamailio.org/docs/<wbr>modules/stable/modules/<wbr>statistics.html</a><br>
    <br>
    The alternative would be to set all active calls in a single dialog
    profile.<br>
    <br>
      -
<a class="m_-5367002523642773269moz-txt-link-freetext" href="https://www.kamailio.org/docs/modules/stable/modules/dialog.html#dialog.f.set_dlg_profile" target="_blank">https://www.kamailio.org/docs/<wbr>modules/stable/modules/dialog.<wbr>html#dialog.f.set_dlg_profile</a><br>
    <br>
    Then get the size of the profile and test it against the limit.<br>
    <br>
    This is more suitable if you want to set limits per user, a.s.o.,
    because you can group on profiles with a specific key (e.g.,
    username).<br>
    <br>
    Cheers,<br>
    Daniel<div><div class="h5"><br>
    <br>
    <div class="m_-5367002523642773269moz-cite-prefix">On 04.12.17 19:28, Mark Blackford
      wrote:<br>
    </div>
    <blockquote type="cite">
      <div dir="ltr">Thank you for your response!
        <div><br>
        </div>
        <div>I am currently replacing the call_control module used with
          CDRTool Prepaid with the dialog module using hash tables. The
          speed and stability are tremendously better!<br>
          <div><br>
          </div>
          <div>My concern is two-fold:<br>
          </div>
          <div>1) I do not want calls to be blocked because I set the
            hash table size too small.  </div>
          <div>2) I do not want any memory usage problems that could
            cause kamailio stability issues.</div>
          <div><br>
          </div>
          <div>
            <div>My understanding, or at least how I want to use the
              "hash_size" modparam, is that hash_size gives dialog a set
              memory space (aka slots and buckets) to store the dialogs
              being tracked.  This is great since I "think" I will have
              constant memory consumption that will be a fixed amount
              and never "grow".  However, I wanted to get a rough idea
              of how many dialogs (customer calls) I could track per
              kamailio instance to properly choose the hash size.</div>
          </div>
          <div><br>
          </div>
          <div>I thought it would be easy to set the value to something
            very small in the lab and just run up the number of calls
            until kamailio hits an upper limit and fails to create any
            more dialogs. </div>
          <div>modparam("dialog", "hash_size", 32)<br>
          </div>
          <div><br>
          </div>
          <div>However, I am able to create almost 2000 dialogs no
            matter what size I choose.  After, reading the information
            in the link about hash tables and your response, I see how a
            larger table with more "hashing" increases lookup
            performance, but I still do not see how the total number of
            dialogs that the module tracks can be set so that the
            kamailio memory usage is protected.  I still look at the
            hash_size as the key here and that there should be a
            relationship, perhaps rough at best, to the maximum number
            of dialogs supported in the table.</div>
          <div><br>
          </div>
          <div>Thanks so much for your time,</div>
        </div>
        <div>Mark Blackord</div>
        <div>Digium Cloud Services</div>
      </div>
      <div class="gmail_extra"><br>
        <div class="gmail_quote">On Sat, Dec 2, 2017 at 2:50 AM,
          Daniel-Constantin Mierla <span dir="ltr"><<a href="mailto:miconda@gmail.com" target="_blank">miconda@gmail.com</a>></span>
          wrote:<br>
          <blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
            <div text="#000000" bgcolor="#FFFFFF">
              <p>Hello,</p>
              <p>hash size does not set any limitation to the number of
                dialogs (active calls), it has impact on searching the
                dialogs, so if you have a lot of active calls,
                increasing the hash size might improve performances.
                Effectively the hash size is used to compute the number
                of slots (aka buckets) the hash table is going to have,
                see more technical details about hash tables at:</p>
              <p>  - <a class="m_-5367002523642773269m_-8301622289956510289moz-txt-link-freetext" href="https://en.wikipedia.org/wiki/Hash_table" target="_blank">https://en.wikipedia.org/wiki/<wbr>Hash_table</a><br>
              </p>
              <p>Can you elaborate on your statement:</p>
              <span>
                <p>> but even setting the hash size to a very tiny
                  number does stop me from creating hundreds of dialogs</p>
              </span>
              <p>Do you mean you are not able to create as many dialogs
                as you want?</p>
              <p>Cheers,<br>
                Daniel<br>
              </p>
              <div>
                <div class="m_-5367002523642773269h5"> <br>
                  <div class="m_-5367002523642773269m_-8301622289956510289moz-cite-prefix">On
                    01.12.17 19:54, Mark Blackford wrote:<br>
                  </div>
                </div>
              </div>
              <blockquote type="cite">
                <div>
                  <div class="m_-5367002523642773269h5">
                    <div dir="ltr">Hello,
                      <div><br>
                      </div>
                      <div>I am trying to properly size the use of the
                        Dialog Module hash for our implementation using:</div>
                      <div><br>
                      </div>
                      <div>modparam("dialog", "hash_size", <number
                        that is power of two>)</div>
                      <div><br>
                      </div>
                      <div>However, in my testing, I have been unable to
                        figure out the relationship between the hash
                        size and a number of dialogs I need to support. 
                        I think the hash size is specifying a memory
                        block in kB, but even setting the hash size to a
                        very tiny number does stop me from creating
                        hundreds of dialogs.</div>
                      <div><br>
                      </div>
                      <div>Is there a way to determine a relationship
                        between the hash size and a rough number of
                        dialogs that would be expected?</div>
                      <div><br>
                      </div>
                      <div>An example of a a dialog looks like this from
                        kamctl:</div>
                      <div><br>
                      </div>
                      <div>
                        <div>[root@kamailio01 ~]# kamctl dialog show</div>
                        <div>dialog memory records</div>
                        <div>dialog::  hash=22:70</div>
                        <div><span style="white-space:pre-wrap">  </span>state::
                          4</div>
                        <div><span style="white-space:pre-wrap">  </span>ref_count::
                          2</div>
                        <div><span style="white-space:pre-wrap">  </span>timestart::
                          1512151205</div>
                        <div><span style="white-space:pre-wrap">  </span>timeout::
                          36083666</div>
                        <div><span style="white-space:pre-wrap">  </span>callid::
                          <a href="mailto:0gQAAC8WAAACBAAALxYAAClws2wyL8GE%2BCSgRY7HIhmg9ZUIISZad46ntOPng3iPIcLaxzLFaytRTI7M0Bzz0g--@10.155.8.40" target="_blank">0gQAAC8WAAACBAAALxYAAClws2wyL8<wbr>GE+CSgRY7HIhmg9ZUIISZad46ntOPn<wbr>g3iPIcLaxzLFaytRTI7M0Bzz0g--@<wbr>10.155.8.40</a></div>
                        <div><span style="white-space:pre-wrap">  </span>from_uri::
                          <a href="mailto:sip%3Ab53667d44239457fbc94fc2f4c4e25a6@sip.dcs-staging.net" target="_blank">sip:b53667d44239457fbc94fc2f4c<wbr>4e25a6@sip.dcs-staging.net</a></div>
                        <div><span style="white-space:pre-wrap">  </span>from_tag::
                          10.155.8.40+1+689d7e5e+8fcf481<wbr>a</div>
                        <div><span style="white-space:pre-wrap">  </span>caller_contact::
                          <a class="m_-5367002523642773269m_-8301622289956510289moz-txt-link-freetext">sip:43f0ae1480846185e8803f21e9<wbr>f2b721@10.155.8.40:5060;<wbr>transport=udp</a></div>
                        <div><span style="white-space:pre-wrap">  </span>caller_cseq::
                          24115</div>
                        <div><span style="white-space:pre-wrap">  </span>caller_route_set:: </div>
                        <div><span style="white-space:pre-wrap">  </span>caller_bind_addr::
                          udp:<a href="http://10.155.8.11:5060" target="_blank">10.155.8.11:5060</a></div>
                        <div><span style="white-space:pre-wrap">  </span>callee_bind_addr::
                          udp:<a href="http://10.155.8.11:5060" target="_blank">10.155.8.11:5060</a></div>
                        <div><span style="white-space:pre-wrap">  </span>to_uri::
                          <a href="mailto:sip%3A2052773090@sip.dcs-staging.net" target="_blank">sip:2052773090@sip.dcs-staging<wbr>.net</a></div>
                        <div><span style="white-space:pre-wrap">  </span>to_tag::
                          sip+1+bdcd0004+2038f37c</div>
                        <div><span style="white-space:pre-wrap">  </span>callee_contact::
                          <a class="m_-5367002523642773269m_-8301622289956510289moz-txt-link-freetext">sip:ca2013e84f10348a1cc825c125<wbr>62bde7@10.155.8.40:5060;<wbr>transport=udp</a></div>
                        <div><span style="white-space:pre-wrap">  </span>callee_cseq::
                          0</div>
                        <div><span style="white-space:pre-wrap">  </span>callee_route_set:: </div>
                      </div>
                      <div><br>
                      </div>
                      <div> </div>
                      <div><br>
                      </div>
                      <div>
                        <div>Thanks!</div>
                        -- <br>
                        <div class="m_-5367002523642773269m_-8301622289956510289gmail-m_2252680259820329684gmail_signature">
                          <div dir="ltr">Mark Blackford
                            <div>Digium Cloud Services</div>
                            <div>678.230.8769</div>
                            <div><br>
                            </div>
                          </div>
                        </div>
                      </div>
                    </div>
                    <br>
                    <fieldset class="m_-5367002523642773269m_-8301622289956510289mimeAttachmentHeader"></fieldset>
                    <br>
                  </div>
                </div>
                <pre>______________________________<wbr>_________________
Kamailio (SER) - Users Mailing List
<a class="m_-5367002523642773269m_-8301622289956510289moz-txt-link-abbreviated" href="mailto:sr-users@lists.kamailio.org" target="_blank">sr-users@lists.kamailio.org</a>
<a class="m_-5367002523642773269m_-8301622289956510289moz-txt-link-freetext" href="https://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-users" target="_blank">https://lists.kamailio.org/cgi<wbr>-bin/mailman/listinfo/sr-users</a><span class="m_-5367002523642773269HOEnZb"><font color="#888888">
</font></span></pre>
                <span class="m_-5367002523642773269HOEnZb"><font color="#888888"> </font></span></blockquote>
              <span class="m_-5367002523642773269HOEnZb"><font color="#888888"> <br>
                  <pre class="m_-5367002523642773269m_-8301622289956510289moz-signature" cols="72">-- 
Daniel-Constantin Mierla
<a class="m_-5367002523642773269m_-8301622289956510289moz-txt-link-abbreviated" href="http://www.twitter.com/miconda" target="_blank">www.twitter.com/miconda</a> -- <a class="m_-5367002523642773269m_-8301622289956510289moz-txt-link-abbreviated" href="http://www.linkedin.com/in/miconda" target="_blank">www.linkedin.com/in/miconda</a>
Kamailio Advanced Training - <a class="m_-5367002523642773269m_-8301622289956510289moz-txt-link-abbreviated" href="http://www.asipto.com" target="_blank">www.asipto.com</a>
Kamailio World Conference - May 14-16, 2018 - <a class="m_-5367002523642773269m_-8301622289956510289moz-txt-link-abbreviated" href="http://www.kamailioworld.com" target="_blank">www.kamailioworld.com</a></pre>
                </font></span></div>
          </blockquote>
        </div>
        <br>
        <br clear="all">
        <div><br>
        </div>
        -- <br>
        <div class="m_-5367002523642773269gmail_signature" data-smartmail="gmail_signature">
          <div dir="ltr">Mark Blackford
            <div>Digium Cloud Services</div>
            <div>678.230.8769</div>
            <div><br>
            </div>
          </div>
        </div>
      </div>
    </blockquote>
    <br>
    <pre class="m_-5367002523642773269moz-signature" cols="72">-- 
Daniel-Constantin Mierla
<a class="m_-5367002523642773269moz-txt-link-abbreviated" href="http://www.twitter.com/miconda" target="_blank">www.twitter.com/miconda</a> -- <a class="m_-5367002523642773269moz-txt-link-abbreviated" href="http://www.linkedin.com/in/miconda" target="_blank">www.linkedin.com/in/miconda</a>
Kamailio Advanced Training - <a class="m_-5367002523642773269moz-txt-link-abbreviated" href="http://www.asipto.com" target="_blank">www.asipto.com</a>
Kamailio World Conference - May 14-16, 2018 - <a class="m_-5367002523642773269moz-txt-link-abbreviated" href="http://www.kamailioworld.com" target="_blank">www.kamailioworld.com</a></pre>
  </div></div></div>

</blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr">Mark Blackford<div>Digium Cloud Services</div><div>678.230.8769</div><div><br></div></div></div>
</div>