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 2022/11/04 09:04:26 UTC

[GitHub] [nifi-minifi-cpp] adamdebreceni opened a new pull request, #1447: MINIFICPP-1976 - Do not store a whole Relationship object for each transfer

adamdebreceni opened a new pull request, #1447:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1447

   
   
   This decreases the memory usage by 7% while using the TailFile processor.
   
   
   ---
   Thank you for submitting a contribution to Apache NiFi - MiNiFi C++.
   
   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 MINIFICPP-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 main)?
   
   - [ ] Is your initial contribution a single, squashed commit?
   
   ### For code changes:
   - [ ] 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?
   - [ ] If applicable, have you updated the NOTICE file?
   
   ### 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 results 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.

To unsubscribe, e-mail: issues-unsubscribe@nifi.apache.org

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


[GitHub] [nifi-minifi-cpp] adam-markovics commented on a diff in pull request #1447: MINIFICPP-1976 - Do not store a whole Relationship object for each transfer

Posted by GitBox <gi...@apache.org>.
adam-markovics commented on code in PR #1447:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1447#discussion_r1024083843


##########
libminifi/include/core/ProcessSession.h:
##########
@@ -155,16 +156,25 @@ class ProcessSession : public ReferenceContainer {
     std::shared_ptr<FlowFile> snapshot;
   };
 
+  using Relationships = utils::ValueIdProvider<Relationship>;
+
+  Relationships relationships_;

Review Comment:
   We only instantiate `ValueCompressor`  with id being 8 bytes, so this doesn't apply now. Also this member should be private as no subclasses use it, so invalid pointer dereferencing is not possible (by someone else) if usage is consistent within this class.



-- 
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: issues-unsubscribe@nifi.apache.org

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


[GitHub] [nifi-minifi-cpp] adamdebreceni commented on a diff in pull request #1447: MINIFICPP-1976 - Do not store a whole Relationship object for each transfer

Posted by GitBox <gi...@apache.org>.
adamdebreceni commented on code in PR #1447:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1447#discussion_r1018837945


##########
libminifi/include/utils/ValueIdProvider.h:
##########
@@ -0,0 +1,61 @@
+/**
+ *
+ * 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/licenseas/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.
+ */
+
+#pragma once
+
+#include <optional>
+#include <unordered_map>
+#include <vector>
+
+namespace org::apache::nifi::minifi::utils {
+
+template<typename T, typename IdType = size_t>
+class ValueIdProvider {

Review Comment:
   I am open to suggestions for a more fitting name



-- 
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: issues-unsubscribe@nifi.apache.org

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


[GitHub] [nifi-minifi-cpp] martinzink commented on a diff in pull request #1447: MINIFICPP-1976 - Do not store a whole Relationship object for each transfer

Posted by GitBox <gi...@apache.org>.
martinzink commented on code in PR #1447:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1447#discussion_r1022723372


##########
libminifi/include/core/ProcessSession.h:
##########
@@ -39,6 +39,7 @@
 #include "provenance/Provenance.h"
 #include "utils/gsl.h"
 #include "ProcessorMetrics.h"
+#include "utils/ValueIdProvider.h"

Review Comment:
   This was left out from https://github.com/apache/nifi-minifi-cpp/pull/1447/commits/43fd546047aa2e9312ccefaf6f2625a5c1639993 and causes compile errors



-- 
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: issues-unsubscribe@nifi.apache.org

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


[GitHub] [nifi-minifi-cpp] adamdebreceni commented on a diff in pull request #1447: MINIFICPP-1976 - Do not store a whole Relationship object for each transfer

Posted by GitBox <gi...@apache.org>.
adamdebreceni commented on code in PR #1447:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1447#discussion_r1023736739


##########
libminifi/include/core/ProcessSession.h:
##########
@@ -155,16 +156,25 @@ class ProcessSession : public ReferenceContainer {
     std::shared_ptr<FlowFile> snapshot;
   };
 
+  using Relationships = utils::ValueIdProvider<Relationship>;
+
+  Relationships relationships_;

Review Comment:
   I would rather we use ids, we could configure the id (compressed_type) to be smaller than 8 bytes, we also can't accidentally dereference an invalid pointer (although we could decompress what was compressed with another compressor, that would not be UB at least)



-- 
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: issues-unsubscribe@nifi.apache.org

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


[GitHub] [nifi-minifi-cpp] adamdebreceni commented on a diff in pull request #1447: MINIFICPP-1976 - Do not store a whole Relationship object for each transfer

Posted by GitBox <gi...@apache.org>.
adamdebreceni commented on code in PR #1447:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1447#discussion_r1018835222


##########
libminifi/include/utils/ValueIdProvider.h:
##########
@@ -0,0 +1,61 @@
+/**
+ *
+ * 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/licenseas/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.
+ */
+
+#pragma once
+
+#include <optional>
+#include <unordered_map>
+#include <vector>
+
+namespace org::apache::nifi::minifi::utils {
+
+template<typename T, typename IdType = size_t>
+class ValueIdProvider {
+ public:
+  using id_type = IdType;
+  static constexpr id_type INVALID_ID = static_cast<id_type>(-1);
+
+  [[nodiscard]]
+  id_type getId(const T& value) {
+    auto [it, inserted] = value_to_id_.insert({value, gsl::narrow<id_type>(values_.size())});

Review Comment:
   added



##########
libminifi/include/utils/ValueIdProvider.h:
##########
@@ -0,0 +1,61 @@
+/**
+ *
+ * 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/licenseas/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.
+ */
+
+#pragma once
+
+#include <optional>
+#include <unordered_map>
+#include <vector>
+
+namespace org::apache::nifi::minifi::utils {
+
+template<typename T, typename IdType = size_t>
+class ValueIdProvider {
+ public:
+  using id_type = IdType;
+  static constexpr id_type INVALID_ID = static_cast<id_type>(-1);
+
+  [[nodiscard]]
+  id_type getId(const T& value) {
+    auto [it, inserted] = value_to_id_.insert({value, gsl::narrow<id_type>(values_.size())});
+    if (inserted) {
+      values_.push_back(value);
+    }
+    return it->second;
+  }
+
+  [[nodiscard]]
+  std::optional<T> getValue(id_type id) const {
+    const auto idx = gsl::narrow<size_t>(id);
+    if (idx < values_.size()) {
+      return values_.at(idx);

Review Comment:
   removed



-- 
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: issues-unsubscribe@nifi.apache.org

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


[GitHub] [nifi-minifi-cpp] adamdebreceni commented on a diff in pull request #1447: MINIFICPP-1976 - Do not store a whole Relationship object for each transfer

Posted by GitBox <gi...@apache.org>.
adamdebreceni commented on code in PR #1447:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1447#discussion_r1024230985


##########
libminifi/include/core/ProcessSession.h:
##########
@@ -155,16 +156,25 @@ class ProcessSession : public ReferenceContainer {
     std::shared_ptr<FlowFile> snapshot;
   };
 
+  using Relationships = utils::ValueIdProvider<Relationship>;
+
+  Relationships relationships_;

Review Comment:
   removed `ValueCompressor`, using a pointer into a cache set



-- 
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: issues-unsubscribe@nifi.apache.org

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


[GitHub] [nifi-minifi-cpp] lordgamez closed pull request #1447: MINIFICPP-1976 - Do not store a whole Relationship object for each transfer

Posted by GitBox <gi...@apache.org>.
lordgamez closed pull request #1447: MINIFICPP-1976 - Do not store a whole Relationship object for each transfer
URL: https://github.com/apache/nifi-minifi-cpp/pull/1447


-- 
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: issues-unsubscribe@nifi.apache.org

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


[GitHub] [nifi-minifi-cpp] adam-markovics commented on a diff in pull request #1447: MINIFICPP-1976 - Do not store a whole Relationship object for each transfer

Posted by GitBox <gi...@apache.org>.
adam-markovics commented on code in PR #1447:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1447#discussion_r1015197406


##########
libminifi/include/utils/ValueIdProvider.h:
##########
@@ -0,0 +1,61 @@
+/**
+ *
+ * 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/licenseas/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.
+ */
+
+#pragma once
+
+#include <optional>
+#include <unordered_map>
+#include <vector>
+
+namespace org::apache::nifi::minifi::utils {
+
+template<typename T, typename IdType = size_t>
+class ValueIdProvider {
+ public:
+  using id_type = IdType;
+  static constexpr id_type INVALID_ID = static_cast<id_type>(-1);
+
+  [[nodiscard]]
+  id_type getId(const T& value) {
+    auto [it, inserted] = value_to_id_.insert({value, gsl::narrow<id_type>(values_.size())});

Review Comment:
   gsl needs to be included as well



##########
libminifi/include/core/ProcessSession.h:
##########
@@ -155,16 +156,25 @@ class ProcessSession : public ReferenceContainer {
     std::shared_ptr<FlowFile> snapshot;
   };
 
+  using Relationships = utils::ValueIdProvider<Relationship>;
+
+  Relationships relationships_;

Review Comment:
   Why isn't this a simple `unordered_set`, while references to `Relationship`s with `id_type`, could just be raw pointers to items stored here? Invalid ones are `nullptr`, if necessary. This could eliminate the need for `ValueIdProvider`.



##########
libminifi/include/utils/ValueIdProvider.h:
##########
@@ -0,0 +1,61 @@
+/**
+ *
+ * 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/licenseas/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.
+ */
+
+#pragma once
+
+#include <optional>
+#include <unordered_map>
+#include <vector>
+
+namespace org::apache::nifi::minifi::utils {
+
+template<typename T, typename IdType = size_t>
+class ValueIdProvider {
+ public:
+  using id_type = IdType;
+  static constexpr id_type INVALID_ID = static_cast<id_type>(-1);
+
+  [[nodiscard]]
+  id_type getId(const T& value) {
+    auto [it, inserted] = value_to_id_.insert({value, gsl::narrow<id_type>(values_.size())});
+    if (inserted) {
+      values_.push_back(value);
+    }
+    return it->second;
+  }
+
+  [[nodiscard]]
+  std::optional<T> getValue(id_type id) const {
+    const auto idx = gsl::narrow<size_t>(id);
+    if (idx < values_.size()) {
+      return values_.at(idx);

Review Comment:
   `at` is checking boundaries for the second time after the condition, I think it's unnecessary



##########
libminifi/include/utils/ValueIdProvider.h:
##########
@@ -0,0 +1,61 @@
+/**
+ *
+ * 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/licenseas/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.
+ */
+
+#pragma once
+
+#include <optional>
+#include <unordered_map>
+#include <vector>
+
+namespace org::apache::nifi::minifi::utils {
+
+template<typename T, typename IdType = size_t>
+class ValueIdProvider {

Review Comment:
   I think a line of comment could explain what this class does, maybe a better name could also be found than overly generic "Provider".



-- 
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: issues-unsubscribe@nifi.apache.org

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


[GitHub] [nifi-minifi-cpp] adam-markovics commented on a diff in pull request #1447: MINIFICPP-1976 - Do not store a whole Relationship object for each transfer

Posted by GitBox <gi...@apache.org>.
adam-markovics commented on code in PR #1447:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1447#discussion_r1018910021


##########
libminifi/include/core/ProcessSession.h:
##########
@@ -155,16 +156,25 @@ class ProcessSession : public ReferenceContainer {
     std::shared_ptr<FlowFile> snapshot;
   };
 
+  using Relationships = utils::ValueIdProvider<Relationship>;
+
+  Relationships relationships_;

Review Comment:
   If we used raw pointers, the only member in `ValueCompressor` would be an `unordered_set`. `compress` would become just an `insert`, `decompress` would just become a pointer dereferencing. Is it still worth creating a class for that, basically a wrapper around a standard container?



-- 
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: issues-unsubscribe@nifi.apache.org

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


[GitHub] [nifi-minifi-cpp] adamdebreceni commented on a diff in pull request #1447: MINIFICPP-1976 - Do not store a whole Relationship object for each transfer

Posted by GitBox <gi...@apache.org>.
adamdebreceni commented on code in PR #1447:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1447#discussion_r1018846947


##########
libminifi/include/utils/ValueIdProvider.h:
##########
@@ -0,0 +1,61 @@
+/**
+ *
+ * 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/licenseas/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.
+ */
+
+#pragma once
+
+#include <optional>
+#include <unordered_map>
+#include <vector>
+
+namespace org::apache::nifi::minifi::utils {
+
+template<typename T, typename IdType = size_t>
+class ValueIdProvider {

Review Comment:
   how about `ValueCompressor` or `CachedCompressor`, with methods like `compress`/`decompress`?



-- 
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: issues-unsubscribe@nifi.apache.org

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


[GitHub] [nifi-minifi-cpp] adamdebreceni commented on a diff in pull request #1447: MINIFICPP-1976 - Do not store a whole Relationship object for each transfer

Posted by GitBox <gi...@apache.org>.
adamdebreceni commented on code in PR #1447:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1447#discussion_r1018840698


##########
libminifi/include/core/ProcessSession.h:
##########
@@ -155,16 +156,25 @@ class ProcessSession : public ReferenceContainer {
     std::shared_ptr<FlowFile> snapshot;
   };
 
+  using Relationships = utils::ValueIdProvider<Relationship>;
+
+  Relationships relationships_;

Review Comment:
   could be, but how we achieve a lower memory usage is not really the concern of `ProcessSession`, this `ValueIdProvider` (rename pending) hides this away, `id_type` could be a raw pointer, `INVALID_ID` could be redefined, and we wouldn't have to touch `ProcessSession` for such a change



-- 
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: issues-unsubscribe@nifi.apache.org

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


[GitHub] [nifi-minifi-cpp] adam-markovics commented on a diff in pull request #1447: MINIFICPP-1976 - Do not store a whole Relationship object for each transfer

Posted by GitBox <gi...@apache.org>.
adam-markovics commented on code in PR #1447:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1447#discussion_r1018910701


##########
libminifi/include/utils/ValueIdProvider.h:
##########
@@ -0,0 +1,61 @@
+/**
+ *
+ * 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/licenseas/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.
+ */
+
+#pragma once
+
+#include <optional>
+#include <unordered_map>
+#include <vector>
+
+namespace org::apache::nifi::minifi::utils {
+
+template<typename T, typename IdType = size_t>
+class ValueIdProvider {

Review Comment:
   I support this naming if we decide to keep the class.



-- 
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: issues-unsubscribe@nifi.apache.org

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