hashgraph / hedera-services

Crypto, token, consensus, file, and smart contract services for the Hedera public ledger
Apache License 2.0
266 stars 119 forks source link

Logging Framework: Improve handlers configuration #13081

Open mxtartaglia-sl opened 1 month ago

mxtartaglia-sl commented 1 month ago

Description

Currently, our logging framework utilizes two separate configurations for handler setup: one within the LoggingSystem and another within each individual handler. This dual configuration approach not only leads to redundancy but also results in inefficiencies during runtime.

To determine if a statement should be logged, we iterate through the list of handlers, querying each one individually with linear time complexity (O(n)). Creating a possible problem in scenarios with multiple handlers. JMH benchmarking have already highlighted this bottleneck even with a fixed number of handlers, leading into thinking this will create issues with increased number of handlers.

Moreover, each handler's internal configuration contains duplicated information, as handlers can inherit settings from the logging system. This also creates difficulties when refreshing handlers configuration, given that the setup doesn't support configuration that declares creation of new handlers.

To address these issues, the proposal is consolidating all configuration settings into a single container.

Benefits This centralized approach would allow for constant-time (O(1)) querying, improving runtime efficiency. Additionally, it would mitigate redundancy. This creates the benefit of dealing with only one concurrent map instead of n. Another possible benefit is the reduction of memory usage (see issue #12175)

Drawbacks Adopting this approach may reduce the ability to dynamically enable or disable handlers. (Q: is this something we need?)

Proposed Solution

Consolidate all configuration settings into a single container within the LoggingSystem. Implement a mechanism for constant-time querying to retrieve applicable handlers for each statement. Address the issue of redundancy by centralizing configuration data and dealing with configuration inheritance in creation time.

Expected Outcome: Improved runtime performance, especially with a large number of handlers. Reduced complexity and redundancy in configuration management. Easier configuration reloading mechanism. Potential trade-off: Loss of dynamic enabling and disabling of handlers.

mxtartaglia-sl commented 1 month ago

Waiting for feedback from End to end testing