Class ControlRate
java.lang.Object
org.apache.nifi.components.AbstractConfigurableComponent
org.apache.nifi.processor.AbstractSessionFactoryProcessor
org.apache.nifi.processor.AbstractProcessor
org.apache.nifi.processors.standard.ControlRate
- All Implemented Interfaces:
org.apache.nifi.components.ConfigurableComponent
,org.apache.nifi.processor.Processor
@SideEffectFree
@TriggerSerially
@InputRequirement(INPUT_REQUIRED)
@Tags({"rate control","throttle","rate","throughput"})
@CapabilityDescription("Controls the rate at which data is transferred to follow-on processors. If you configure a very small Time Duration, then the accuracy of the throttle gets worse. You can improve this accuracy by decreasing the Yield Duration, at the expense of more Tasks given to the processor.")
@UseCase(description="Limit the rate at which data is sent to a downstream system with little to no bursts",keywords={"throttle","limit","slow down","data rate"},configuration="Set the \"Rate Control Criteria\" to `data rate`.\nSet the \"Time Duration\" property to `1 sec`.\nConfigure the \"Maximum Rate\" property to specify how much data should be allowed through each second.\n\nFor example, to allow through 8 MB per second, set \"Maximum Rate\" to `8 MB`.\n") @UseCase(description="Limit the rate at which FlowFiles are sent to a downstream system with little to no bursts",keywords={"throttle","limit","slow down","flowfile rate"},configuration="Set the \"Rate Control Criteria\" to `flowfile count`.\nSet the \"Time Duration\" property to `1 sec`.\nConfigure the \"Maximum Rate\" property to specify how many FlowFiles should be allowed through each second.\n\nFor example, to allow through 100 FlowFiles per second, set \"Maximum Rate\" to `100`.\n") @UseCase(description="Reject requests that exceed a specific rate with little to no bursts",keywords={"throttle","limit","slow down","request rate"},configuration="Set the \"Rate Control Criteria\" to `flowfile count`.\nSet the \"Time Duration\" property to `1 sec`.\nSet the \"Rate Exceeded Strategy\" property to `Route to \'rate exceeded\'`.\nConfigure the \"Maximum Rate\" property to specify how many requests should be allowed through each second.\n\nFor example, to allow through 100 requests per second, set \"Maximum Rate\" to `100`.\nIf more than 100 requests come in during any one second, the additional requests will be routed to `rate exceeded` instead of `success`.\n") @UseCase(description="Reject requests that exceed a specific rate, allowing for bursts",keywords={"throttle","limit","slow down","request rate"},configuration="Set the \"Rate Control Criteria\" to `flowfile count`.\nSet the \"Time Duration\" property to `1 min`.\nSet the \"Rate Exceeded Strategy\" property to `Route to \'rate exceeded\'`.\nConfigure the \"Maximum Rate\" property to specify how many requests should be allowed through each minute.\n\nFor example, to allow through 100 requests per second, set \"Maximum Rate\" to `6000`.\nThis will allow through 6,000 FlowFiles per minute, which averages to 100 FlowFiles per second. However, those 6,000 FlowFiles may come all within the first couple of\nseconds, or they may come in over a period of 60 seconds. As a result, this gives us an average rate of 100 FlowFiles per second but allows for bursts of data.\nIf more than 6,000 requests come in during any one minute, the additional requests will be routed to `rate exceeded` instead of `success`.\n")
public class ControlRate
extends org.apache.nifi.processor.AbstractProcessor
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static class
private class
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final String
static final org.apache.nifi.components.AllowableValue
private final ConcurrentMap
<String, ControlRate.Throttle> static final String
static final org.apache.nifi.components.AllowableValue
static final String
static final org.apache.nifi.components.AllowableValue
private final ConcurrentMap
<String, ControlRate.Throttle> private static final long
private static final String
private static final Set
<org.apache.nifi.processor.Relationship> static final String
static final org.apache.nifi.components.AllowableValue
static final org.apache.nifi.components.PropertyDescriptor
private String
(package private) static final org.apache.nifi.components.AllowableValue
private final AtomicLong
static final org.apache.nifi.components.PropertyDescriptor
static final org.apache.nifi.components.PropertyDescriptor
static final int
static final org.apache.nifi.components.PropertyDescriptor
private String
private String
private static final Pattern
private static final List
<org.apache.nifi.components.PropertyDescriptor> static final org.apache.nifi.components.PropertyDescriptor
static final org.apache.nifi.components.PropertyDescriptor
private static final Set
<org.apache.nifi.processor.Relationship> static final org.apache.nifi.components.PropertyDescriptor
private String
private String
(package private) static final org.apache.nifi.processor.Relationship
(package private) static final org.apache.nifi.processor.Relationship
(package private) static final org.apache.nifi.processor.Relationship
private Set
<org.apache.nifi.processor.Relationship> (package private) static final org.apache.nifi.components.AllowableValue
static final org.apache.nifi.components.PropertyDescriptor
private int
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate void
clearExpiredThrottles
(org.apache.nifi.processor.ProcessContext context) private boolean
protected Collection
<org.apache.nifi.components.ValidationResult> customValidate
(org.apache.nifi.components.ValidationContext context) private boolean
private long
getCountAccrual
(org.apache.nifi.flowfile.FlowFile flowFile) protected long
Get current time in millisecondsprivate long
getDataSizeAccrual
(org.apache.nifi.flowfile.FlowFile flowFile) Set
<org.apache.nifi.processor.Relationship> protected List
<org.apache.nifi.components.PropertyDescriptor> private void
holdFlowFilesExceedingRate
(org.apache.nifi.processor.ProcessContext context, org.apache.nifi.processor.ProcessSession session) private boolean
isRateAttributeValid
(org.apache.nifi.flowfile.FlowFile flowFile) void
onPropertyModified
(org.apache.nifi.components.PropertyDescriptor descriptor, String oldValue, String newValue) void
onScheduled
(org.apache.nifi.processor.ProcessContext context) void
onTrigger
(org.apache.nifi.processor.ProcessContext context, org.apache.nifi.processor.ProcessSession session) private void
routeFlowFilesExceedingRate
(org.apache.nifi.processor.ProcessContext context, org.apache.nifi.processor.ProcessSession session) Methods inherited from class org.apache.nifi.processor.AbstractProcessor
onTrigger
Methods inherited from class org.apache.nifi.processor.AbstractSessionFactoryProcessor
getControllerServiceLookup, getIdentifier, getLogger, getNodeTypeProvider, init, initialize, isConfigurationRestored, isScheduled, toString, updateConfiguredRestoredTrue, updateScheduledFalse, updateScheduledTrue
Methods inherited from class org.apache.nifi.components.AbstractConfigurableComponent
equals, getPropertyDescriptor, getPropertyDescriptors, getSupportedDynamicPropertyDescriptor, hashCode, validate
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface org.apache.nifi.components.ConfigurableComponent
getPropertyDescriptor, getPropertyDescriptors, validate
Methods inherited from interface org.apache.nifi.processor.Processor
isStateful, migrateProperties, migrateRelationships
-
Field Details
-
DATA_RATE
- See Also:
-
FLOWFILE_RATE
- See Also:
-
ATTRIBUTE_RATE
- See Also:
-
DATA_OR_FLOWFILE_RATE
- See Also:
-
DATA_RATE_VALUE
public static final org.apache.nifi.components.AllowableValue DATA_RATE_VALUE -
FLOWFILE_RATE_VALUE
public static final org.apache.nifi.components.AllowableValue FLOWFILE_RATE_VALUE -
ATTRIBUTE_RATE_VALUE
public static final org.apache.nifi.components.AllowableValue ATTRIBUTE_RATE_VALUE -
DATA_OR_FLOWFILE_RATE_VALUE
public static final org.apache.nifi.components.AllowableValue DATA_OR_FLOWFILE_RATE_VALUE -
HOLD_FLOWFILE
static final org.apache.nifi.components.AllowableValue HOLD_FLOWFILE -
ROUTE_TO_RATE_EXCEEDED
static final org.apache.nifi.components.AllowableValue ROUTE_TO_RATE_EXCEEDED -
MAX_FLOW_FILES_PER_BATCH
public static final int MAX_FLOW_FILES_PER_BATCH- See Also:
-
DEFAULT_ACCRUAL_COUNT
private static final long DEFAULT_ACCRUAL_COUNT- See Also:
-
RATE_CONTROL_CRITERIA
public static final org.apache.nifi.components.PropertyDescriptor RATE_CONTROL_CRITERIA -
MAX_RATE
public static final org.apache.nifi.components.PropertyDescriptor MAX_RATE -
MAX_DATA_RATE
public static final org.apache.nifi.components.PropertyDescriptor MAX_DATA_RATE -
MAX_COUNT_RATE
public static final org.apache.nifi.components.PropertyDescriptor MAX_COUNT_RATE -
RATE_EXCEEDED_STRATEGY
public static final org.apache.nifi.components.PropertyDescriptor RATE_EXCEEDED_STRATEGY -
RATE_CONTROL_ATTRIBUTE_NAME
public static final org.apache.nifi.components.PropertyDescriptor RATE_CONTROL_ATTRIBUTE_NAME -
TIME_PERIOD
public static final org.apache.nifi.components.PropertyDescriptor TIME_PERIOD -
GROUPING_ATTRIBUTE_NAME
public static final org.apache.nifi.components.PropertyDescriptor GROUPING_ATTRIBUTE_NAME -
PROPERTIES
-
REL_SUCCESS
static final org.apache.nifi.processor.Relationship REL_SUCCESS -
REL_FAILURE
static final org.apache.nifi.processor.Relationship REL_FAILURE -
REL_RATE_EXCEEDED
static final org.apache.nifi.processor.Relationship REL_RATE_EXCEEDED -
DEFAULT_RELATIONSHIPS
-
RATE_EXCEEDED_RELATIONSHIPS
-
POSITIVE_LONG_PATTERN
-
DEFAULT_GROUP_ATTRIBUTE
-
relationships
-
dataThrottleMap
-
countThrottleMap
-
lastThrottleClearTime
-
rateControlCriteria
-
rateControlAttribute
-
maximumRateStr
-
maximumCountRateStr
-
groupingAttributeName
-
timePeriodSeconds
private volatile int timePeriodSeconds
-
-
Constructor Details
-
ControlRate
public ControlRate()
-
-
Method Details
-
getSupportedPropertyDescriptors
- Overrides:
getSupportedPropertyDescriptors
in classorg.apache.nifi.components.AbstractConfigurableComponent
-
getRelationships
- Specified by:
getRelationships
in interfaceorg.apache.nifi.processor.Processor
- Overrides:
getRelationships
in classorg.apache.nifi.processor.AbstractSessionFactoryProcessor
-
customValidate
protected Collection<org.apache.nifi.components.ValidationResult> customValidate(org.apache.nifi.components.ValidationContext context) - Overrides:
customValidate
in classorg.apache.nifi.components.AbstractConfigurableComponent
-
onPropertyModified
public void onPropertyModified(org.apache.nifi.components.PropertyDescriptor descriptor, String oldValue, String newValue) - Specified by:
onPropertyModified
in interfaceorg.apache.nifi.components.ConfigurableComponent
- Overrides:
onPropertyModified
in classorg.apache.nifi.components.AbstractConfigurableComponent
-
onScheduled
@OnScheduled public void onScheduled(org.apache.nifi.processor.ProcessContext context) -
onTrigger
public void onTrigger(org.apache.nifi.processor.ProcessContext context, org.apache.nifi.processor.ProcessSession session) throws org.apache.nifi.processor.exception.ProcessException - Specified by:
onTrigger
in classorg.apache.nifi.processor.AbstractProcessor
- Throws:
org.apache.nifi.processor.exception.ProcessException
-
routeFlowFilesExceedingRate
private void routeFlowFilesExceedingRate(org.apache.nifi.processor.ProcessContext context, org.apache.nifi.processor.ProcessSession session) -
holdFlowFilesExceedingRate
private void holdFlowFilesExceedingRate(org.apache.nifi.processor.ProcessContext context, org.apache.nifi.processor.ProcessSession session) -
clearExpiredThrottles
private void clearExpiredThrottles(org.apache.nifi.processor.ProcessContext context) -
getCurrentTimeMillis
protected long getCurrentTimeMillis()Get current time in milliseconds- Returns:
- Current time in milliseconds from System
-
isRateAttributeValid
private boolean isRateAttributeValid(org.apache.nifi.flowfile.FlowFile flowFile) -
getDataSizeAccrual
private long getDataSizeAccrual(org.apache.nifi.flowfile.FlowFile flowFile) -
getCountAccrual
private long getCountAccrual(org.apache.nifi.flowfile.FlowFile flowFile) -
dataThrottleRequired
private boolean dataThrottleRequired() -
countThrottleRequired
private boolean countThrottleRequired()
-