You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@nifi.apache.org by GitBox <gi...@apache.org> on 2020/06/19 15:52:53 UTC

[GitHub] [nifi] gardellajuanpablo opened a new pull request #4352: NIFI-7563 Optimize the usage of JMS sessions and message producers

gardellajuanpablo opened a new pull request #4352:
URL: https://github.com/apache/nifi/pull/4352


   Thank you for submitting a contribution to Apache NiFi.
   
   Please provide a short description of the PR here:
   
   #### Description of PR
   
   _Enables X functionality; fixes bug NIFI-YYYY._
   
   In order to streamline the review of the contribution we ask you
   to ensure the following steps have been taken:
   
   ### For all changes:
   - [ ] Is there a JIRA ticket associated with this PR? Is it referenced 
        in the commit message?
   
   - [ ] Does your PR title start with **NIFI-XXXX** where XXXX is the JIRA number you are trying to resolve? Pay particular attention to the hyphen "-" character.
   
   - [ ] Has your PR been rebased against the latest commit within the target branch (typically `master`)?
   
   - [ ] Is your initial contribution a single, squashed commit? _Additional commits in response to PR reviewer feedback should be made on this branch and pushed to allow change tracking. Do not `squash` or use `--force` when pushing to allow for clean monitoring of changes._
   
   ### For code changes:
   - [ ] Have you ensured that the full suite of tests is executed via `mvn -Pcontrib-check clean install` at the root `nifi` folder?
   - [ ] Have you written or updated unit tests to verify your changes?
   - [ ] Have you verified that the full build is successful on JDK 8?
   - [ ] Have you verified that the full build is successful on JDK 11?
   - [ ] If adding new dependencies to the code, are these dependencies licensed in a way that is compatible for inclusion under [ASF 2.0](http://www.apache.org/legal/resolved.html#category-a)? 
   - [ ] If applicable, have you updated the `LICENSE` file, including the main `LICENSE` file under `nifi-assembly`?
   - [ ] If applicable, have you updated the `NOTICE` file, including the main `NOTICE` file found under `nifi-assembly`?
   - [ ] If adding new Properties, have you added `.displayName` in addition to .name (programmatic access) for each of the new properties?
   
   ### For documentation related changes:
   - [ ] Have you ensured that format looks appropriate for the output in which it is rendered?
   
   ### Note:
   Please ensure that once the PR is submitted, you check GitHub Actions CI for build issues and submit an update to your PR as soon as possible.
   


----------------------------------------------------------------
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.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [nifi] gardellajuanpablo commented on pull request #4352: NIFI-7563 Optimize the usage of JMS sessions and message producers

Posted by GitBox <gi...@apache.org>.
gardellajuanpablo commented on pull request #4352:
URL: https://github.com/apache/nifi/pull/4352#issuecomment-652323183


   Please cancel this PR


----------------------------------------------------------------
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.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [nifi] jfrazee commented on a change in pull request #4352: NIFI-7563 Optimize the usage of JMS sessions and message producers

Posted by GitBox <gi...@apache.org>.
jfrazee commented on a change in pull request #4352:
URL: https://github.com/apache/nifi/pull/4352#discussion_r447314098



##########
File path: nifi-nar-bundles/nifi-jms-bundle/nifi-jms-processors/src/test/java/org/apache/nifi/jms/processors/PublishJMSIT.java
##########
@@ -385,6 +390,66 @@ protected TcpTransport createTcpTransport(WireFormat wf, SocketFactory socketFac
         }
     }
 
+    /**
+     * <p>
+     * This test validates the optimal resources usage. To process one message is expected to create only one connection, one session and one message producer.
+     * </p>
+     * <p>
+     * See <a href="NIFI-7563">https://issues.apache.org/jira/browse/NIFI-7563</a> for details.
+     * </p>
+     * @throws Exception any error related to the broker.
+     */
+    @Test(timeout = 10000)
+    public void validateNIFI7563() throws Exception {
+        BrokerService broker = new BrokerService();
+        try {
+            broker.setPersistent(false);
+            TransportConnector connector = broker.addConnector("tcp://127.0.0.1:0");
+            int port = connector.getServer().getSocketAddress().getPort();
+            broker.start();
+
+            final ActiveMQConnectionFactory innerCf = new ActiveMQConnectionFactory("tcp://127.0.0.1:" + port);
+            ConnectionFactoryInvocationHandler connectionFactoryProxy = new ConnectionFactoryInvocationHandler(innerCf);
+
+            // Create a connection Factory proxy to catch metrics and usage.
+            ConnectionFactory cf = (ConnectionFactory) Proxy.newProxyInstance(ConnectionFactory.class.getClassLoader(), new Class[] { ConnectionFactory.class }, connectionFactoryProxy);
+
+            TestRunner runner = TestRunners.newTestRunner(new PublishJMS());
+            JMSConnectionFactoryProviderDefinition cs = mock(JMSConnectionFactoryProviderDefinition.class);
+            when(cs.getIdentifier()).thenReturn("cfProvider");
+            when(cs.getConnectionFactory()).thenReturn(cf);
+            runner.addControllerService("cfProvider", cs);
+            runner.enableControllerService(cs);
+
+            runner.setProperty(PublishJMS.CF_SERVICE, "cfProvider");
+
+            String destinationName = "myDestinationName";
+            // The destination option according current implementation should contain topic or queue to infer the destination type
+            // from the name. Check https://issues.apache.org/jira/browse/NIFI-7561. Once that is fixed, the name can be
+            // randomly created.
+            String topicNameInHeader = "topic-foo";
+            runner.setProperty(PublishJMS.DESTINATION, destinationName);
+            runner.setProperty(PublishJMS.DESTINATION_TYPE, PublishJMS.QUEUE);
+
+            Map<String, String> flowFileAttributes = new HashMap<>();
+            // This method will be removed once https://issues.apache.org/jira/browse/NIFI-7564 is fixed.
+            flowFileAttributes.put(JmsHeaders.DESTINATION, topicNameInHeader);
+            flowFileAttributes.put(JmsHeaders.REPLY_TO, topicNameInHeader);
+            runner.enqueue("hi".getBytes(), flowFileAttributes);
+            runner.enqueue("h2".getBytes(), flowFileAttributes);
+            runner.setThreadCount(1);

Review comment:
       Could we add a test that tests the scenario with more threads? I believe your comment in the JIRA is accurate but I think the threading is the only real concern in this PR.




----------------------------------------------------------------
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.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [nifi] gardellajuanpablo commented on a change in pull request #4352: NIFI-7563 Optimize the usage of JMS sessions and message producers

Posted by GitBox <gi...@apache.org>.
gardellajuanpablo commented on a change in pull request #4352:
URL: https://github.com/apache/nifi/pull/4352#discussion_r447610193



##########
File path: nifi-nar-bundles/nifi-jms-bundle/nifi-jms-processors/src/test/java/org/apache/nifi/jms/processors/PublishJMSIT.java
##########
@@ -385,6 +390,66 @@ protected TcpTransport createTcpTransport(WireFormat wf, SocketFactory socketFac
         }
     }
 
+    /**
+     * <p>
+     * This test validates the optimal resources usage. To process one message is expected to create only one connection, one session and one message producer.
+     * </p>
+     * <p>
+     * See <a href="NIFI-7563">https://issues.apache.org/jira/browse/NIFI-7563</a> for details.
+     * </p>
+     * @throws Exception any error related to the broker.
+     */
+    @Test(timeout = 10000)
+    public void validateNIFI7563() throws Exception {
+        BrokerService broker = new BrokerService();
+        try {
+            broker.setPersistent(false);
+            TransportConnector connector = broker.addConnector("tcp://127.0.0.1:0");
+            int port = connector.getServer().getSocketAddress().getPort();
+            broker.start();
+
+            final ActiveMQConnectionFactory innerCf = new ActiveMQConnectionFactory("tcp://127.0.0.1:" + port);
+            ConnectionFactoryInvocationHandler connectionFactoryProxy = new ConnectionFactoryInvocationHandler(innerCf);
+
+            // Create a connection Factory proxy to catch metrics and usage.
+            ConnectionFactory cf = (ConnectionFactory) Proxy.newProxyInstance(ConnectionFactory.class.getClassLoader(), new Class[] { ConnectionFactory.class }, connectionFactoryProxy);
+
+            TestRunner runner = TestRunners.newTestRunner(new PublishJMS());
+            JMSConnectionFactoryProviderDefinition cs = mock(JMSConnectionFactoryProviderDefinition.class);
+            when(cs.getIdentifier()).thenReturn("cfProvider");
+            when(cs.getConnectionFactory()).thenReturn(cf);
+            runner.addControllerService("cfProvider", cs);
+            runner.enableControllerService(cs);
+
+            runner.setProperty(PublishJMS.CF_SERVICE, "cfProvider");
+
+            String destinationName = "myDestinationName";
+            // The destination option according current implementation should contain topic or queue to infer the destination type
+            // from the name. Check https://issues.apache.org/jira/browse/NIFI-7561. Once that is fixed, the name can be
+            // randomly created.
+            String topicNameInHeader = "topic-foo";
+            runner.setProperty(PublishJMS.DESTINATION, destinationName);
+            runner.setProperty(PublishJMS.DESTINATION_TYPE, PublishJMS.QUEUE);
+
+            Map<String, String> flowFileAttributes = new HashMap<>();
+            // This method will be removed once https://issues.apache.org/jira/browse/NIFI-7564 is fixed.
+            flowFileAttributes.put(JmsHeaders.DESTINATION, topicNameInHeader);
+            flowFileAttributes.put(JmsHeaders.REPLY_TO, topicNameInHeader);
+            runner.enqueue("hi".getBytes(), flowFileAttributes);
+            runner.enqueue("h2".getBytes(), flowFileAttributes);
+            runner.setThreadCount(1);

Review comment:
       Thanks for reviewing it. Actually the issue happens when a worker is reused. It can be reproduced with only one thread, but I can add another test to verify using **less than** (it could be possible that for N threads only M workers are created, when M < M). I will do.




----------------------------------------------------------------
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.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [nifi] gardellajuanpablo commented on a change in pull request #4352: NIFI-7563 Optimize the usage of JMS sessions and message producers

Posted by GitBox <gi...@apache.org>.
gardellajuanpablo commented on a change in pull request #4352:
URL: https://github.com/apache/nifi/pull/4352#discussion_r448255708



##########
File path: nifi-nar-bundles/nifi-jms-bundle/nifi-jms-processors/src/test/java/org/apache/nifi/jms/processors/PublishJMSIT.java
##########
@@ -385,6 +390,66 @@ protected TcpTransport createTcpTransport(WireFormat wf, SocketFactory socketFac
         }
     }
 
+    /**
+     * <p>
+     * This test validates the optimal resources usage. To process one message is expected to create only one connection, one session and one message producer.
+     * </p>
+     * <p>
+     * See <a href="NIFI-7563">https://issues.apache.org/jira/browse/NIFI-7563</a> for details.
+     * </p>
+     * @throws Exception any error related to the broker.
+     */
+    @Test(timeout = 10000)
+    public void validateNIFI7563() throws Exception {
+        BrokerService broker = new BrokerService();
+        try {
+            broker.setPersistent(false);
+            TransportConnector connector = broker.addConnector("tcp://127.0.0.1:0");
+            int port = connector.getServer().getSocketAddress().getPort();
+            broker.start();
+
+            final ActiveMQConnectionFactory innerCf = new ActiveMQConnectionFactory("tcp://127.0.0.1:" + port);
+            ConnectionFactoryInvocationHandler connectionFactoryProxy = new ConnectionFactoryInvocationHandler(innerCf);
+
+            // Create a connection Factory proxy to catch metrics and usage.
+            ConnectionFactory cf = (ConnectionFactory) Proxy.newProxyInstance(ConnectionFactory.class.getClassLoader(), new Class[] { ConnectionFactory.class }, connectionFactoryProxy);
+
+            TestRunner runner = TestRunners.newTestRunner(new PublishJMS());
+            JMSConnectionFactoryProviderDefinition cs = mock(JMSConnectionFactoryProviderDefinition.class);
+            when(cs.getIdentifier()).thenReturn("cfProvider");
+            when(cs.getConnectionFactory()).thenReturn(cf);
+            runner.addControllerService("cfProvider", cs);
+            runner.enableControllerService(cs);
+
+            runner.setProperty(PublishJMS.CF_SERVICE, "cfProvider");
+
+            String destinationName = "myDestinationName";
+            // The destination option according current implementation should contain topic or queue to infer the destination type
+            // from the name. Check https://issues.apache.org/jira/browse/NIFI-7561. Once that is fixed, the name can be
+            // randomly created.
+            String topicNameInHeader = "topic-foo";
+            runner.setProperty(PublishJMS.DESTINATION, destinationName);
+            runner.setProperty(PublishJMS.DESTINATION_TYPE, PublishJMS.QUEUE);
+
+            Map<String, String> flowFileAttributes = new HashMap<>();
+            // This method will be removed once https://issues.apache.org/jira/browse/NIFI-7564 is fixed.
+            flowFileAttributes.put(JmsHeaders.DESTINATION, topicNameInHeader);
+            flowFileAttributes.put(JmsHeaders.REPLY_TO, topicNameInHeader);
+            runner.enqueue("hi".getBytes(), flowFileAttributes);
+            runner.enqueue("h2".getBytes(), flowFileAttributes);
+            runner.setThreadCount(1);

Review comment:
       Done, but I messed up during rebase. I have to create another branch from latest changes in master. The changes are now at https://github.com/apache/nifi/pull/4378. Sorry about that, could you please review it soon? That will prevent to me rebase it again :). 




----------------------------------------------------------------
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.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [nifi] jfrazee commented on a change in pull request #4352: NIFI-7563 Optimize the usage of JMS sessions and message producers

Posted by GitBox <gi...@apache.org>.
jfrazee commented on a change in pull request #4352:
URL: https://github.com/apache/nifi/pull/4352#discussion_r447314728



##########
File path: nifi-nar-bundles/nifi-jms-bundle/nifi-jms-processors/src/test/java/org/apache/nifi/jms/processors/helpers/ConnectionFactoryInvocationHandler.java
##########
@@ -0,0 +1,110 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.nifi.jms.processors.helpers;
+
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.Method;
+import java.lang.reflect.Proxy;
+import java.util.List;
+import java.util.Objects;
+import java.util.concurrent.CopyOnWriteArrayList;
+import java.util.concurrent.atomic.AtomicInteger;
+
+import javax.annotation.concurrent.ThreadSafe;
+import javax.jms.Connection;
+import javax.jms.ConnectionFactory;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * {@link ConnectionFactory}'s invocation handler to be used to create {@link Proxy} instances. This handler stores useful information to validate the proper resources handling of underlying
+ * connection factory.
+ */
+@ThreadSafe
+public final class ConnectionFactoryInvocationHandler implements InvocationHandler {
+
+    private static final Logger LOGGER = LoggerFactory.getLogger(ConnectionFactoryInvocationHandler.class);
+
+    private final ConnectionFactory connectionFactory;
+    private final List<ConnectionInvocationHandler> handlers = new CopyOnWriteArrayList<>();
+    private final AtomicInteger openedConnections = new AtomicInteger();
+
+    public ConnectionFactoryInvocationHandler(ConnectionFactory connectionFactory) {
+        this.connectionFactory = Objects.requireNonNull(connectionFactory);
+    }
+
+    @Override
+    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
+        final Object o = connectionFactory.getClass().getMethod(method.getName(), method.getParameterTypes()).invoke(connectionFactory, args);
+        LOGGER.debug("Method {} called on {}", method.getName(), connectionFactory);

Review comment:
       Minor nit. I know this is only used for a test, but can we wrap this in `LOGGER.isDebugEnabled()`? Same for `ConnectionInvocationHandler`.




----------------------------------------------------------------
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.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [nifi] gardellajuanpablo closed pull request #4352: NIFI-7563 Optimize the usage of JMS sessions and message producers

Posted by GitBox <gi...@apache.org>.
gardellajuanpablo closed pull request #4352:
URL: https://github.com/apache/nifi/pull/4352


   


----------------------------------------------------------------
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.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org