<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 TRANSITIONAL//EN">
<HTML>
<HEAD>
  <META HTTP-EQUIV="Content-Type" CONTENT="text/html; CHARSET=UTF-8">
  <META NAME="GENERATOR" CONTENT="GtkHTML/4.2.3">
</HEAD>
<BODY>
Hi,<BR>
<BR>
When running a soak on presence with RLS NOTIFY requests are by far the most common.&nbsp; Further, especially with RLS in place, performance of Kamailio presence can be quite limited.&nbsp; The writers of the presence RFCs do seem to acknowledge that this is indeed an issue - hence the restrictions on the rate at which NOTIFY requests can be sent.<BR>
<BR>
I am looking for ways to sensibly reduce the number of NOTIFYs generated, and in this case, it seems that the presence module is actually sending them more frequently than the specification says it should anyway.<BR>
<BR>
Reducing the number of NOTIFYs sent doesn't just help with presence, but it should also reduce the amount of work that the RLS module has to do too - as it will receive (and have to process) less NOTIFYs as well.<BR>
<BR>
Of course I am open to other ways to approach this problem.&nbsp; Another thing I have been considering is setting the flags and fields I have discussed below but not sending NOTIFYs right away at all.&nbsp; I would then have a timer task (perhaps at the 100ms you suggest below) that generates outstanding NOTIFYs - but not at a rate of more than once per five seconds for each presentity.&nbsp; Effectively, this timer task would be a notifier, which I think is one of the things suggested recently on the list.<BR>
<BR>
Regards,<BR>
<BR>
Peter<BR>
<BR>
On Fri, 2012-03-30 at 10:01 +0200, Klaus Darilion wrote:
<BLOCKQUOTE TYPE=CITE>
<PRE>

On 29.03.2012 23:19, Peter Dunkley wrote:
&gt; Hi,
&gt;
&gt; RFC 3856 section 6.10 states: &quot;A PA SHOULD NOT generate notifications for
&gt; a single presentity at a rate of more than once every five seconds.&quot;

I wonder if this is useful. E.g. a user tries to call somebody, but the 
target is busy. Thus, the call will last maybe 3 seconds having the 
dialog states: trying, proceeding, early, terminated.

How is it supposed to work? It just sends trying, but no the others? Or 
will they be queued, so only trying, and 5 seconds later, terminated is 
sent?
</PRE>
</BLOCKQUOTE>
I don't understand what this has to do with calls.&nbsp; I am just talking about NOTIFY requests from presence after a change in presentity or a SUBSCRIBE.<BR>
<BR>
<BLOCKQUOTE TYPE=CITE>
<PRE>
&gt;
&gt; I would like to add this to the presence module (making the rate
&gt; configurable).
&gt;
&gt; I have an idea as to how I would like to do it:
&gt; - Add a last notified time-stamp field to each presentity
&gt; - Add a updated since last notified flag field to each presentity
&gt; - Add a notify required flag field to each active_watcher
&gt;
&gt; - When a presentity is updated the last notified time-stamp is checked.
&gt; If the time is far enough in the past the notifies are sent and the
&gt; time-stamp is updated.  If enough time has not passed the updated since
&gt; flag is set for the presentity and the notify required flag is set for all
&gt; active_watchers of that presentity.
&gt; - When a presentity is subscribed to (this includes re-subscribes) the
&gt; last notified time-stamp is checked.  If the time is far enough in the
&gt; past the (single) notify is sent and the time-stamp is updated.  If enough
&gt; time has not passed the updated since flag is set for the presentity and
&gt; the notify required flag is set for this active_watcher record.

RFC3265 states that a NOTIFY MUST sent immediately after every SUBSCRIBE.

</PRE>
</BLOCKQUOTE>
Ah...&nbsp; But define immediately.&nbsp; A 2XX response should also be sent immediately after every SUBSCRIBE, but the timeout is 64*T1 (32 seconds).&nbsp; So a NOTIFY that, in many cases, comes out right away, or in the worst case within 5 to 10 seconds, should count as immediate.<BR>
<BR>
<BLOCKQUOTE TYPE=CITE>
<PRE>
&gt; - A timer (the minimum time between subscribes - default 5 seconds) is
&gt; run.  On expiry a query is done on the presentity table for presentities
&gt; that have been updated _AND_ the last notified time is more than the
&gt; minimum time ago.  For each of these presentities, a query is done on the
&gt; active_watchers for watchers of that presentity that have the notify
&gt; required flag set.  Notifies containing the presentities are then sent to
&gt; the watchers waiting on them.
&gt;
&gt; This should ensure that no presentity notifies more than it should, while
&gt; ensuring that all changes are (eventually) sent out, and all subscribes
&gt; result in a notify (eventually) being sent.  Eventually being typically
&gt; within 5 seconds and in under 10 seconds in the worst case (assuming the
&gt; default setting of 5 seconds).
&gt;
&gt; Can anyone see any problems with this?

I wonder why you delay NOTIFYs for (re)SUBSCRIBEs? On (re)SUBSCRIBEs 
just NOTIFY with last published state and do not set the &quot;notify 
required&quot; flag. Then it may happen that the minimum NOTIFY interval is 
not maintained the first few seconds after a (re)SUBSCRIBE but IMO this 
is not that bad and enables immediate notification after every 
(re)SUBSCRIBE.

</PRE>
</BLOCKQUOTE>
As you say, if I receive a PUBLISH and then a re-SUBSCRIBE to a presentity then I will send out NOTIFYs too often.&nbsp; I have seen (bad) clients that re-PUBLISH immediately before re-SUBSCRIBE and un-PUBLISH immediately before un-SUBSCRIBE.&nbsp; If a lot of people use these bad clients then you have a problem.<BR>
<BR>
<BLOCKQUOTE TYPE=CITE>
<PRE>
&gt; Are there any objections to me implementing this?

Make it configurable :-) E.g. setting &quot;minimum_notification_delay&quot; to 0 
disables the feature.

</PRE>
</BLOCKQUOTE>
Of course <IMG SRC="cid:1333095300.2773.6.camel@pd-laptop-linux" ALIGN="middle" ALT=":-)" BORDER="0"><BR>
<BR>
<BLOCKQUOTE TYPE=CITE>
<PRE>
It may also increase DB load and cause more race-conditions (to be 
resolved with DB-transactions) due to more DB lookups.

</PRE>
</BLOCKQUOTE>
It also helps with a race condition I think I am seeing (and similar to that recently discussed on this list) where you can have more than one NOTIFY outstanding on a dialog at a time, and if these get out of sequence then you do definitely get problems.<BR>
<BR>
While there may be more DB load overall, I suspect that because this helps spread it out somewhat it should make the performance more even.&nbsp; Also many of these queries will be much simpler and lighter as I do not need to always retrieve the presentity field, which is particularly large.<BR>
<BR>
<BLOCKQUOTE TYPE=CITE>
<PRE>
E.g. what if the timer finds a presentity for which NOTIFYs needs to be 
sent and - while iterating over all the presentities - a new PUBLISH is 
received which triggers immediate NOTIFY. It may happen that both 
processes manipulate the active watchers table at the same time (notify 
required flag).
</PRE>
</BLOCKQUOTE>
Is this not also a problem with rls_presentity which uses a very similar mechanism already?<BR>
<BR>
<BLOCKQUOTE TYPE=CITE>
<PRE>

&gt; In theory running a (5 second) timer could make presence &quot;lumpy&quot; in the
&gt; same way RLS is (see my previous email).  However, if this proves to be
&gt; the case I believe the same mechanism I have proposed for RLS can be used
&gt; here.

Why run the timer only every 5 seconds? Run it every second (or 100ms) 
then it should not be lumpy anymore.
</PRE>
</BLOCKQUOTE>
<BR>
<BLOCKQUOTE TYPE=CITE>
<PRE>
regards
Klaus
</PRE>
</BLOCKQUOTE>
<BR>
<TABLE CELLSPACING="0" CELLPADDING="0" WIDTH="100%">
<TR>
<TD>
<PRE>
-- 
Peter Dunkley
Technical Director
Crocodile RCS Ltd
</PRE>
</TD>
</TR>
</TABLE>
</BODY>
</HTML>