<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
  <meta content="text/html;charset=UTF-8" http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
Steve Murphy wrote:
<blockquote cite="mid1193843164.22777.60.camel@digium2" type="cite">
  <meta http-equiv="Content-Type" content="text/html; ">
  <meta name="GENERATOR" content="GtkHTML/3.14.3">
In my effort to resurrect my long-ignored work on keeping large
dialplans from slowing down the PBX, I unearthed the fact, that
somehow, somewhere,  around 20% of the performance of the PBX engine
was "missing"!!!<br>
  <br>
Where this performance went, I have no idea. But we all need to think
on how we might get them back. I've come up with almost half of them
(percentage points of performance, that is) in one optimization,
perhaps others of you can come up with others.<br>
  <br>
My test is a simple tight loop of 4 priorities, I've written about and
talked about at conferences previously. Before, about a year ago, I was
seeing 90,000 PIPS from my test system. Yesterday, I measured trunk at
76,000 PIPS. With my optimization, I see 83,000 PIPS. <br>
  <br>
I've used gprof on my fast-ast2 branch of asterisk, and these are the
contending routines for optimizations:<br>
  <br>
  %   cumulative self            self     total<br>
time   seconds  seconds    calls   s/call   s/call  name<br>
23.83      5.47     5.47  4000005     0.00     0.00 
pbx_substitute_variables<br>
11.69      8.15     2.68  2000075     0.00     0.00 
pbx_substitute_variables_helper_full<br>
</blockquote>
...<br>
Well the following is obviously MUUCH faster than the original:<br>
<br>
static void pbx_substitute_variables(char *passdata, int datalen,
struct ast_channel *c, struct ast_exten *e)<br>
{<br>
<br>
        /* No variables or expressions in e-&gt;data, so why scan it? */<br>
        if (e-&gt;data &amp;&amp; !strchr(e-&gt;data, '$'))<br>
                ast_copy_string(passdata, e-&gt;data, datalen);<br>
                return;<br>
        }<br>
        <br>
        *passdata = 0;<br>
        pbx_substitute_variables_helper(c, e-&gt;data, passdata,
datalen - 1);<br>
}<br>
<br>
<br>
Original:<br>
static void pbx_substitute_variables(char *passdata, int datalen,
struct ast_channel *c, struct ast_exten *e)<br>
{<br>
        memset(passdata, 0, datalen);<br>
<br>
        /* No variables or expressions in e-&gt;data, so why scan it? */<br>
        if (e-&gt;data &amp;&amp; !strchr(e-&gt;data, '$') &amp;&amp;
!strstr(e-&gt;data,"${") &amp;&amp; !strstr(e-&gt;data,"$[") &amp;&amp;
!strstr(e-&gt;data,"$(")) {<br>
                ast_copy_string(passdata, e-&gt;data, datalen);<br>
                return;<br>
        }<br>
<br>
        pbx_substitute_variables_helper(c, e-&gt;data, passdata,
datalen - 1);<br>
}<br>
<br>
<br>
<br>
<br>
static void pbx_substitute_variables(char *passdata, int datalen,
struct ast_channel *c, struct ast_exten *e)<br>
{<br>
        memset(passdata, 0, datalen);<br>
<br>
        /* No variables or expressions in e-&gt;data, so why scan it? */<br>
        if (e-&gt;data &amp;&amp; !strchr(e-&gt;data, '$') &amp;&amp;
!strstr(e-&gt;data,"${") &amp;&amp; !strstr(e-&gt;data,"$[") &amp;&amp;
!strstr(e-&gt;data,"$(")) {<br>
                ast_copy_string(passdata, e-&gt;data, datalen);<br>
                return;<br>
        }<br>
<br>
        pbx_substitute_variables_helper(c, e-&gt;data, passdata,
datalen - 1);<br>
}<br>
<br>
<br>
<br>
<br>
<br>
<blockquote cite="mid1193843164.22777.60.camel@digium2" type="cite"><br>
[dialextens]<br>
exten =&gt; _10X,1,Dial(Zap/${EXTEN:2}|30|tw)<br>
exten =&gt; _1ZX,1,Dial(Zap/${EXTEN:1}|30|tw)<br>
  <br>
  <br>
[dialthrus]<br>
exten =&gt; _3XX,1,Dial(Zap/${EXTEN:1}|30|tw)<br>
  <br>
  <br>
[t1incoming]<br>
include =&gt; dialextens<br>
include =&gt; parkedcalls<br>
exten =&gt; s,1,Answer()<br>
exten =&gt; s,2,Background(welcome-to-test-machine)<br>
  <br>
  <br>
[incoming]<br>
include =&gt; dialextens<br>
include =&gt; parkedcalls<br>
exten =&gt; s,1,Answer()<br>
exten =&gt; s,2,Background(welcome-to-test-machine)<br>
  <br>
  <br>
[extension]<br>
include =&gt; dialextens<br>
include =&gt; dialthrus<br>
exten =&gt; 5,1,Record(recording:gsm)<br>
exten =&gt; 5,2,Background(recording)<br>
exten =&gt; 81,1,Set(iterations=$[1000000])<br>
exten =&gt; 81,2,Set(time1=${EPOCH})<br>
exten =&gt; 81,3,Set(i=$[1])<br>
  <font color="#ff6600">exten =&gt;
81,4,GotoIf($[${i}&lt;${iterations}]?5:8)</font><br>
  <font color="#ff6600">exten =&gt; 81,5,NoOp(Hello)</font><br>
  <font color="#ff6600">exten =&gt; 81,6,Set(i=$[${i}+1])</font><br>
  <font color="#ff6600">exten =&gt; 81,7,Goto(4)</font><br>
exten =&gt; 81,8,NoOp(Finish for-extension-1)<br>
exten =&gt; 81,9,Set(time2=${EPOCH})<br>
exten =&gt; 81,10,Verbose(The time diff is $[${time2} - ${time1} ]
seconds)<br>
exten =&gt; 81,11,Verbose(Which means that the priorities/sec = $[4*
${iterations} / (${time2} - ${time1}) ])<br>
exten =&gt; 81,12,SayNumber($[4 * ${iterations} / (${time2} - ${time1})
])<br>
exten =&gt; 82,1,NoOp(Never here)<br>
exten =&gt; 82,2,Verbose(Not here either!)<br>
exten =&gt; 83,1,Read(x|beep|1||1|0.3)<br>
exten =&gt; 83,2,Read(x|beep|1||1|0.3)<br>
exten =&gt; 83,3,Read(x|beep|1||1|0.3)<br>
  <br>
murf<br>
  <table cellpadding="0" cellspacing="0" width="100%">
    <tbody>
      <tr>
        <td>
        <pre>-- 
Steve Murphy
Software Developer
Digium
        </pre>
        </td>
      </tr>
    </tbody>
  </table>
  <pre wrap="">
<hr size="4" width="90%">
_______________________________________________
--Bandwidth and Colocation Provided by <a class="moz-txt-link-freetext" href="http://www.api-digital.com">http://www.api-digital.com</a>--

asterisk-dev mailing list
To UNSUBSCRIBE or update options visit:
   <a class="moz-txt-link-freetext" href="http://lists.digium.com/mailman/listinfo/asterisk-dev">http://lists.digium.com/mailman/listinfo/asterisk-dev</a></pre>
</blockquote>
<br>
</body>
</html>