[asterisk-dev] Wanted: Missing CPU Cycles... Reward!
Vadim Lebedev
vadim at mbdsys.com
Wed Oct 31 12:05:03 CDT 2007
Steve Murphy wrote:
> 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"!!!
>
> 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.
>
> 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.
>
> I've used gprof on my fast-ast2 branch of asterisk, and these are the
> contending routines for optimizations:
>
> % cumulative self self total
> time seconds seconds calls s/call s/call name
> 23.83 5.47 5.47 4000005 0.00 0.00
> pbx_substitute_variables
> 11.69 8.15 2.68 2000075 0.00 0.00
> pbx_substitute_variables_helper_full
...
Well the following is obviously MUUCH faster than the original:
static void pbx_substitute_variables(char *passdata, int datalen, struct
ast_channel *c, struct ast_exten *e)
{
/* No variables or expressions in e->data, so why scan it? */
if (e->data && !strchr(e->data, '$'))
ast_copy_string(passdata, e->data, datalen);
return;
}
*passdata = 0;
pbx_substitute_variables_helper(c, e->data, passdata, datalen - 1);
}
Original:
static void pbx_substitute_variables(char *passdata, int datalen, struct
ast_channel *c, struct ast_exten *e)
{
memset(passdata, 0, datalen);
/* No variables or expressions in e->data, so why scan it? */
if (e->data && !strchr(e->data, '$') && !strstr(e->data,"${") &&
!strstr(e->data,"$[") && !strstr(e->data,"$(")) {
ast_copy_string(passdata, e->data, datalen);
return;
}
pbx_substitute_variables_helper(c, e->data, passdata, datalen - 1);
}
static void pbx_substitute_variables(char *passdata, int datalen, struct
ast_channel *c, struct ast_exten *e)
{
memset(passdata, 0, datalen);
/* No variables or expressions in e->data, so why scan it? */
if (e->data && !strchr(e->data, '$') && !strstr(e->data,"${") &&
!strstr(e->data,"$[") && !strstr(e->data,"$(")) {
ast_copy_string(passdata, e->data, datalen);
return;
}
pbx_substitute_variables_helper(c, e->data, passdata, datalen - 1);
}
>
> [dialextens]
> exten => _10X,1,Dial(Zap/${EXTEN:2}|30|tw)
> exten => _1ZX,1,Dial(Zap/${EXTEN:1}|30|tw)
>
>
> [dialthrus]
> exten => _3XX,1,Dial(Zap/${EXTEN:1}|30|tw)
>
>
> [t1incoming]
> include => dialextens
> include => parkedcalls
> exten => s,1,Answer()
> exten => s,2,Background(welcome-to-test-machine)
>
>
> [incoming]
> include => dialextens
> include => parkedcalls
> exten => s,1,Answer()
> exten => s,2,Background(welcome-to-test-machine)
>
>
> [extension]
> include => dialextens
> include => dialthrus
> exten => 5,1,Record(recording:gsm)
> exten => 5,2,Background(recording)
> exten => 81,1,Set(iterations=$[1000000])
> exten => 81,2,Set(time1=${EPOCH})
> exten => 81,3,Set(i=$[1])
> exten => 81,4,GotoIf($[${i}<${iterations}]?5:8)
> exten => 81,5,NoOp(Hello)
> exten => 81,6,Set(i=$[${i}+1])
> exten => 81,7,Goto(4)
> exten => 81,8,NoOp(Finish for-extension-1)
> exten => 81,9,Set(time2=${EPOCH})
> exten => 81,10,Verbose(The time diff is $[${time2} - ${time1} ] seconds)
> exten => 81,11,Verbose(Which means that the priorities/sec = $[4*
> ${iterations} / (${time2} - ${time1}) ])
> exten => 81,12,SayNumber($[4 * ${iterations} / (${time2} - ${time1}) ])
> exten => 82,1,NoOp(Never here)
> exten => 82,2,Verbose(Not here either!)
> exten => 83,1,Read(x|beep|1||1|0.3)
> exten => 83,2,Read(x|beep|1||1|0.3)
> exten => 83,3,Read(x|beep|1||1|0.3)
>
> murf
> --
> Steve Murphy
> Software Developer
> Digium
>
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> --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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.digium.com/pipermail/asterisk-dev/attachments/20071031/ef0e1cd2/attachment.htm
More information about the asterisk-dev
mailing list