[ 
https://issues.apache.org/jira/browse/NIFI-16633?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Xinyu Wang updated NIFI-16633:
------------------------------
    Description: 
When a processor is set to Execution = Primary node and the node isn't the 
primary node, ConnectableTask skips the invocation and returns a yield result, 
but it doesn't yield the component:

{code:java}
if (!isRunOnCluster(flowController)) {
    ...
    return NOT_PRIMARY_NODE_YIELD_RESULT;   // InvocationResult.yield("This 
node is not the primary node")
}
{code}

TimerDrivenSchedulingAgent only reschedules after the component's own yield if 
connectable.getYieldExpiration() is in the future, which means the component 
has to have called yield(). Any other yield result is rescheduled after 
nifi.bored.yield.duration (10 ms by default). Nothing calls connectable.yield() 
on this path, so a Primary-only processor that is RUNNING on a non-primary node 
gets retried about every 10 ms, no matter what its scheduling period or Yield 
Duration (1 sec by default) is.

Every retry calls isPrimary(), which asks the LeaderElectionManager whether 
this node is the primary node.

The bored yield makes sense for a processor that has no work, because there 
might be work on the next trigger. Here the reason for skipping is the role of 
the node, which doesn't change until the leadership changes, so no new data on 
this node can make the processor run. That's why this case looks different to 
me.

h3. Observed

3-node cluster on EKS, 100 timer-driven threads, about 30 Primary-only 
processors RUNNING (about 290 before part of them were stopped) and several 
thousand RUNNING processors in total.

* {{nifi.sh diagnostics}} shows the Leader Election service being polled about 
170,000 times in 5 minutes on a non-primary node and about 73,000 times on the 
primary node. The difference is about 98,000 polls (roughly 330 per second). 
With a 1 second yield, about 30 processors would only account for around 9,000 
polls in 5 minutes, so it's about ten times higher.

These numbers come from a 2.5.0 based build. The relevant code is the same in 
2.12.0 and main.

h3. Questions

# Is it intentional that the not-primary path uses the bored yield duration, 
and not the Yield Duration of the processor or its scheduling period?
# Would calling connectable.yield() here be acceptable, so that a Primary-only 
processor on a non-primary node is retried after its Yield Duration?

h3. Trade-off

A longer interval delays the first run on a node that becomes the primary node. 
With the default Yield Duration of 1 sec, a processor could start up to about 1 
sec later after a failover than it does with the 10 ms retry. If that matters, 
the yield could be capped at a smaller value, or only applied to timer-driven 
components.

Cron-driven components aren't affected by the 10 ms retry, since their next 
trigger comes from the cron schedule.

  was:
When a processor is configured with Execution = Primary node and the node is 
not the primary node, ConnectableTask skips the invocation and returns a yield 
result, but it does not yield the component:

{code:java}
if (!isRunOnCluster(flowController)) {
    ...
    return NOT_PRIMARY_NODE_YIELD_RESULT;   // InvocationResult.yield("This 
node is not the primary node")
}
{code}

TimerDrivenSchedulingAgent reschedules the task after the component's yield 
only if connectable.getYieldExpiration() is in the future, which requires the 
component to have called yield(). For any other yield result it reschedules the 
task after nifi.bored.yield.duration (default 10 ms). Since nothing calls 
connectable.yield() on this path, a Primary-only processor that is RUNNING on a 
non-primary node is retried about every 10 ms, regardless of its scheduling 
period and of its configured Yield Duration (default 1 sec).

Each retry calls isPrimary(), which asks the LeaderElectionManager whether this 
node is the primary node.

This looks different from the usual case that the bored yield is designed for. 
For a processor without work, the node could have work on the next trigger, so 
a short retry is reasonable. Here the reason for skipping is the node role, 
which does not change until the leadership changes, and no new data on this 
node can make the processor run.

h3. Observed

On a 3-node cluster running on EKS, with 100 timer-driven threads, about 30 
Primary-only processors in the RUNNING state (about 290 before part of them 
were stopped), and several thousand RUNNING processors in total:

* {{nifi.sh diagnostics}} shows the Leader Election service being polled about 
170,000 times in 5 minutes on a non-primary node and about 73,000 times on the 
primary node. The difference is about 98,000 polls (roughly 330 per second). 
With a 1 second yield, about 30 processors would only account for around 9,000 
polls in 5 minutes, so this is about ten times higher.

These numbers were measured on a 2.5.0 based build. The relevant code is the 
same in 2.12.0 and main.

h3. Questions

# Is it intended that the not-primary-node path uses the bored yield duration, 
rather than the Yield Duration of the processor or its scheduling period?
# Would it be acceptable to call connectable.yield() in this case, so that a 
Primary-only processor on a non-primary node is retried after its Yield 
Duration?

h3. Trade-off

A longer retry interval delays the first run on a node that becomes the primary 
node. With the default Yield Duration of 1 sec, a processor could start up to 
about 1 sec later after a failover than with the 10 ms retry. If that delay is 
a concern, the yield could be limited to a smaller value or only apply to 
timer-driven components.

Cron-driven components are not affected by the 10 ms retry, because the next 
trigger is determined by the cron schedule.


> Primary-only processors on non-primary nodes are rescheduled every 
> nifi.bored.yield.duration instead of using the yield duration
> --------------------------------------------------------------------------------------------------------------------------------
>
>                 Key: NIFI-16633
>                 URL: https://issues.apache.org/jira/browse/NIFI-16633
>             Project: Apache NiFi
>          Issue Type: Improvement
>          Components: Core Framework
>    Affects Versions: 2.12.0
>            Reporter: Xinyu Wang
>            Priority: Minor
>
> When a processor is set to Execution = Primary node and the node isn't the 
> primary node, ConnectableTask skips the invocation and returns a yield 
> result, but it doesn't yield the component:
> {code:java}
> if (!isRunOnCluster(flowController)) {
>     ...
>     return NOT_PRIMARY_NODE_YIELD_RESULT;   // InvocationResult.yield("This 
> node is not the primary node")
> }
> {code}
> TimerDrivenSchedulingAgent only reschedules after the component's own yield 
> if connectable.getYieldExpiration() is in the future, which means the 
> component has to have called yield(). Any other yield result is rescheduled 
> after nifi.bored.yield.duration (10 ms by default). Nothing calls 
> connectable.yield() on this path, so a Primary-only processor that is RUNNING 
> on a non-primary node gets retried about every 10 ms, no matter what its 
> scheduling period or Yield Duration (1 sec by default) is.
> Every retry calls isPrimary(), which asks the LeaderElectionManager whether 
> this node is the primary node.
> The bored yield makes sense for a processor that has no work, because there 
> might be work on the next trigger. Here the reason for skipping is the role 
> of the node, which doesn't change until the leadership changes, so no new 
> data on this node can make the processor run. That's why this case looks 
> different to me.
> h3. Observed
> 3-node cluster on EKS, 100 timer-driven threads, about 30 Primary-only 
> processors RUNNING (about 290 before part of them were stopped) and several 
> thousand RUNNING processors in total.
> * {{nifi.sh diagnostics}} shows the Leader Election service being polled 
> about 170,000 times in 5 minutes on a non-primary node and about 73,000 times 
> on the primary node. The difference is about 98,000 polls (roughly 330 per 
> second). With a 1 second yield, about 30 processors would only account for 
> around 9,000 polls in 5 minutes, so it's about ten times higher.
> These numbers come from a 2.5.0 based build. The relevant code is the same in 
> 2.12.0 and main.
> h3. Questions
> # Is it intentional that the not-primary path uses the bored yield duration, 
> and not the Yield Duration of the processor or its scheduling period?
> # Would calling connectable.yield() here be acceptable, so that a 
> Primary-only processor on a non-primary node is retried after its Yield 
> Duration?
> h3. Trade-off
> A longer interval delays the first run on a node that becomes the primary 
> node. With the default Yield Duration of 1 sec, a processor could start up to 
> about 1 sec later after a failover than it does with the 10 ms retry. If that 
> matters, the yield could be capped at a smaller value, or only applied to 
> timer-driven components.
> Cron-driven components aren't affected by the 10 ms retry, since their next 
> trigger comes from the cron schedule.



--
This message was sent by Atlassian Jira
(v10.3.26#10030026)

Reply via email to