Uploaded image for project: 'Camel'
  1. Camel
  2. CAMEL-9355

Current Throttler implementation is not accurate and does not work in a multi-threaded route

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Resolved
    • Major
    • Resolution: Fixed
    • 2.16.0
    • 2.17.0
    • camel-core, eip
    • None
    • Patch Available
    • Unknown
    • Patch

    Description

      Current Throttler implementation is not accurate and is even more inaccurate in a multi-threaded route (think sjms....consumerCount=100).

      The delay to sleep cannot be calculated ahead of time in a multi-threaded environment, to this end the Throttler should not extend DelayProcessorSupport.

      Attached is a patch that changes throttler to use a Semaphore to do accurate and multi-thread safe throttling.

      The code I think is much cleaner, smaller and easier to understand. Than it used to be before.

      Unit tests still pass, I had to make some changes to ThrottlerTest as it made assumptions about the implementation and was doing bad things like adding a 750ms buffer to validating the minimum throttle delay.. ThrottlerTest is now very sane.

      I've also implemented support to allow the throttler construct to be used without any nested outputs. For example the follow code is now valid.

      <throttle><constant>100</constant></throttle> 
      

      If you want to disable this feature it can be done in ThrottlerDefinition::createProcessor() line 82 changing false to true.

      I think this allows more flexible usage of the throttler, in my use case I want to delay the further execution of the route, and I don't want to have to split my routes up into separate sub-routes to be able to do that.

      Attachments

        1. CAMEL_9355.patch
          38 kB
          Aaron Whiteside
        2. CAMEL_9355v2.patch
          41 kB
          Aaron Whiteside
        3. CAMEL_9355v3.patch
          40 kB
          Aaron Whiteside

        Activity

          People

            davsclaus Claus Ibsen
            aaronjwhiteside Aaron Whiteside
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: