[SR-Users] Packet processing order

Daniel-Constantin Mierla miconda at gmail.com
Tue Dec 6 16:59:13 CET 2022


On 06.12.22 14:44, Jawaid Bazyar wrote:
> Hi Alex,
>
> Yes that's what I meant exactly. Some multi-process systems are truly stateless (DNS, for example).
>
> I meant no insult by use of the term, just its sense of "simplistic". 
>
> I appreciate Daniel's comments about the Internet creating out of order packets. While there is truth to that, operators go to great lengths to avoid designs that reorder packets, as it does strain stacks. TCP treats out of order much the same way it handles packet loss and it can cause retransmissions and loss of goodput.

Well, here you refer to tcp stack implementation, which is at endpoints
of the tcp connection (A<=>B), and they deal with packets order, not the
intermediary IP routers/nodes, what I said in my previous response.

Feel free to make pull requests with patches that you think are useful,
they will be reviewed and merged if they are useful, it's an open source
project and contributions are encouraged. Just have in mind that
performance is a major characteristic expected from a sip proxy.


>  Surely in SIP there is the potential to cause timeouts and retransmissions yes?
>
> I guess my point would be, sure, sometimes it can't be helped; but if it can be helped, why exacerbate it?
>
>
> I was doing some thinking about performance, and you can maintain performance by the following approach:
>
> Create N queues, one assigned to each worker thread
> Hash incoming messages to a queue based on call ID
> Each worker thread works on its assigned queue.

Which does not work on all cases .. like (imagining) for a system used
for large file transfers done with MESSAGE/INFO requests using same
Call-Id and incremented CSeq per file. You can end up with having same
hash id reminder for many call-ids, pushing most of the packets in the
same queue, the associated worker process becoming incapable of handling
the assigned traffic, packets then being dropped from network/socket
buffer or fill available memory. 


>
> This takes care of the issue - from the perspective of a single dialog, it's the same as setting children=1. But this approach also ought to enable you to have many more worker threads. Currently, the more worker threads, the more likely reordering will occur. With the algorithm above, you can have many more worker threads and not worry about increasing reordering.

I pointed to the core parameters for an option that is now available and
Alex named it. He also provided hints about other queuing features. The
sworker module can be leveraged for another variant. But again, it does
not solve it overall.

Cheers,
Daniel


>
> Cheers,
>
> Jawaid
>
>
>
> On 12/6/22, 6:11 AM, "sr-users on behalf of Alex Balashov" <sr-users-bounces at lists.kamailio.org on behalf of abalashov at evaristesys.com> wrote:
>
>     I suspect that what Jawaid meant by "naive" was that, in Kamailio, there is not a central distributor thread which aims to buffer, serialise and otherwise order packets prior to distribution into worker processes or threads, as is common in many other multiprocess systems. 
>
>     I agree that "naive" is perhaps not the best choice of vocabulary for it, and of course there would be performance downsides to such a centralised pipeline. But I think that's what was probably meant.
>
>     -- Alex
>
>     > On Dec 6, 2022, at 4:15 AM, Daniel-Constantin Mierla <miconda at gmail.com> wrote:
>     > 
>     > Hello,
>     > actually your expectation that packets should come in order is "naive", just think about how internet is constructed and IP routing works. In the past it was easy to reproduce on mobile networks scenarios when sending CANCEL very quickly after the INVITE resulted in CANCEL arriving first at the proxy, then the INVITE.
>     > Probably you don't get it in your lab environment where you have sipp on the same system as the sip server or one network segment away, but over the internet the packets can get in different order because of network transmission (different IP routing paths). It is the reason in some cases there are jitter buffers and sequence numbers (e.g., in RTP and SIP (CSeq)). In other words, the protocols like RTP or SIP were designed to deal with these out-of-order packets.
>     > Ans here is a wikipedia short article enumerating what can cause out of order:
>     >   - https://en.wikipedia.org/wiki/Out-of-order_delivery
>     > That said, if you missed in the message from mailing list archive that you linked to, there is a global parameter that should reduce the risk of sending out of order sip packets to the minimum that can be done from SIP processing point of view based on call-id, but there are still chances that on multi-cpu systems the packets read from the network can get to be processed in different order because of how read on udp sockets is done by kernel/libc and how cpu scheduler allocate cycles to running application processes.
>     > Cheers,
>     > Daniel
>     > On 05.12.22 19:34, Jawaid Bazyar wrote:
>     >> Hi,
>     >>  I have experienced out of order packet processing when testing a simple Kamailio config.
>     >>  The configuration is as follows, basically:
>     >>  request_route{
>     >>         record_route();
>     >>          enum_query();
>     >>         xlog("INVITE ENUM query - To URI $tU");
>     >>         forward();
>     >> }
>     >>  I saw this thread from 2020:
>     >>  sr-users at lists.kamailio.org <https://www.mail-archive.com/<a href=>/msg11786.html">https://www.mail-archive.com/sr-users@lists.kamailio.org/msg11786.html
>     >>  The issue seems to be that kamailio process scheduling is naïve – i.e., incoming SIP packets are processed without regard to whether packets received before this one, are currently being processed. This means any packets after the initial INVITE that require more processing, can get reordered.  In my test lab I have:
>     >>                 SIPp – UAC
>     >>                 Kamailio Proxy
>     >>                 SIPp – UAS
>     >>  The proxy uses enum NAPR lookups to route calls to +13038151000 to the UAS.
>     >>  Now, if I do SIPp UAC o SIPp UAS directly, I have no problems – no out of order packets.
>     >>  It is only when I introduce Kamailio in the middle that I get OOO packets.
>     >>  See the images attached: uac-to-proxy, proxy, and proxy-to-uas.
>     >>  In this example, Kamailio OOO causes SIPp UAC to fail to “generate audio” – because UAC does not see packets in the correct order, I never turns on the simulated audio. Calls that have in-order dialogs, work fine, and SIPP UAC “pauses” 10 seconds to simulate a phone call.
>     >>  So far, the error rate runs from 1/1000 to around 1/200 – pretty bad.
>     >>   In the thread, a few things were suggested.
>     >>  Have fewer kamailio processes than cores:
>     >>                 Did not resolve issue.
>     >>  Try route_locks_size = 256
>     >>                 Did not resolve issue. Though, it did alter it somewhat. But, it is not clear to me how this works – would this setting restrict the number of open calls to 256?
>     >>  Have only one kamailio process: (“children=1”)
>     >>                This works. “Works”, I should say, because this would greatly restrict total platform scalability to a point where it is probably useless for my application.
>     >>   I saw the same issue discussed in the OpenSIPS mailing list from 2010, and the response was “this is not a bug”.
>     >>  Well, I respectfully beg to differ with both OpenSIPS and Kamailio – it IS a bug. I don’t think a proxy should reorder packets involved in a call in a non-deterministic way. In the Kamailio list thread, Alex Balashov discusses the contortions he has to go through to avoid repercussions from this issue.
>     >>  Kamailio as-is probably works fine for relatively low-volume operations. And a lot of the feedback is “why are out of order packets a problem?” OK, sure, in the very specific example given in the 2020 thread, maybe who cares. But in my thinking, there is absolutely nothing preventing Kamailio from generating much more serious OOO scenarios that would cause calls to fail. In my example, Kamailio OOO causes SIPp to fail to “generate audio”. Who knows how other SIP stacks will behave?
>     >>  But the more one will try to scale Kamailio, the more significantly this out of order processing issue will become.
>     >>  The solution to this seems very simple and straightforward – put packets to be processed into a queue PER Call-ID, or something along those lines.
>     >>  In short, the parallelism should be by call, not by packet.
>     >>  What say ye? Have I misunderstood something here?
>     >>  Cheers,
>     >>  Jawaid
>     >>   
>     >> __________________________________________________________
>     >> Kamailio - Users Mailing List - Non Commercial Discussions
>     >> sr-users at lists.kamailio.org
>     >> Important: keep the mailing list in the recipients, do not reply only to the sender!
>     >> Edit mailing list options or unsubscribe:
>     >> https://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-users
>     >> 
>     > -- 
>     > Daniel-Constantin Mierla -- www.asipto.com
>     > www.twitter.com/miconda -- www.linkedin.com/in/miconda
>     > __________________________________________________________
>     > Kamailio - Users Mailing List - Non Commercial Discussions
>     > sr-users at lists.kamailio.org
>     > Important: keep the mailing list in the recipients, do not reply only to the sender!
>     > Edit mailing list options or unsubscribe:
>     > https://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-users
>
>
>     -- 
>     Alex Balashov | Principal | Evariste Systems LLC
>
>     Tel: +1-706-510-6800 / +1-800-250-5920 (toll-free)
>     Web: http://www.evaristesys.com/, http://www.csrpswitch.com/
>
>
>     __________________________________________________________
>     Kamailio - Users Mailing List - Non Commercial Discussions
>     sr-users at lists.kamailio.org
>     Important: keep the mailing list in the recipients, do not reply only to the sender!
>     Edit mailing list options or unsubscribe:
>     https://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-users
>
>
>
> __________________________________________________________
> Kamailio - Users Mailing List - Non Commercial Discussions
> sr-users at lists.kamailio.org
> Important: keep the mailing list in the recipients, do not reply only to the sender!
> Edit mailing list options or unsubscribe:
> https://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-users

-- 
Daniel-Constantin Mierla -- www.asipto.com
www.twitter.com/miconda -- www.linkedin.com/in/miconda




More information about the sr-users mailing list