lordgamez commented on code in PR #2245:
URL: https://github.com/apache/nifi-minifi-cpp/pull/2245#discussion_r4006678185


##########
benchmarks/repository_benchmark/run_benchmark.py:
##########
@@ -0,0 +1,421 @@
+#!/usr/bin/env python3
+# 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.
+
+import argparse
+import re
+import docker
+import humanfriendly
+import json
+import os
+import random
+import shutil
+import string
+import tempfile
+import threading
+import time
+import jinja2
+from datetime import datetime, timezone
+from enum import Enum
+
+SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__))
+RESOURCES_DIR = os.path.join(SCRIPT_DIR, "resources")
+GET_CONFIG_FILE_TEMPLATE = "get_config.json"
+GENERATE_CONFIG_FILE_TEMPLATE = "generate_config.json"
+RESULTS_DIR = os.path.join(SCRIPT_DIR, "results")
+
+MINIFI_HOME = "/opt/minifi/minifi-current"
+FLOWFILE_REPO_DIR = f"{MINIFI_HOME}/flowfile_repository"
+CONTENT_REPO_DIR = f"{MINIFI_HOME}/content_repository"
+INPUT_DIR = "/tmp/input"
+
+FLOWFILE_REPOSITORY_CLASSES = {
+    "rocksdb": "FlowFileRepository",
+    "lmdb": "LmdbFlowFileRepository",
+    "volatile": "VolatileFlowFileRepository",
+}
+
+CONTENT_REPOSITORY_CLASSES = {
+    "rocksdb": "DatabaseContentRepository",
+    "lmdb": "LmdbContentRepository",
+    "filesystem": "FileSystemRepository",
+    "volatile": "VolatileContentRepository",
+}
+
+LOG_TIMESTAMP_RE = re.compile(r'\[(\d{4}-\d{2}-\d{2} 
\d{2}:\d{2}:\d{2}\.\d+)\]')
+
+
+class InputGenerationType(str, Enum):
+    TIMED_GETFILE = "timed_getfile"
+    TIMED_GENERATEFLOWFILE = "timed_generateflowfile"
+    BURST = "burst"
+
+
+def build_properties(flowfile_repository: str, content_repository: str) -> 
dict[str, str]:
+    properties = {
+        "nifi.flow.configuration.file": f"{MINIFI_HOME}/conf/config.yml",
+        "nifi.extension.path": "../extensions/*",
+        "nifi.administrative.yield.duration": "1 sec",
+        "nifi.bored.yield.duration": "100 millis",
+        "nifi.openssl.fips.support.enable": "false",
+        "nifi.provenance.repository.class.name": "NoOpRepository",
+        "nifi.flowfile.repository.directory.default": FLOWFILE_REPO_DIR,
+        "nifi.database.content.repository.directory.default": CONTENT_REPO_DIR,
+        "nifi.flowfile.repository.class.name": 
FLOWFILE_REPOSITORY_CLASSES[flowfile_repository],
+        "nifi.content.repository.class.name": 
CONTENT_REPOSITORY_CLASSES[content_repository],
+    }
+    return properties
+
+
+def write_properties_file(properties: dict[str, str], path: str) -> None:
+    with open(path, "w") as properties_file:
+        for key, value in properties.items():
+            properties_file.write(f"{key}={value}\n")
+
+
+def repo_size(container, path: str) -> int:
+    exit_code, output = container.exec_run(["du", "-sk", path])
+    if exit_code != 0:
+        return 0
+    try:
+        return int(output.decode().split()[0]) * 1024
+    except (ValueError, IndexError):
+        return 0
+
+
+def read_container_stats(container) -> tuple[int, int, int, int]:
+    stats = container.stats(stream=False, one_shot=True)
+    memory_stats = stats.get("memory_stats", {})
+    usage = memory_stats.get("usage")
+    if usage is None:
+        mem = 0
+    else:
+        inactive_file = memory_stats.get("stats", {}).get("inactive_file", 0)
+        mem = max(usage - inactive_file, 0)
+
+    cpu_stats = stats.get("cpu_stats", {})
+    cpu_total = cpu_stats.get("cpu_usage", {}).get("total_usage", 0)
+    system_cpu = cpu_stats.get("system_cpu_usage", 0)
+    num_cpus = cpu_stats.get("online_cpus") or len(cpu_stats.get("cpu_usage", 
{}).get("percpu_usage") or [1])
+    return mem, cpu_total, system_cpu, num_cpus
+
+
+def generate_single_input(input_dir: str, file_size: int, index: int) -> None:
+    data = os.urandom(file_size)
+    # Write to a temp name then rename so GetFile never reads a partial file.
+    tmp_path = os.path.join(input_dir, f".{index}.tmp")
+    final_path = os.path.join(input_dir, f"input_{index}.bin")
+    with open(tmp_path, "wb") as input_file:
+        input_file.write(data)
+    os.rename(tmp_path, final_path)

Review Comment:
   Fixed in 
https://github.com/apache/nifi-minifi-cpp/pull/2245/commits/a6d1495efb23ba3081ddf4beb6970d3e30fe9c83



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to