telefonicaid / fiware-orion

Context Broker and CEF building block for context data management, providing NGSI interfaces.
https://github.com/telefonicaid/fiware-orion/blob/master/doc/manuals/orion-api.md
GNU Affero General Public License v3.0
210 stars 265 forks source link

Notification flow control on update #3568

Closed fgalan closed 4 years ago

fgalan commented 5 years ago

Sometimes (especially with batch updates, i.e. POST /v2/op/update) a single update may trigger a large set of notifications which take some time to be processed (e.g. due to the receiver doesn't responses immediately). If the sender of the updates goes faster than notification processing (due to Orion responses immediately to the update sender, without waiting for notification finalization) this can cause saturation problems (typically, the notification queue gets full and new notifications are discarded). Thus, some flow control mechanism is needed.

Let's consider a flow control algorithm with depends on three parameters: notifications coefficient (C) from 0 to 1, evaluation step (S) in milliseconds, maximum time (M) in milliseconds.

The algorith is as follows:

  1. When start to processing the update, get the current value of the notification queue. Let's name that value Q_0
  2. During the processing of the update, count how many subscriptions are triggered (i.e. how many subscriptions are added to the notification queue). Let's name that value N.
  3. Now that the processing as ended:
    1. Gets the new value of the queue: Q_i
    2. If Q_i <= Q_0 +(1 - C) * N then go to 4. Else wait for form S milliseconds and continue to 3.iii.
      • Note that if C = 1 corresponds to highest flow control. In this case: Q_i <= Q_0, that is: the size of the queue as large as we found it at the start of the update.
      • Note that If C = 0 corresponds to lowest flow control. In this case: Q_i <= Q_0 + N, that is: we won't want to wait for any of the notifications to be processed (regarding the initial size of the queue at the start of the update).
    3. If the cumulative wait time is more than M, then go to 4. Otherwise, go back to 3.i (a value of 0 for M could mean always go to 3.1).
  4. Orion response to the client of the update

Additional notes:

mrutid commented 5 years ago

OK

fgalan commented 4 years ago

Implemented by PR https://github.com/telefonicaid/fiware-orion/pull/3577