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

Tracing aware executors wrap Runnables and Callables more cleanly #310

Merged
merged 3 commits into from
Oct 11, 2019

Conversation

carterkozak
Copy link
Contributor

@carterkozak carterkozak commented Oct 10, 2019

==COMMIT_MSG==
Firstly, we should not optimize around stack depth in most cases
because it can result in large methods that the JVM cannot efficiently
inline and additional GC pressure depending on the implementation.

However, we use tracing a lot, a tracing wrapped executor shows up
in ~50% of stack traces in a large internal service, and exceptions
propagate through multiple executors in many cases.
This would not make sense to change if the tracing stack frames
provided information, but wrapping from runnable to callable
isn't helpful, nor are lambda frames to turn a Callable into
a ThrowingCallable.

This change is completely internal to tracing and does not expose
any new public APIs.

Before: frames 2, 3, 4, and 5 are from tracing

com.palantir.logsafe.exceptions.SafeRuntimeException: Stack Trace
        at com.palantir.tracing.TracerTest.lambda$testStackDepth$9(TracerTest.java:486)
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
        at com.palantir.tracing.DeferredTracer.withTrace(DeferredTracer.java:104)
        at com.palantir.tracing.Tracers$TracingAwareCallable.call(Tracers.java:356)
        at com.palantir.tracing.WrappingExecutorService.lambda$wrapTask$0(WrappingExecutorService.java:67)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
        at java.lang.Thread.run(Thread.java:748)

After: line 2 handles tracing, the rest would be present without tracing

com.palantir.logsafe.exceptions.SafeRuntimeException: Stack Trace
        at com.palantir.tracing.TracerTest.lambda$testStackDepth$9(TracerTest.java:486)
        at com.palantir.tracing.Tracers$TracingAwareRunnable.run(Tracers.java:409)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
        at java.lang.Thread.run(Thread.java:748)

==COMMIT_MSG==

Possible downsides?

none.

@carterkozak carterkozak requested a review from a team as a code owner October 10, 2019 22:14
@changelog-app
Copy link

changelog-app bot commented Oct 10, 2019

Generate changelog in changelog/@unreleased

Type

  • Feature
  • Improvement
  • Fix
  • Break
  • Deprecation
  • Manual task
  • Migration

Description

Tracing aware executors wrap Runnables and Callables more cleanly

Check the box to generate changelog(s)

  • Generate changelog entry

@robert3005
Copy link
Contributor

@carterkozak I actually think your description is great as a commit message instead of one sentence summary.

@carterkozak
Copy link
Contributor Author

Good call, updated

@iamdanfox
Copy link
Contributor

Is there a way of including an assertion about the stackframes here? The new ones are very neat and don't want to accidentally regress!

@carterkozak
Copy link
Contributor Author

Firstly, we should not optimize around stack depth in most cases
because it can result in large methods that the JVM cannot efficiently
inline and additional GC pressure depending on the implementation.

However, we use tracing a lot, a tracing wrapped executor shows up
in ~50% of stack traces in a large internal service, and exceptions
propagate through multiple executors in many cases.
This would not make sense to change if the tracing stack frames
provided information, but wrapping from runnable to callable
isn't helpful, nor are lambda frames to turn a Callable into
a ThrowingCallable.

This change is completely internal to tracing and does not expose
any new public APIs.

Before: frames 2, 3, 4, and 5 are from tracing
```
com.palantir.logsafe.exceptions.SafeRuntimeException: Stack Trace
        at com.palantir.tracing.TracerTest.lambda$testStackDepth$9(TracerTest.java:486)
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
        at com.palantir.tracing.DeferredTracer.withTrace(DeferredTracer.java:104)
        at com.palantir.tracing.Tracers$TracingAwareCallable.call(Tracers.java:356)
        at com.palantir.tracing.WrappingExecutorService.lambda$wrapTask$0(WrappingExecutorService.java:67)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
        at java.lang.Thread.run(Thread.java:748)
```

After: line 2 handles tracing, the rest would be present without tracing
```
com.palantir.logsafe.exceptions.SafeRuntimeException: Stack Trace
        at com.palantir.tracing.TracerTest.lambda$testStackDepth$9(TracerTest.java:486)
        at com.palantir.tracing.Tracers$TracingAwareRunnable.run(Tracers.java:409)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
        at java.lang.Thread.run(Thread.java:748)
```
@carterkozak carterkozak force-pushed the ckozak/tracing_stack_frames branch from bc57f2d to 5fa5616 Compare October 11, 2019 13:12
@carterkozak
Copy link
Contributor Author

Updated, added docs to the tests to make the intent clear.

Copy link
Contributor

@iamdanfox iamdanfox left a comment

Choose a reason for hiding this comment

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

Thanks Carter!

@bulldozer-bot bulldozer-bot bot merged commit f24f16f into develop Oct 11, 2019
@bulldozer-bot bulldozer-bot bot deleted the ckozak/tracing_stack_frames branch October 11, 2019 14:41
@svc-autorelease
Copy link
Collaborator

Released 3.3.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants