markobean commented on code in PR #6506:
URL: https://github.com/apache/nifi/pull/6506#discussion_r1018464607
##########
nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/ControlRate.java:
##########
@@ -408,34 +498,59 @@ public FlowFileFilterResult filter(FlowFile flowFile) {
groupName = DEFAULT_GROUP_ATTRIBUTE;
}
- Throttle throttle = throttleMap.get(groupName);
- if (throttle == null) {
- throttle = new Throttle(timePeriodSeconds, TimeUnit.SECONDS,
getLogger());
+ Throttle dataThrottle = dataThrottleMap.get(groupName);
+ Throttle countThrottle = countThrottleMap.get(groupName);
- final long newRate;
- if
(DataUnit.DATA_SIZE_PATTERN.matcher(maximumRateStr).matches()) {
- newRate = DataUnit.parseDataSize(maximumRateStr,
DataUnit.B).longValue();
- } else {
- newRate = Long.parseLong(maximumRateStr);
+ boolean dataThrottlingActive = false;
+ if (dataThrottleRequired()) {
+ if (dataThrottle == null) {
+ dataThrottle = new Throttle(timePeriodSeconds,
TimeUnit.SECONDS, getLogger());
+
dataThrottle.setMaxRate(DataUnit.parseDataSize(maximumRateStr,
DataUnit.B).longValue());
+ dataThrottleMap.put(groupName, dataThrottle);
}
- throttle.setMaxRate(newRate);
- throttleMap.put(groupName, throttle);
+ dataThrottle.lock();
+ try {
+ if (dataThrottle.tryAdd(getDataSizeAccrual(flowFile))) {
+ flowFilesInBatch += 1;
+ if (flowFilesInBatch>= flowFilesPerBatch) {
+ flowFilesInBatch = 0;
+ return FlowFileFilterResult.ACCEPT_AND_TERMINATE;
+ } else {
+ // only accept flowfile if additional count
throttle does not need to run
+ if (!countThrottleRequired()) {
+ return
FlowFileFilterResult.ACCEPT_AND_CONTINUE;
+ }
+ }
+ } else {
+ dataThrottlingActive = true;
+ }
+ } finally {
+ dataThrottle.unlock();
+ }
}
- throttle.lock();
- try {
- if (throttle.tryAdd(accrual)) {
- flowFilesInBatch += 1;
- if (flowFilesInBatch>= flowFilesPerBatch) {
- flowFilesInBatch = 0;
- return FlowFileFilterResult.ACCEPT_AND_TERMINATE;
- } else {
- return FlowFileFilterResult.ACCEPT_AND_CONTINUE;
+ // continue processing count throttle only if required and if data
throttle is not already limiting flowfiles
+ if (countThrottleRequired() && !dataThrottlingActive) {
+ if (countThrottle == null) {
+ countThrottle = new Throttle(timePeriodSeconds,
TimeUnit.SECONDS, getLogger());
+
countThrottle.setMaxRate(Long.parseLong(maximumCountRateStr));
+ countThrottleMap.put(groupName, countThrottle);
+ }
+ countThrottle.lock();
+ try {
+ if (countThrottle.tryAdd(getCountAccrual(flowFile))) {
+ flowFilesInBatch += 1;
Review Comment:
Done.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]