<html><head><style type="text/css"><!-- DIV {margin:0px} --></style></head><body><div style="font-family:courier, monaco, monospace, sans-serif;font-size:12pt"><DIV></DIV>
<DIV><BR>&nbsp;</DIV>
<DIV>Anthony Minessale II<BR><BR>FreeSWITCH http://www.freeswitch.org/<BR>ClueCon http://www.cluecon.com/<BR><BR>AIM: anthm<BR>MSN:anthony_minessale@hotmail.com<BR>JABBER:anthony.minessale@gmail.com<BR>IRC: irc.freenode.net #freeswitch</DIV>
<DIV><BR>FreeSWITCH Developer Conference<BR>sip:888@66.250.68.194<BR>iax:guest@66.250.68.194/888<BR>googletalk:freeswitch@gmail.com<BR>pstn:712-432-7800</DIV>
<DIV style="FONT-SIZE: 12pt; FONT-FAMILY: courier, monaco, monospace, sans-serif"><BR><BR>
<DIV style="FONT-SIZE: 12pt; FONT-FAMILY: times new roman, new york, times, serif">----- Original Message ----<BR>From: Alex Guan &lt;alex.guan@prodeasystems.com&gt;<BR>To: freeswitch-dev@lists.freeswitch.org<BR>Sent: Thursday, September 7, 2006 2:26:41 PM<BR>Subject: Re: [Freeswitch-dev] Questions regarding the architecture<BR></DIV>
<DIV style="FONT-SIZE: 12pt; FONT-FAMILY: times new roman, new york, times, serif">First of all, thanks for paying attention.&nbsp; I have been waiting for someone to finally raise any questions</DIV>
<DIV style="FONT-SIZE: 12pt; FONT-FAMILY: times new roman, new york, times, serif">at all about the code so congrats.</DIV>
<DIV style="FONT-SIZE: 12pt; FONT-FAMILY: times new roman, new york, times, serif">&nbsp;</DIV>
<DIV style="FONT-SIZE: 12pt; FONT-FAMILY: times new roman, new york, times, serif">I am open to suggestions in that matter. You may want to look at the newest revision of the code as we discuss this</DIV>
<DIV style="FONT-SIZE: 12pt; FONT-FAMILY: times new roman, new york, times, serif">because it has become more complicated from the one you are describing.&nbsp; The functionality to wait for </DIV>
<DIV style="FONT-SIZE: 12pt; FONT-FAMILY: times new roman, new york, times, serif">and outbound call has been moved to the switch_ivr_originate function which is a standard&nbsp;function now</DIV>
<DIV style="FONT-SIZE: 12pt; FONT-FAMILY: times new roman, new york, times, serif">used anywhere in the code where an outbound call must be&nbsp;made.&nbsp; The&nbsp;function takes a destination&nbsp;string which</DIV>
<DIV style="FONT-SIZE: 12pt; FONT-FAMILY: times new roman, new york, times, serif">represents a channel endpoint url&nbsp;and may contain one or more of these strings separated by an &amp; character.</DIV>
<DIV style="FONT-SIZE: 12pt; FONT-FAMILY: times new roman, new york, times, serif">when there are multiple&nbsp;channels being called at once the complexity&nbsp;goes up and the while loop in question</DIV>
<DIV style="FONT-SIZE: 12pt; FONT-FAMILY: times new roman, new york, times, serif">now polls the status of all the channels that are candidates for the outgoing connection which makes the&nbsp;conditional</DIV>
<DIV style="FONT-SIZE: 12pt; FONT-FAMILY: times new roman, new york, times, serif">mutex&nbsp;idea harder to properly implement.&nbsp;&nbsp;The good news is we do a switch_yield(1000) [sleep 1 ms and yield the cpu] </DIV>
<DIV style="FONT-SIZE: 12pt; FONT-FAMILY: times new roman, new york, times, serif">and this loop tends to never last very long in a traditional call.&nbsp; I am not against optimizing as long as it doesn't compromize</DIV>
<DIV style="FONT-SIZE: 12pt; FONT-FAMILY: times new roman, new york, times, serif">stability.</DIV>
<DIV style="FONT-SIZE: 12pt; FONT-FAMILY: times new roman, new york, times, serif">&nbsp;&nbsp;</DIV>
<DIV style="FONT-SIZE: 12pt; FONT-FAMILY: times new roman, new york, times, serif">&nbsp;</DIV>
<DIV style="FONT-SIZE: 12pt; FONT-FAMILY: times new roman, new york, times, serif">There is a bigger problem I see in a similar situation in the RTP.&nbsp; The defualt behaviour in the config for things that use</DIV>
<DIV style="FONT-SIZE: 12pt; FONT-FAMILY: times new roman, new york, times, serif">RTP is to set the read socket in async mode meaning the reads will timeout exactly in tune with the desired sample rate and packet interval</DIV>
<DIV style="FONT-SIZE: 12pt; FONT-FAMILY: times new roman, new york, times, serif">regardless of reading a valid packet or not.&nbsp; Artificial packets are generated and flagged as CNG so they are not interpreted by the codec engine and are simply passed through to keep the timing right.&nbsp; We currently are using switch_time_now() which on unix translates to</DIV>
<DIV style="FONT-SIZE: 12pt; FONT-FAMILY: times new roman, new york, times, serif">gettimeofday() using a method where we take an initial timestamp then increment that number by the desired ms interval and do several</DIV>
<DIV style="FONT-SIZE: 12pt; FONT-FAMILY: times new roman, new york, times, serif">gettime calls until we land on or past the desired ms mark at which point we calculate the next mark based on the last (not based on the current time as that source cannot be trusted) so if we start at 1000 ms epoch we go up to 1020 1040 1060 etc.&nbsp; This works but is very</DIV>
<DIV style="FONT-SIZE: 12pt; FONT-FAMILY: times new roman, new york, times, serif">taxing on the box.&nbsp; I am considering comming up with a way to start a single thread in the core for every unique sample rate and interval combo</DIV>
<DIV style="FONT-SIZE: 12pt; FONT-FAMILY: times new roman, new york, times, serif">desired by anything using the code and having interested threads register to be woken up at this interval somehow so the inner read loop in rtp can try to read on a nonblocking socket then hit a mutex that is reliably woken up at the exact desired interval.</DIV>
<DIV style="FONT-SIZE: 12pt; FONT-FAMILY: times new roman, new york, times, serif">&nbsp;</DIV>
<DIV style="FONT-SIZE: 12pt; FONT-FAMILY: times new roman, new york, times, serif">This is of course somewhat tricky so I need to think about it more but possibly using some other form of timer would also help this matter </DIV>
<DIV style="FONT-SIZE: 12pt; FONT-FAMILY: times new roman, new york, times, serif">like POSIX or something (anyone have any examples?)&nbsp; I am fairly sure that this timing thing leaves room to double how many calls </DIV>
<DIV style="FONT-SIZE: 12pt; FONT-FAMILY: times new roman, new york, times, serif">we can get at once on a hefty box that can already do upwards of 1000 channels even with this bottleneck in place...</DIV>
<DIV style="FONT-SIZE: 12pt; FONT-FAMILY: times new roman, new york, times, serif">&nbsp;</DIV>
<DIV style="FONT-SIZE: 12pt; FONT-FAMILY: times new roman, new york, times, serif">So let me know what you think....</DIV>
<DIV style="FONT-SIZE: 12pt; FONT-FAMILY: times new roman, new york, times, serif">&nbsp;</DIV>
<DIV style="FONT-SIZE: 12pt; FONT-FAMILY: times new roman, new york, times, serif"><BR>&nbsp;</DIV>
<DIV style="FONT-SIZE: 12pt; FONT-FAMILY: times new roman, new york, times, serif">Anthony,<BR><BR>Great answers indeed.&nbsp;&nbsp;Thanks a lot!&nbsp;&nbsp;Is there a documentation system that I can save it to ... like a wiki?&nbsp;&nbsp;These information are too valuable to be buried in the mail archive.<BR><BR>It took me a while but I think I have come to agreement for pretty much every point you made, except one.&nbsp;&nbsp;The only thing I felt suspicious is the busy waiting in which the originator polls check_channel_status() a million times after the originatee starts ringing but before it answers.&nbsp;&nbsp; Can't we wait for a mutex or condition waken up by CALL_ANSWERED?&nbsp;&nbsp;Imagine if you have a thousand incoming calls, there will be 1000 while loops spinning the processor.<BR><BR>Another issue I noticed is that hold/resume is not working properly.&nbsp;&nbsp;There was no 200OK for the re-INVITE.&nbsp;&nbsp;I tried to debug further but somehow couldn't
 get into mod_exosip.c using gdb.&nbsp;&nbsp;(DDD and Eclipse behaved the same.&nbsp;&nbsp;Does anybody have the same issue?)&nbsp;&nbsp;I kind of guess the issue is what kind of SDP is the SIP phone sending for hold.&nbsp;&nbsp;The old way is to set an all zero O field, as opposed to SENDONLY or INACTIVE.&nbsp;&nbsp;Anyways, if mod_exopsip.c is going way, we should probably just wait for mod_sofia.<BR><BR>Two more basic questions:<BR>1. Licensing.&nbsp;&nbsp;A main problem I saw with Asterisk is it's GPL/Digium dual licensing scheme.&nbsp;&nbsp;I don't see any serious business development could be possible under this license.&nbsp;&nbsp;I think Mark and his company have made a big mistake on this subject.&nbsp;&nbsp;(And their business model as well.)&nbsp;&nbsp;What's the main rationale for you/other founders to choose MPL?&nbsp;&nbsp;Do you favour/oppose to commercial development using freeswitch in their proprietary systems?<BR><BR>2. Memory usage.&nbsp;&nbsp;I am
 seeing freeswitch using 25M bytes of memory with just one basic SIP call.&nbsp;&nbsp;It's a little surprising.&nbsp;&nbsp;Should I turn on the -Os to see if we can save some space?<BR><BR>&nbsp;&nbsp;PID USER&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;PR&nbsp;&nbsp;NI&nbsp;&nbsp;VIRT&nbsp;&nbsp;RES&nbsp;&nbsp;SHR S %CPU %MEM&nbsp;&nbsp;&nbsp;&nbsp;TIME+ COMMAND<BR>25295 root&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 0 -20 27040&nbsp;&nbsp;25m 3696 S&nbsp;&nbsp;&nbsp;&nbsp;0&nbsp;&nbsp;2.5&nbsp;&nbsp; 0:00.12 lt-freeswitch&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <BR><BR>Thanks,<BR>Alex<BR><BR>________________________________<BR><BR>From: Anthony Minessale [mailto:anthmct@yahoo.com]<BR>Sent: Wed 9/6/2006 2:01 PM<BR>To: freeswitch-dev@lists.freeswitch.org<BR>Subject: Re: [Freeswitch-dev] Questions regarding the architecture<BR><BR><BR>1.&nbsp;&nbsp; Thread architecture.&nbsp;&nbsp;For a basic call, why do we need two threads for the sessions (one for each
 endpoint)?&nbsp;&nbsp;While the thread in charge of originator&nbsp;&nbsp;is in the switch_core_standard_on_execute(), the other thread is in the switch_core_session_run() while loop.&nbsp;&nbsp;&nbsp;&nbsp;What's advantage of doing this compared to Asterisk's one thread approach?&nbsp;&nbsp;Why do we need the thread for the originatee?<BR>A)<BR><BR>Every session has a thread which is managed by the state machine in the core which sees it from creation to destruction.<BR>In the case of a bridged call the existing thread of both sessions are used to move inbound audio across to the opposite session at the same time.<BR>A one threaded approach such as asterisk will leave you doing poll's on 2 sockets at once and blocking in one direction will impeed the other as <BR>well as forcing you to expose something that can be polled, (not all channels have sockets)<BR>The states of the orignatee channel are overridden from the default behaviour to perform the bridge<BR>in this
 case:<BR>CS_HOLD pauses the thread.<BR>CS_RING moves the state to CS_HOLD where it will wait until it's moved to CS_LOOPBACK or CS_HANGUP by the originate function. <BR>CS_LOOPBACK runs the audio bridge code sending the audio back to the other channel.<BR>The originator is in CS_EXECUTE meaning it's running instructions installed by a dialplan module.<BR>At this point both channels are in the same code reading A and writing B as well as moving messages and dtmf across one another.<BR>If either is interrupted the functions exits in both sessions and the originatee state override table <BR>is cleared and the session is moved to the new state where the execution continues.&nbsp;&nbsp;if this state is hangup<BR>the call ends.<BR><BR>2. What does CS_LOOPBACK really mean?&nbsp;&nbsp;When A calls B, B is in the LOOPBACK state after the call is established.&nbsp;&nbsp;Yet, the switch_core_on_loopback() is not really called.<BR>A)<BR><BR>The default for loopback is to echo the
 audio back to the channel, <BR>in the case of a bridge it's overridden to send it audio to the other session instead<BR>of itself.<BR><BR><BR>3. When A calls B and before B answers, the caller session thread does busy waiting by constantly calling check_channel_status().&nbsp;&nbsp;Is there a better approach than this?&nbsp;&nbsp; And with this architecture how are we going to incorporate with the voice mail and other timer-based applications?<BR><BR>A)<BR>Yes this is the best approach, the originator has created the originatee and is waiting for the endpoint module to place it into the CS_RING state <BR>when this happens because we overrode it we move it to CS_HOLD and wait for it to be answered or for a timeout to occur.<BR>The point is we have waited for it to be safe for us to control.<BR><BR>4. When the orginatee hangs up, the exosip_kill_channel() was called 3 times just for the orginatee channel.&nbsp;&nbsp;The same function is called twice for the originator
 channel.&nbsp;&nbsp;Is this by design?<BR><BR>A)<BR>The should be as few calls to this as possible once it's ok to have mutiple calls to it it just calls for any blocking to end<BR>on a read or write operation such as the socket api call "shutdown()" does <BR>We are not using exosip anymore, we have started coding mod_sofia which is our preferred sip code.<BR>There are several changes comming up this week you may want to study.<BR><BR>Thanks,<BR><BR><BR>Anthony Minessale II<BR><BR>FreeSWITCH <A href="http://www.freeswitch.org/" target=_blank>http://www.freeswitch.org/</A><BR>ClueCon <A href="http://www.cluecon.com/" target=_blank>http://www.cluecon.com/</A><BR><BR>AIM: anthm<BR>MSN:anthony_minessale@hotmail.com<BR>JABBER:anthony.minessale@gmail.com<BR>IRC: irc.freenode.net #freeswitch<BR><BR>FreeSWITCH Developer Conference<BR>sip:888@66.250.68.194<BR>iax:guest@66.250.68.194/888<BR>googletalk:freeswitch@gmail.com<BR>pstn:712-432-7800<BR><BR><BR>----- Original Message
 ----<BR>From: Alex Guan &lt;alex.guan@prodeasystems.com&gt;<BR>To: freeswitch-dev@lists.freeswitch.org<BR>Sent: Wednesday, September 6, 2006 10:13:43 AM<BR>Subject: [Freeswitch-dev] Questions regarding the architecture<BR><BR><BR>Gang,<BR><BR>I am new to freeswitch and have been studying it for the last week.&nbsp;&nbsp;A few questions regarding the architecture.&nbsp;&nbsp;Any input will be greatly appreciated.<BR><BR>1.&nbsp;&nbsp; Thread architecture.&nbsp;&nbsp;For a basic call, why do we need two threads for the sessions (one for each endpoint)?&nbsp;&nbsp;While the thread in charge of originator&nbsp;&nbsp;is in the switch_core_standard_on_execute(), the other thread is in the switch_core_session_run() while loop.&nbsp;&nbsp;&nbsp;&nbsp;What's advantage of doing this compared to Asterisk's one thread approach?&nbsp;&nbsp;Why do we need the thread for the originatee?<BR><BR>2. What does CS_LOOPBACK really mean?&nbsp;&nbsp;When A calls B, B is in the LOOPBACK state
 after the call is established.&nbsp;&nbsp;Yet, the switch_core_on_loopback() is not really called.<BR><BR>3. When A calls B and before B answers, the caller session thread does busy waiting by constantly calling check_channel_status().&nbsp;&nbsp;Is there a better approach than this?&nbsp;&nbsp; And with this architecture how are we going to incorporate with the voice mail and other timer-based applications?<BR><BR>4. When the orginatee hangs up, the exosip_kill_channel() was called 3 times just for the orginatee channel.&nbsp;&nbsp;The same function is called twice for the originator channel.&nbsp;&nbsp;Is this by design?<BR><BR>Thanks,<BR>Alex<BR>_______________________________________________<BR>Freeswitch-dev mailing list<BR>Freeswitch-dev@lists.freeswitch.org<BR><A href="http://lists.freeswitch.org/mailman/listinfo/freeswitch-dev" target=_blank>http://lists.freeswitch.org/mailman/listinfo/freeswitch-dev</A> &lt;<A
 href="http://console.mxlogic.com/redir/?5dOWbXb8USC-yejhjhdw0PVkDjDo_Z34FS9Y01MjlS67OFek7qUX7_EoBeNcKxVATvzhOYMOMyOYeodECTo_Z34FS9BQfcBO5mUm-wafBitetz_QciDoDM04Sy-yMCrhhv7fK6zBxUQsCTNNI5-Aq83iSbN_W69jIjbEupdbFEw0tLWjBm53h17OeNgB0yq89A_d46NIjBfXjrzVKvxYYmfSk3q9JASC-yejKYUr3wsm" target=_blank>http://console.mxlogic.com/redir/?5dOWbXb8USC-yejhjhdw0PVkDjDo_Z34FS9Y01MjlS67OFek7qUX7_EoBeNcKxVATvzhOYMOMyOYeodECTo_Z34FS9BQfcBO5mUm-wafBitetz_QciDoDM04Sy-yMCrhhv7fK6zBxUQsCTNNI5-Aq83iSbN_W69jIjbEupdbFEw0tLWjBm53h17OeNgB0yq89A_d46NIjBfXjrzVKvxYYmfSk3q9JASC-yejKYUr3wsm</A>&gt; <BR>UNSUBSCRIBE:<A href="http://lists.freeswitch.org/mailman/options/freeswitch-dev" target=_blank>http://lists.freeswitch.org/mailman/options/freeswitch-dev</A> &lt;<A
 href="http://console.mxlogic.com/redir/?5dOWbXb8USC-yejhjhdw0PVkDjDo_Z34FS9Y01MjlS6lmDaIaoX7_EoBeNcKxVATvzhOYMOMyOYeodECTo_Z34FS9BQfcBO5mUm-wafBitetz_QciDoDM04Sy-yMCrhhv7fK6zBxUQsCTNNI5-Aq83iSbN_W69jIjbEupdbFEw0tLWjBm53h17OeNgB0yq89A_d46NIjBfXjrzVKvxYYmfSk3qpJASC-yejKYUr3wsm" target=_blank>http://console.mxlogic.com/redir/?5dOWbXb8USC-yejhjhdw0PVkDjDo_Z34FS9Y01MjlS6lmDaIaoX7_EoBeNcKxVATvzhOYMOMyOYeodECTo_Z34FS9BQfcBO5mUm-wafBitetz_QciDoDM04Sy-yMCrhhv7fK6zBxUQsCTNNI5-Aq83iSbN_W69jIjbEupdbFEw0tLWjBm53h17OeNgB0yq89A_d46NIjBfXjrzVKvxYYmfSk3qpJASC-yejKYUr3wsm</A>&gt; <BR><A href="http://www.freeswitch.org/" target=_blank>http://www.freeswitch.org</A> &lt;<A href="http://console.mxlogic.com/redir/?5dOWbXb8USC-yejhjhdw0Do_Z34FS9Y01MTvzhOYMOMyOYeodECTo_Z34FS9BQfcBO5mUm-wafBitetz_QciDoDM04Sy-yMCrhhv7fK6zBxUQsCTNNI5-Aq83iSbN_W69jIjbEupdbFEw0tLWjBm53h17OeNgB0yq89A_d46NIjBfXjrzVKvxYYmfSk3r9JASC-yejKYUr3wsm"
 target=_blank>http://console.mxlogic.com/redir/?5dOWbXb8USC-yejhjhdw0Do_Z34FS9Y01MTvzhOYMOMyOYeodECTo_Z34FS9BQfcBO5mUm-wafBitetz_QciDoDM04Sy-yMCrhhv7fK6zBxUQsCTNNI5-Aq83iSbN_W69jIjbEupdbFEw0tLWjBm53h17OeNgB0yq89A_d46NIjBfXjrzVKvxYYmfSk3r9JASC-yejKYUr3wsm</A>&gt;</DIV>
<DIV style="FONT-SIZE: 12pt; FONT-FAMILY: times new roman, new york, times, serif">_______________________________________________<BR>Freeswitch-dev mailing list<BR>Freeswitch-dev@lists.freeswitch.org<BR><A href="http://lists.freeswitch.org/mailman/listinfo/freeswitch-dev" target=_blank>http://lists.freeswitch.org/mailman/listinfo/freeswitch-dev</A><BR>UNSUBSCRIBE:<A href="http://lists.freeswitch.org/mailman/options/freeswitch-dev" target=_blank>http://lists.freeswitch.org/mailman/options/freeswitch-dev</A><BR><A href="http://www.freeswitch.org/" target=_blank>http://www.freeswitch.org</A></DIV><BR></DIV></div></body></html>