[ 
https://issues.apache.org/jira/browse/CAMEL-12418?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16442054#comment-16442054
 ] 

ASF GitHub Bot commented on CAMEL-12418:
----------------------------------------

davsclaus closed pull request #2283: CAMEL-12418: High CPU load on events 
watching
URL: https://github.com/apache/camel/pull/2283
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git 
a/components/camel-consul/src/main/java/org/apache/camel/component/consul/endpoint/ConsulEventConsumer.java
 
b/components/camel-consul/src/main/java/org/apache/camel/component/consul/endpoint/ConsulEventConsumer.java
index 2e8a141e0bb..7133fec5df3 100644
--- 
a/components/camel-consul/src/main/java/org/apache/camel/component/consul/endpoint/ConsulEventConsumer.java
+++ 
b/components/camel-consul/src/main/java/org/apache/camel/component/consul/endpoint/ConsulEventConsumer.java
@@ -18,6 +18,8 @@
 
 import java.math.BigInteger;
 import java.util.List;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.TimeUnit;
 
 import com.orbitz.consul.Consul;
 import com.orbitz.consul.EventClient;
@@ -28,14 +30,19 @@
 import org.apache.camel.Exchange;
 import org.apache.camel.Message;
 import org.apache.camel.Processor;
+import org.apache.camel.spi.ExecutorServiceManager;
 import org.apache.camel.component.consul.ConsulConfiguration;
 import org.apache.camel.component.consul.ConsulConstants;
 import org.apache.camel.component.consul.ConsulEndpoint;
 
 public final class ConsulEventConsumer extends 
AbstractConsulConsumer<EventClient> {
+    private ExecutorServiceManager executorServiceManager;
+    private ScheduledExecutorService scheduledExecutorService;
 
     public ConsulEventConsumer(ConsulEndpoint endpoint, ConsulConfiguration 
configuration, Processor processor) {
         super(endpoint, configuration, processor, Consul::eventClient);
+        this.executorServiceManager = 
endpoint.getCamelContext().getExecutorServiceManager();
+        this.scheduledExecutorService = 
this.executorServiceManager.newSingleThreadScheduledExecutor(this, 
"ConsulEventConsumer");
     }
 
     @Override
@@ -43,22 +50,34 @@ protected Runnable createWatcher(EventClient client) throws 
Exception {
         return new EventWatcher(client);
     }
 
+    @Override
+    protected void doStop() throws Exception {
+        executorServiceManager.shutdownGraceful(scheduledExecutorService);
+        super.doStop();
+    }
+
     // 
*************************************************************************
     // Watch
     // 
*************************************************************************
 
     private class EventWatcher extends AbstractWatcher implements 
EventResponseCallback {
+
         EventWatcher(EventClient client) {
             super(client);
         }
 
         @Override
-        public void watch(EventClient client) {
-            client.listEvents(
-                key,
-                QueryOptions.blockSeconds(configuration.getBlockSeconds(), 
index.get()).build(),
-                this
-            );
+        public void watch(final EventClient client) {
+            scheduledExecutorService.schedule(new Runnable() {
+                @Override
+                public void run() {
+                    client.listEvents(
+                        key,
+                        
QueryOptions.blockSeconds(configuration.getBlockSeconds(), index.get()).build(),
+                        EventWatcher.this
+                    );
+                }
+            }, configuration.getBlockSeconds(), TimeUnit.SECONDS);
         }
 
         @Override


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


> camel-consul - High CPU load on events watching
> -----------------------------------------------
>
>                 Key: CAMEL-12418
>                 URL: https://issues.apache.org/jira/browse/CAMEL-12418
>             Project: Camel
>          Issue Type: Bug
>          Components: camel-consul
>    Affects Versions: 2.21.0
>            Reporter: Viachaslau Tsikhanovich
>            Priority: Major
>             Fix For: 2.22.0
>
>
> Camel-Consul library expects EventClient to block requests and [passes number 
> of seconds to block request to 
> EventClient|https://github.com/apache/camel/blob/camel-2.21.0/components/camel-consul/src/main/java/org/apache/camel/component/consul/endpoint/ConsulEventConsumer.java#L59].
>  However Event HTTP Endpoint [does not support Blocking 
> Queries|https://www.consul.io/api/event.html] and EventClient [ignores passed 
> queryOptions|https://github.com/rickfast/consul-client/blob/1.1.1/src/main/java/com/orbitz/consul/EventClient.java#L164].
>  This results in high CPU usage because ConsulEventConsumer constantly makes 
> requests to Consul without any delay or blocking.
>  Maybe some _Thread.sleep_ could be added to _EventWatcher.watch(EventClient 
> client)_ before _client.listEvents_ call or any other fix to introduce delay 
> between _listEvents_ requests.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to