<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> </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 <alex.guan@prodeasystems.com><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. 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"> </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. 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 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 made. The function takes a destination string which</DIV>
<DIV style="FONT-SIZE: 12pt; FONT-FAMILY: times new roman, new york, times, serif">represents a channel endpoint url and may contain one or more of these strings separated by an & character.</DIV>
<DIV style="FONT-SIZE: 12pt; FONT-FAMILY: times new roman, new york, times, serif">when there are multiple channels being called at once the complexity 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 conditional</DIV>
<DIV style="FONT-SIZE: 12pt; FONT-FAMILY: times new roman, new york, times, serif">mutex idea harder to properly implement. 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. 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"> </DIV>
<DIV style="FONT-SIZE: 12pt; FONT-FAMILY: times new roman, new york, times, serif"> </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. 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. 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. 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. This works but is very</DIV>
<DIV style="FONT-SIZE: 12pt; FONT-FAMILY: times new roman, new york, times, serif">taxing on the box. 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"> </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?) 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"> </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"> </DIV>
<DIV style="FONT-SIZE: 12pt; FONT-FAMILY: times new roman, new york, times, serif"><BR> </DIV>
<DIV style="FONT-SIZE: 12pt; FONT-FAMILY: times new roman, new york, times, serif">Anthony,<BR><BR>Great answers indeed. Thanks a lot! Is there a documentation system that I can save it to ... like a wiki? 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. 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. Can't we wait for a mutex or condition waken up by CALL_ANSWERED? 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. There was no 200OK for the re-INVITE. I tried to debug further but somehow couldn't
get into mod_exosip.c using gdb. (DDD and Eclipse behaved the same. Does anybody have the same issue?) I kind of guess the issue is what kind of SDP is the SIP phone sending for hold. The old way is to set an all zero O field, as opposed to SENDONLY or INACTIVE. 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. A main problem I saw with Asterisk is it's GPL/Digium dual licensing scheme. I don't see any serious business development could be possible under this license. I think Mark and his company have made a big mistake on this subject. (And their business model as well.) What's the main rationale for you/other founders to choose MPL? Do you favour/oppose to commercial development using freeswitch in their proprietary systems?<BR><BR>2. Memory usage. I am
seeing freeswitch using 25M bytes of memory with just one basic SIP call. It's a little surprising. Should I turn on the -Os to see if we can save some space?<BR><BR> PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND<BR>25295 root 0 -20 27040 25m 3696 S 0 2.5 0:00.12 lt-freeswitch <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. Thread architecture. For a basic call, why do we need two threads for the sessions (one for each
endpoint)? While the thread in charge of originator is in the switch_core_standard_on_execute(), the other thread is in the switch_core_session_run() while loop. What's advantage of doing this compared to Asterisk's one thread approach? 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. if this state is hangup<BR>the call ends.<BR><BR>2. What does CS_LOOPBACK really mean? When A calls B, B is in the LOOPBACK state after the call is established. 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(). Is there a better approach than this? 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. The same function is called twice for the originator
channel. 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 <alex.guan@prodeasystems.com><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. A few questions regarding the architecture. Any input will be greatly appreciated.<BR><BR>1. Thread architecture. For a basic call, why do we need two threads for the sessions (one for each endpoint)? While the thread in charge of originator is in the switch_core_standard_on_execute(), the other thread is in the switch_core_session_run() while loop. What's advantage of doing this compared to Asterisk's one thread approach? Why do we need the thread for the originatee?<BR><BR>2. What does CS_LOOPBACK really mean? When A calls B, B is in the LOOPBACK state
after the call is established. 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(). Is there a better approach than this? 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. The same function is called twice for the originator channel. 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> <<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>> <BR>UNSUBSCRIBE:<A href="http://lists.freeswitch.org/mailman/options/freeswitch-dev" target=_blank>http://lists.freeswitch.org/mailman/options/freeswitch-dev</A> <<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>> <BR><A href="http://www.freeswitch.org/" target=_blank>http://www.freeswitch.org</A> <<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>></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>