[Asterisk-Dev] sched.c::schedule function can be a bottleneck and is optimised backwards

steve at daviesfam.org steve at daviesfam.org
Fri Oct 28 12:08:46 MST 2005


Hi,

I've been looking at performance in iax2 for handling registrations.

oprofile revealed that 60-70% of my execution time was in 
ast_sched_add_variable in sched.c

With lots of registrations, its true that many many tasklets are getting 
scheduled, but I didn't expect this activity to be my bottleneck.

By inspection, I'm pretty sure that the time is going in schedule().

The logic searches down the schedule queue, looking for the first entry to 
run later than the new one.  The new one is then inserted there.

It would be much quicker to search the list backwards.  Stands to reason 
that the new entry is much more likely to go at the end or near to the end 
of the queue than it is to go near the start.

Thats definitely the case for the example of registrations, but I'm pretty 
confident that it'll be the case in general, seeing as how time goes 
forwards.

Agreed to change it around?  I think that the list will need to be made 
doubly-linked as I need to be able to insert near the end and retrieve 
from the front.

Steve



More information about the asterisk-dev mailing list