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

Log SDK optimization - Improve perf 15%-30% #2043

Merged
merged 3 commits into from
Aug 22, 2024

Conversation

lalitb
Copy link
Member

@lalitb lalitb commented Aug 22, 2024

Changes

Optimize Log SDK by avoiding unnecessary copy operation and redirections

  • LogData structure is removed.
  • Logger::emit() method is modified for unnecessary copy/assignment operation.
  • LogProcessor::emit method is modified to directly take reference of LogRecord and InstrumentationLibrary instead of LogData. This simplifies the API, and more importantly ones less level of redirection while accessing these components.

Existing:

fn emit(&self, _: &mut LogData)

Updated:

fn emit(&self, record: &mut LogRecord, library: &InstrumentationLibrary);

Benchmarks and stress: (courtesy chatgpt to generate table from the results):

Benchmark Main Branch (ns) PR Branch (ns) Change Performance
ot_layer_enabled 264.70 - 268.47 216.33 - 216.69 -17.979% to -18.548% Improved
Logging_Comparable_To_Appender 134.11 - 134.30 96.087 - 96.240 -28.174% to -28.378% Improved
log_noop_processor 141.65 - 141.81 102.56 - 102.70 -27.468% to -27.635% Improved
log_cloning_processor 238.92 - 239.35 178.97 - 179.24 -25.048% to -25.337% Improved
log_clone_and_send_to_channel_processor 620.69 - 628.54 582.68 - 584.69 -6.0463% to -6.9739% Improved
LogExporterWithFuture 284.68 - 285.04 129.92 - 130.31 -54.197% to -54.449% Improved
LogExporterWithoutFuture 250.91 - 251.26 98.156 - 98.299 -60.799% to -60.891% Improved
Stress (Throughput) Main Branch (iterations/sec) PR Branch (iterations/sec) Change Performance
Average 38,812,133 44,491,457 +14.7% Improved

Merge requirement checklist

  • CONTRIBUTING guidelines followed
  • Unit tests added/updated (if applicable)
  • Appropriate CHANGELOG.md files updated for non-trivial, user-facing changes
  • Changes in public API reviewed (if applicable)

@lalitb lalitb requested a review from a team August 22, 2024 07:34
Copy link

codecov bot commented Aug 22, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 77.1%. Comparing base (90ca577) to head (fe68e31).
Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##            main   #2043     +/-   ##
=======================================
- Coverage   77.1%   77.1%   -0.1%     
=======================================
  Files        123     123             
  Lines      21104   21103      -1     
=======================================
- Hits       16275   16274      -1     
  Misses      4829    4829             

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

let provider = self.provider();
let processors = provider.log_processors();
let trace_context = Context::map_current(|cx| {
cx.has_active_span()
.then(|| TraceContext::from(cx.span().span_context()))
});
let mut log_record = record;

//let mut log_record = record;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: is this comment required?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, will remove it in next PR.

fn emit(&self, data: &mut LogData);
/// - `record`: A mutable reference to `LogData` representing the log record.
/// - `instrumentation`: The instrumentation library associated with the log record.
fn emit(&self, data: &mut LogRecord, instrumentation: &InstrumentationLibrary);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: for a future PR, we can provide empty implementation for this as well.

@@ -9,6 +9,7 @@
~38 M /sec
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please update this, if there are any changes.

Copy link
Member Author

@lalitb lalitb Aug 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes this should be ~44K, will update the benchmark and stress stats with preallocate attribute PR.

Copy link
Member

@cijothomas cijothomas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice improvements! Please add a changelog and we can merge.

@cijothomas cijothomas merged commit 673c328 into open-telemetry:main Aug 22, 2024
25 checks passed
@cijothomas
Copy link
Member

Merging to keep progressing, changelog can added later, before release.

cijothomas pushed a commit to cijothomas/opentelemetry-rust that referenced this pull request Aug 22, 2024
cijothomas pushed a commit to cijothomas/opentelemetry-rust that referenced this pull request Aug 22, 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.

2 participants