<HTML><BODY style="word-wrap: break-word; -khtml-nbsp-mode: space; -khtml-line-break: after-white-space; "><BR><DIV><DIV>On 21 Dec 2005, at 15:39, Steve Kann wrote:</DIV><BR class="Apple-interchange-newline"><BLOCKQUOTE type="cite"><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">Dmytro Mishchenko wrote:</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; min-height: 14px; "><BR></DIV> <BLOCKQUOTE type="cite"><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">Hello,</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; min-height: 14px; "><BR></DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">Here is a problem with IAX and probably other kind of channels.</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; min-height: 14px; "><BR></DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">IAX2 channel function socket_read() process all kind of IAX frames.</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">Frames of type: IAX_COMMAND_REGREQ, IAX_COMMAND_AUTHREQ, IAX_COMMAND_AUTHREP etc. may take some significant time for processing. E.g. in the case when realtime engine will try to get data from DB. If this time is even half of a second its enough to interrupt ALL currently running calls. All audio streams delayed until one frame being processed. It makes audio choppy.</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; min-height: 14px; "><BR></DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">I'm thinking that such kind of work as finding user should be scheduled and executed by other thread. Does it make sense? Or may be some other solution can be used?</DIV><P style="margin: 0.0px 0.0px 0.0px 0.0px; min-height: 14.0px"><SPAN class="Apple-converted-space"> </SPAN><BR class="khtml-block-placeholder"></P> </BLOCKQUOTE><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; min-height: 14px; "><BR></DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">I've talked about this with people in chat before, and yes, you're right.</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; min-height: 14px; "><BR></DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">This wasn't really as big of an issue before RealTime stuff was added, because before then, everything was CPU-bound, and there weren't any(?) cases where these actions would block.</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; min-height: 14px; "><BR></DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">Now, though, there are.</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; min-height: 14px; "><BR></DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">So, there's lots of solutions to the problem, and I would probably go with this:</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; min-height: 14px; "><BR></DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">Have a pool of "worker" threads, and a "work queue". <SPAN class="Apple-converted-space">  </SPAN>When socket_read reads and parses frames, if there's a possible blocking operation involved (like ARA), it puts the frame into the work queue, which these worker threads are waiting on (or servicing).<SPAN class="Apple-converted-space">  </SPAN>It would seem that other than some reorganizing of socket_read (probably to break it up into smaller functions), this could be done without having to do major surgery.</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; min-height: 14px; "><BR></DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">I'm not sure myself which types of frames can lead to blocking like this, but it certainly would only be a tiny minority of the frames that are being processed.</DIV></BLOCKQUOTE><DIV><BR class="khtml-block-placeholder"></DIV><DIV>There is a thing to watch here, you might need to ack the command frame before you actually act on it, then </DIV><DIV>send an explicit response eg REGREJ or REGACK. Eitherway the IAX sequence numbering gets a </DIV><DIV>bit more complex to implement than in the single thread version.</DIV><DIV> </DIV><BR><BLOCKQUOTE type="cite"><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; min-height: 14px; "><BR></DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">-SteveK</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; min-height: 14px; "><BR></DIV></BLOCKQUOTE><BR>Tim.</DIV><BR><DIV> <P style="margin: 0.0px 0.0px 0.0px 0.0px"><FONT face="Helvetica" size="3" style="font: 12.0px Helvetica"><A href="http://www.westhawk.co.uk">http://www.westhawk.co.uk</A>/</FONT></P>  </DIV><BR></BODY></HTML>