[asterisk-dev] chan_sip -- improving the speed of sip reloads

Russell Bryant russell at digium.com
Tue Nov 20 22:31:08 CST 2007

Steve Murphy wrote:
> This is an interesting thought. I shall look into that. But, the code in
> IAX2 uses the iterators, also... so, if it is a big win to move over, I
> may rewrite those loops, also, then.

My feeling is that there are situations where the iterator is preferred over the
ao2_callback() method of executing code for every object in the container.
Specifically, if the code inside the traversal could be somewhat computationally
expensive, then you may want to avoid holding the container lock for the entire

For example, the code to handle the "iax2 show peers" CLI command uses an
iterator so that it doesn't block the container for the entire duration of
writing all of the peer data to the CLI fd.  Instead, the container lock is only
held for very short periods of time.  The reason is that any sort of delay in
the writes blocks every single IAX processing thread from doing any other
lookups in the container, which have a much higher priority than the response at
the CLI.

Of course, you increase the overall runtime of the iteration due to having to
contend for the lock so many times.  But, hopefully the benefits in response
time by other processing threads make it worth it.  I guess we'd have to do some
profiling to really know for sure.  But, I remember that there were noticeable
effects when I was doing some test calls through a system, loading it with a ton
of IAX2 registrations, and executing various CLI commands.

Russell Bryant
Senior Software Engineer
Open Source Team Lead
Digium, Inc.

More information about the asterisk-dev mailing list