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

perf: optimization for logging system with profiling and efficient log file management #2832

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

beats-dh
Copy link
Collaborator

@beats-dh beats-dh commented Aug 20, 2024

PR Description

This PR improves the performance of the logging system and adds profiling functionality with automatic log generation. Additionally, optimizations have been performed to ensure that logs are written efficiently to text files.

Main changes:

Log Processing Optimization:

  • Added check to avoid unnecessary log processing at trace and debug levels. Now, the system only formats and processes log messages at these levels if they are enabled, saving resources and improving overall performance.

Automatic Generation of Log Files for Profiling:

  • The profile function now automatically generates a dedicated log file, containing the execution time of profiled functions. This allows for easier analysis of the performance of critical functions by keeping logs organized and separated by execution.

Optimization in Writing Logs to Text Files:

  • Implemented a strategy to reuse loggers associated with existing log files. This avoids creating new files unnecessarily and improves performance by ensuring that subsequent log messages are written to the same file when appropriate.

Debug and Trace Logs Availability:

  • Debug and trace level logs are now only available in the debug compilation level, ensuring that these detailed logs are not generated in production builds, thus further optimizing performance.

Usage Example:

OutputMessage_ptr OutputMessagePool::getOutputMessage() {
	return g_logger().profile(__FUNCTION__, [&]() {
			return  std::make_shared<OutputMessage>();
		});
}
class ExampleClass {
public:
    void performTask() {
        // Use the 'profile' function to measure the execution time of 'computeHeavyTask'
        g_logger().profile("computeHeavyTask", [this]() {
            computeHeavyTask();
        });
    }

private:
    void computeHeavyTask() {
        // Simulation of a time-consuming task
        std::this_thread::sleep_for(std::chrono::seconds(2));
        // Heavy task done
    }
};
  • In this example, performTask calls the computeHeavyTask function and uses the logger to measure the execution time of this function, recording the result in a specific log file.

Justification:

  • These improvements aim to optimize server performance, especially in production environments, where trace and debug level logs are not necessary. The new profiling log functionality provides a structured way to monitor and improve the performance of critical functions. Optimization of writing to log files reduces I/O overhead, improving the overall efficiency of the logging system.

Tests:

  • Manual checks have been performed to ensure that trace and debug level log messages are not processed when disabled.
    The profiling functionality has been tested and it has been verified that the log files are generated correctly with the recorded execution times.
    Additional testing was performed to ensure that writing to log files is efficient and that files are reused correctly without unnecessary creation of new files.

This comment was marked as outdated.

Copy link
Contributor

This PR is stale because it has been open 45 days with no activity.

@github-actions github-actions bot added the Stale No activity label Sep 22, 2024
Copy link

sonarcloud bot commented Oct 14, 2024

@github-actions github-actions bot removed the Stale No activity label Oct 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant