Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

如何对Hugegraph-server中的Kneighbor算法的执行过程作profiling。分析算法执行过程中的各个阶段的内存和CPU占用。 #2516

Open
SkrDrag opened this issue Apr 11, 2024 · 7 comments
Labels
feature New feature question Further information is requested

Comments

@SkrDrag
Copy link

SkrDrag commented Apr 11, 2024

Feature Description (功能描述)

如何对Hugegraph-server中的Kneighbor算法的执行过程作profiling。分析算法执行过程中的各个阶段的内存和CPU占用。

@SkrDrag SkrDrag added the feature New feature label Apr 11, 2024
Copy link

dosubot bot commented Apr 11, 2024

To profile the Kneighbor algorithm in Hugegraph-server for memory and CPU usage, consider the following approaches:

  1. Use Java Profiling Tools: Tools like Arthas, VisualVM, YourKit, or JProfiler can help you monitor the CPU and memory usage in real-time. Start profiling before executing the Kneighbor algorithm and observe the performance throughout its execution stages.

  2. Manual Instrumentation: Add manual logging in the KneighborAPI class to track memory and CPU usage. Use System.currentTimeMillis() for CPU time and calculate memory usage by subtracting free memory from total memory using Runtime.getRuntime(). Insert these measurements at critical points in the algorithm's execution path and log the results for analysis.

Example code snippet for manual instrumentation:

long startTime = System.currentTimeMillis();
long startMemory = Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory();

// Algorithm execution code

long endTime = System.currentTimeMillis();
long endMemory = Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory();

LOG.debug("Execution time: " + (endTime - startTime) + "ms");
LOG.debug("Memory used: " + (endMemory - startMemory) + " bytes");
  1. Java Microbenchmark Harness (JMH): For detailed performance analysis, integrate JMH to benchmark the Kneighbor algorithm's execution.

  2. Application Performance Monitoring (APM) Tools: Leverage APM tools like New Relic, Dynatrace, or AppDynamics for comprehensive insights into the algorithm's performance, including CPU, memory, and database metrics.

Remember, manual instrumentation is more suited for a development or staging environment due to the need for source code modification. For detailed setup instructions for Java profiling tools, refer to their respective documentation.

This approach should provide a comprehensive view of the Kneighbor algorithm's performance within Hugegraph-server, allowing for targeted optimizations based on the observed CPU and memory usage.

Sources

About Dosu

This response is meant to be useful and save you time. It is not meant to be a precise solution, but rather a starting point for your own research.

Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant.

If you want to continue the conversation, start your reply with @dosu-bot.

@dosubot dosubot bot added the question Further information is requested label Apr 11, 2024
@SkrDrag
Copy link
Author

SkrDrag commented Apr 11, 2024

2. System.currentTimeMillis() for CPU time and calculate memory usage by subtracting free memory from total memory using Runtime.getRuntime(). Insert these measurements at critical points in the algorithm's execution path and log the results for analysis.

Example code snippet for manual instrumentation:

long startTime = System.currentTimeMillis();
long startMemory = Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory();

// Algorithm execution code

long endTime = System.currentTimeMillis();
long endMemory = Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory();

LOG.debug("Execution time: " + (endTime - startTime) + "ms");
LOG.debug("Memory used: " + (endMemory - startMemory) + " bytes");
  1. Java Microbenchmark Harness (JMH): For detailed performance analysis, integrate JMH to benchmark th

修改代码,编译运行之后,输出的log文件应该在哪个目录下

@imbajin
Copy link
Member

imbajin commented Apr 12, 2024

@SkrDrag u should better call the 🤖 with the @ to get quicker response

image

like @dosu-bot & response it for better experience

Copy link

dosubot bot commented Apr 12, 2024

The location of the log files after modifying the code, compiling, and running it depends on the configuration of your logging framework within the Hugegraph-server project. Typically, Java projects use logging frameworks like Log4j, SLF4J, or java.util.logging, and the output directory for log files is defined in the configuration file of these frameworks.

  1. Check the Logging Configuration: Look for configuration files related to the logging framework being used. This could be log4j.properties, log4j2.xml, logging.properties, or similar, depending on the framework. These files are usually located in the src/main/resources directory for Maven projects or src/resources for Gradle projects.

  2. Default Logging Directory: If the logging configuration does not specify a file path, logs are typically written to the console or to a default log file in the directory where the application was started.

  3. Custom Log File Location: If you have specified a custom file path in the logging configuration, the logs will be written to that location. For example, in a log4j.properties file, you might find a line like log4j.appender.FILE.File=/path/to/your/logfile.log, which indicates the log file location.

  4. Application Server Logs: If Hugegraph-server is deployed on an application server, logs might also be redirected to the server's log system. In this case, check the documentation of the server for log file locations.

If you're unable to find the logs, ensure that the logging level is set appropriately to capture debug logs, as the example code snippet uses LOG.debug for logging. You might need to adjust the logging level to DEBUG for the relevant classes or packages in your logging configuration.

Remember, the exact steps can vary based on the specific logging framework and configuration used in your project. If you're still having trouble, reviewing the documentation of the logging framework or searching for configuration examples online can provide more detailed guidance.

About Dosu

This response is meant to be useful and save you time. It is not meant to be a precise solution, but rather a starting point for your own research.

Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant.

If you want to continue the conversation, start your reply with @dosu-bot.

@javeme
Copy link
Contributor

javeme commented Apr 13, 2024

@SkrDrag 可以参考机器人回答的方式1--使用Java profile工具,不建议方式2--手动打点。
我个人使用async-profiler工具来生成火焰图:https://github.com/async-profiler/async-profiler
生成某个PID进程的火焰图可参考命令:./profiler.sh -d 30 -f profile.svg PID

@imbajin
Copy link
Member

imbajin commented Apr 14, 2024

@SkrDrag 可以参考机器人回答的方式1--使用Java profile工具,不建议方式2--手动打点。 我个人使用async-profiler工具来生成火焰图:async-profiler/async-profiler 。 生成某个PID进程的火焰图可参考命令:./profiler.sh -d 30 -f profile.svg PID

Some Notes:

We(HugeGraph Server) have already integrated the Arthas, and it also integrate the async-profiler already, no need to download async-profiler separately. (And u could check the flame graph in the web view directly, much friendly)

(Also cc to @dosu-bot , u should learn it & tell users to use it next time)

Refer:

  1. https://arthas.aliyun.com/en/doc/profiler.html
  2. https://arthas.aliyun.com/en/doc/profiler.html#view-profiler-results-under-arthas-output-via-browser
  3. feat(api): support embedded arthas agent in hugegraph-server #2278

Copy link

dosubot bot commented Apr 14, 2024

To profile the Kneighbor algorithm in HugeGraph Server and analyze its performance, including memory and CPU usage, you can leverage the integrated Arthas tool, which includes async-profiler. This approach allows you to generate detailed flame graphs without needing to download async-profiler separately. Here's how to do it:

  1. Ensure HugeGraph Server is Running: Your server needs to be active to attach the Arthas agent.

  2. Invoke Arthas via HugeGraph's Integrated API: HugeGraph Server has integrated Arthas, making it accessible through an API endpoint. You can start Arthas by making a PUT request to the /arthas endpoint, which will initialize it with the necessary configuration.

  3. Profile with Async-Profiler: Once Arthas is attached, use its CLI to start profiling. For CPU profiling, you might use a command like profiler start --event cpu -d 60, adjusting the duration as needed.

  4. Generate and View Flame Graph: After profiling, generate a flame graph with a command like profiler stop --format html > /path/to/flamegraph.html. Open the generated HTML file in a browser to view the performance characteristics of the Kneighbor algorithm.

For more detailed instructions, including how to configure and start Arthas, refer to the ArthasAPI.java file in the HugeGraph Server codebase. This file outlines the API endpoint for starting Arthas, detailing the necessary configurations for the HugeGraph environment.

This method provides a comprehensive view of the algorithm's performance, enabling targeted optimizations based on observed CPU and memory usage.

Sources

About Dosu

This response is meant to be useful and save you time. It is not meant to be a precise solution, but rather a starting point for your own research.

Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant.

If you want to continue the conversation, start your reply with @dosu-bot.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants