title: Performance degrade issue using ActiveMQ scheduler
body: <p>In one of our project we are suffering for ActiveMQ performance degrade when we use the schedule facility (enabling schedulerSupport in ActiveMQ configuration) with high amount of message (1M or more). The project is Spring based, and we are, also, using Camel for routes management.</p>
  
  <p>Our routes are configured as follow:</p>
  
  <ul>
  <li>a producer P produces 800 messages/sec and sends them through a non persistent ActiveMQ queue Q</li>
  <li>a consumer Cq processes messages from Q according to the following rule: for each message it verifies if the message can be process immediately (every message has a time-window attribute to define that). If it's possible, Cq forwards the message to the Throttling queue T; if it's not, Cq forwards the messages into a support queue S</li>
  <li>a consumer Cs processes messages from S and it schedules the message according to its time-window (setting the ActiveMQ property <code>ScheduledMessage.AMQ_SCHEDULED_DELAY</code> with the following statement: <code>message.setLongProperty(ScheduledMessage.AMQ_SCHEDULED_DELAY, &lt;delay&gt;);</code>) where <code>&lt;delay&gt;</code> is evaluated according to the message time-window</li>
  <li>when a scheduled message wakes up from the ActiveMQ scheduled-area, it is forwarded to the Throttling queue T</li>
  <li>the consumer Ct processes the message from T using a third parties component (via TCP connection)</li>
  </ul>
  
  <p>When P produces messages for immediate processing (i.e., without time-window) the system performs well even with an high amount of messages (1M or more): monitoring the queues we can see them almost empty (no message stays pending in any queue).</p>
  
  <p>When P produces messages for delayed processing (i.e., with time-window) we see the following behavior:</p>
  
  <ul>
  <li>we have messages pending in all the queues (Q and S), while we expect to have them pending only on the queue S</li>
  <li>when the message scheduled in S wakes up they moves to the T queue: these messages are processed according to the throttling configuration (1K messages/sec)</li>
  <li>the message still pending in Q and S move very slowly to T (around 50 messages/sec)</li>
  <li>in case we try a second round of messages (without time-window) just after all the precious messages have been processed (using, again the producer P), we still sending out messages to 50 messages/sec even if, in this case, we are not using the scheduled-area at all</li>
  </ul>
  
  <p><strong>Summary of the issue</strong></p>
  
  <ul>
  <li>ActiveMQ version: 5.9.0 (configured with 3GB of max memory limit)</li>
  <li>Camel version: 2.15.1</li>
  <li>Spring version: 4.1.3.RELEASE</li>
  <li>average dimension of 1 message: 4.5KiB</li>
  <li>Critical routes:
  <ul>
  <li><em>Q -> S (scheduled-area) -> T</em> </li>
  <li><em>Q -> T</em> (after the use of the scheduled-area)</li>
  </ul></li>
  <li>Without using scheduler: within 1M messages, we process easily 1K messages/sec (the limit depends from a Camel Throttling queue)</li>
  <li>Using scheduler: within 1M messages, we process 50 messages/sec</li>
  <li>Monitoring CPUs and memory usage, we cannot spot-out any issue: from 2% to 5% of CPUs usage and we never go out-of-memory (the Java GC seems works fine too)</li>
  <li>Hardware (virtualized based on VMWare):
  <ul>
  <li>CPUs: 24 vCPUs mapped on 24 real 'Intel(R) Xeon(R) CPU E5-2680 v3 @ 2.50GHz' CPUs</li>
  <li>Ram: 31744MB</li>
  </ul></li>
  </ul>
  
  <p>cheers and thanks in advance for your help,</p>
  
  <p>Eros</p>