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 TypeClassDescription(package private) static enumprivate static classprivate class -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final ConcurrentMap<String, ControlRate.Throttle> private final ConcurrentMap<String, ControlRate.Throttle> private static final longprivate static final Stringprivate static final Set<org.apache.nifi.processor.Relationship> static final org.apache.nifi.components.PropertyDescriptorprivate String(package private) static final org.apache.nifi.components.AllowableValueprivate final AtomicLongstatic final org.apache.nifi.components.PropertyDescriptorstatic final org.apache.nifi.components.PropertyDescriptorstatic final intstatic final org.apache.nifi.components.PropertyDescriptorprivate Stringprivate Stringprivate static final Patternprivate static final List<org.apache.nifi.components.PropertyDescriptor> static final org.apache.nifi.components.PropertyDescriptorstatic final org.apache.nifi.components.PropertyDescriptorprivate static final Set<org.apache.nifi.processor.Relationship> static final org.apache.nifi.components.PropertyDescriptorprivate Stringprivate ControlRate.RateControlCriteria(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.Relationshipprivate Set<org.apache.nifi.processor.Relationship> (package private) static final org.apache.nifi.components.AllowableValuestatic final org.apache.nifi.components.PropertyDescriptorprivate int -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate voidclearExpiredThrottles(org.apache.nifi.processor.ProcessContext context) private booleanprotected Collection<org.apache.nifi.components.ValidationResult> customValidate(org.apache.nifi.components.ValidationContext context) private booleanprivate longgetCountAccrual(org.apache.nifi.flowfile.FlowFile flowFile) protected longGet current time in millisecondsprivate longgetDataSizeAccrual(org.apache.nifi.flowfile.FlowFile flowFile) Set<org.apache.nifi.processor.Relationship> protected List<org.apache.nifi.components.PropertyDescriptor> private voidholdFlowFilesExceedingRate(org.apache.nifi.processor.ProcessContext context, org.apache.nifi.processor.ProcessSession session) private booleanisRateAttributeValid(org.apache.nifi.flowfile.FlowFile flowFile) voidonPropertyModified(org.apache.nifi.components.PropertyDescriptor descriptor, String oldValue, String newValue) voidonScheduled(org.apache.nifi.processor.ProcessContext context) voidonTrigger(org.apache.nifi.processor.ProcessContext context, org.apache.nifi.processor.ProcessSession session) private voidrouteFlowFilesExceedingRate(org.apache.nifi.processor.ProcessContext context, org.apache.nifi.processor.ProcessSession session) Methods inherited from class org.apache.nifi.processor.AbstractProcessor
onTriggerMethods inherited from class org.apache.nifi.processor.AbstractSessionFactoryProcessor
getControllerServiceLookup, getIdentifier, getLogger, getNodeTypeProvider, init, initialize, isConfigurationRestored, isScheduled, toString, updateConfiguredRestoredTrue, updateScheduledFalse, updateScheduledTrueMethods inherited from class org.apache.nifi.components.AbstractConfigurableComponent
equals, getPropertyDescriptor, getPropertyDescriptors, getSupportedDynamicPropertyDescriptor, hashCode, validateMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface org.apache.nifi.components.ConfigurableComponent
getPropertyDescriptor, getPropertyDescriptors, validateMethods inherited from interface org.apache.nifi.processor.Processor
isStateful, migrateProperties, migrateRelationships
-
Field Details
-
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 -
PROPERTY_DESCRIPTORS
-
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:
getSupportedPropertyDescriptorsin classorg.apache.nifi.components.AbstractConfigurableComponent
-
getRelationships
- Specified by:
getRelationshipsin interfaceorg.apache.nifi.processor.Processor- Overrides:
getRelationshipsin classorg.apache.nifi.processor.AbstractSessionFactoryProcessor
-
customValidate
protected Collection<org.apache.nifi.components.ValidationResult> customValidate(org.apache.nifi.components.ValidationContext context) - Overrides:
customValidatein classorg.apache.nifi.components.AbstractConfigurableComponent
-
onPropertyModified
public void onPropertyModified(org.apache.nifi.components.PropertyDescriptor descriptor, String oldValue, String newValue) - Specified by:
onPropertyModifiedin interfaceorg.apache.nifi.components.ConfigurableComponent- Overrides:
onPropertyModifiedin 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:
onTriggerin 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()
-