Question about PJ_IOQUEUE_KEY_FREE_DELAY

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tue, Sep 2, 2008 at 5:02 AM, Simon Chen <simonmychen at seed.net.tw> wrote:

>  Hi! Benny,
>
>     I am studing the ioqueue_select.c for adding PJ_IOQUEUE_HAS_SAFE_UNREG
> to ioqueue_epoll.c.  I have a question about PJ_IOQUEUE_KEY_FREE_DELAY. Why
> does the ioqueue key need to delay PJ_IOQUEUE_KEY_FREE_DELAY before put in
> the free-list?
>
>

I think PJ_IOQUEUE_KEY_FREE_DELAY is there for historical reason and
probably it's not that important now, although having said that, I probably
wouldn't want to remove it either for the simple reason that it works.

The reason for this delay is related to the ioqueue concurrency. By design,
the ioqueue does not guarantee that simultaneous handle unregistration and
other operation is thread safe, and application should take care of this
concurrency problem on its own. But in practice, most applications
(including pjsip and pjmedia) don't take care about this either, hence the
PJ_IOQUEUE_HAS_SAFE_UNREG mechanism was added to solve this (this was done
long time ago).

But recently, a new mechanism as added to control concurrency (the
pj_ioqueue_set_default_concurrency() and pj_ioqueue_set_concurrency()
functions), and while by default the concurrency is enabled (hence
unregistration is not thread-safe), some sockets (such as UDP media
transport) do set them to disabled (hence unregistration is thread-safe), so
the PJ_IOQUEUE_KEY_FREE_DELAY probably is not necessary anymore.


    When I set the value of max_fd to 1 in pj_ioqueue_create() and register
> a TCP socket to send a message, it works ok. After finished sending the
> message and unregister the key then register a new TCP socket(shorter than
> PJ_IOQUEUE_KEY_FREE_DELAY), the pj_ioqueue_register_sock() is stopped at
> pj_assert(!pj_list_empty(&ioqueue->free_list)). This is caused by that the
> only one key is in closing list. There are two way to fix this issue, one is
> to create more key in pj_ioqueue_create(). But how many key should be
> created? The other is to allocate memory for new key in
> pj_ioqueue_register_sock() when free list is empty and reuse it. What do you
> think?
>
>

Creating keys in demand probably is the best solution, but then these keys
must be deleted (and not put into the free list) once the handle is
unregistered. The reason is because unlike the pre-created keys, these
on-demand keys may be created using a temporary pool supplied in
pj_ioqueue_register_sock(), so the pool may no longer exist after the
unregistration.

The simplest solution is just to create more keys, or maybe reduce
PJ_IOQUEUE_KEY_FREE_DELAY to zero and see how it goes.

Cheers
 Benny



> Simon
>
>
>
>
> _______________________________________________
> Visit our blog: http://blog.pjsip.org
>
> pjsip mailing list
> pjsip at lists.pjsip.org
> http://lists.pjsip.org/mailman/listinfo/pjsip_lists.pjsip.org
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.pjsip.org/pipermail/pjsip_lists.pjsip.org/attachments/20080902/928ea5f6/attachment.html 


[Index of Archives]     [Asterisk Users]     [Asterisk App Development]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Security]     [Bugtraq]     [Linux]     [Linux OMAP]     [Linux MIPS]     [Linux API]
  Powered by Linux