-
Notifications
You must be signed in to change notification settings - Fork 957
Use Sampler
to determine whether to fill stack trace
#2111
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
Conversation
Motivation: `Flags.verboseExceptions()` gives a user only two choices - enabling stacktrace for all exceptions or not. We could let a user take trade-offs by allowing him or her to specify a `Sampler` specification. Modifications: - Accept a `Sampler` specification string as a value of the `com.linecorp.armeria.verboseExceptions` system property. - Use the default specification of `rate-limited=1`, which allows one trace per second per exception type. - Note that `true` and `false` are translated into `always` and `never`. - Add `ExceptionSampler` - Replace Flags.verboseExceptions()` with `verboseExceptionSampler()` and `verboseExceptionSamplerSpec()` - Add a benchmark Result: - A user will get the stack trace for some exceptions out of the box, which is a better experience. - Previously, a user had to set `true` to the flag manually. - A user can trade-off between the cost of filling in stack trace and the debuggability in a fine-grained manner. Benchmark result: ``` Benchmark Mode Cnt Score Error Units ExceptionSamplerBenchmark.baseline_singleton thrpt 5 113645503.499 ± 4733673.802 ops/s ExceptionSamplerBenchmark.baseline_withStackTrace thrpt 5 415370.775 ± 117032.077 ops/s ExceptionSamplerBenchmark.baseline_withoutStackTrace thrpt 5 50683298.670 ± 8876147.874 ops/s ExceptionSamplerBenchmark.sampler_always thrpt 5 423056.060 ± 81934.927 ops/s ExceptionSamplerBenchmark.sampler_never thrpt 5 67165540.355 ± 13892391.328 ops/s ExceptionSamplerBenchmark.sampler_rateLimited thrpt 5 15781563.939 ± 1037630.515 ops/s ```
@adriancole You might find this interesting. |
|
89c9d4c
to
2bc6273
Compare
benchmarks/src/jmh/java/com/linecorp/armeria/common/ExceptionSamplerBenchmark.java
Outdated
Show resolved
Hide resolved
private final String spec; | ||
|
||
ExceptionSampler(String spec) { | ||
samplerFactory = unused -> Sampler.of(spec); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there any chance that a user wants to set different specs for different exceptions?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure. Perhaps we can consider that when someone asks for it? 😉
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added a comment about this idea to Flags
} | ||
|
||
@Override | ||
public boolean isSampled(Class<? extends Throwable> exceptionType) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so the rationale for the type parameter is solving the overhead problem caused by allocating an exception, correct?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, kind of. If we accepted a Throwable
, we will see a chicken and egg problem. 😄
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice work! 👍
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
16ff042
to
c7af530
Compare
Codecov Report
@@ Coverage Diff @@
## master #2111 +/- ##
============================================
- Coverage 73.78% 73.69% -0.09%
+ Complexity 9491 9488 -3
============================================
Files 833 834 +1
Lines 36545 36585 +40
Branches 4525 4527 +2
============================================
- Hits 26964 26963 -1
- Misses 7253 7292 +39
- Partials 2328 2330 +2
Continue to review full report at Codecov.
|
@@ -23,7 +23,7 @@ | |||
*/ | |||
public class ArmeriaStatusException extends RuntimeException { | |||
|
|||
public static final long serialVersionUID = -8370257107063108923L; | |||
private static final long serialVersionUID = -8370257107063108923L; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
😱
still LGTM 👍 |
@@ -95,16 +95,19 @@ | |||
|
|||
switch (spec) { | |||
case "true": | |||
case "always": |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
Motivation: `Flags.verboseExceptions()` gives a user only two choices - enabling stacktrace for all exceptions or not. We could let a user take trade-offs by allowing him or her to specify a `Sampler` specification. Modifications: - Accept a `Sampler` specification string as a value of the `com.linecorp.armeria.verboseExceptions` system property. - Use the default specification of `rate-limited=10`, which allows 10 traces per second per exception type. - Note that `true` and `false` are translated into `always` and `never`. - Add `ExceptionSampler` - Replace `Flags.verboseExceptions()` with `verboseExceptionSampler()` and `verboseExceptionSamplerSpec()` - The exceptions which never had stack traces can now have stack trace. - Add a benchmark Result: - A user will get the stack trace for some exceptions out of the box, which is a better experience. - Previously, a user had to set `true` to the flag manually. - A user can trade-off between the cost of filling in stack trace and the debuggability in a fine-grained manner. Benchmark result: ``` Benchmark Mode Cnt Score Error Units ExceptionSamplerBenchmark.baseline_singleton thrpt 5 115913078.321 ± 2470676.668 ops/s ExceptionSamplerBenchmark.baseline_withStackTrace thrpt 5 435184.216 ± 68777.567 ops/s ExceptionSamplerBenchmark.baseline_withoutStackTrace thrpt 5 51507410.813 ± 4643400.389 ops/s ExceptionSamplerBenchmark.sampler_always thrpt 5 460633.461 ± 23792.691 ops/s ExceptionSamplerBenchmark.sampler_never thrpt 5 65191830.351 ± 10603815.026 ops/s ExceptionSamplerBenchmark.sampler_random_1 thrpt 5 22901381.973 ± 992182.987 ops/s ExceptionSamplerBenchmark.sampler_random_10 thrpt 5 4131608.570 ± 62347.977 ops/s ExceptionSamplerBenchmark.sampler_rateLimited_1 thrpt 5 16322277.831 ± 591082.048 ops/s ExceptionSamplerBenchmark.sampler_rateLimited_10 thrpt 5 15205268.392 ± 339038.406 ops/s ```
Motivation: `Flags.verboseExceptions()` gives a user only two choices - enabling stacktrace for all exceptions or not. We could let a user take trade-offs by allowing him or her to specify a `Sampler` specification. Modifications: - Accept a `Sampler` specification string as a value of the `com.linecorp.armeria.verboseExceptions` system property. - Use the default specification of `rate-limited=10`, which allows 10 traces per second per exception type. - Note that `true` and `false` are translated into `always` and `never`. - Add `ExceptionSampler` - Replace `Flags.verboseExceptions()` with `verboseExceptionSampler()` and `verboseExceptionSamplerSpec()` - The exceptions which never had stack traces can now have stack trace. - Add a benchmark Result: - A user will get the stack trace for some exceptions out of the box, which is a better experience. - Previously, a user had to set `true` to the flag manually. - A user can trade-off between the cost of filling in stack trace and the debuggability in a fine-grained manner. Benchmark result: ``` Benchmark Mode Cnt Score Error Units ExceptionSamplerBenchmark.baseline_singleton thrpt 5 115913078.321 ± 2470676.668 ops/s ExceptionSamplerBenchmark.baseline_withStackTrace thrpt 5 435184.216 ± 68777.567 ops/s ExceptionSamplerBenchmark.baseline_withoutStackTrace thrpt 5 51507410.813 ± 4643400.389 ops/s ExceptionSamplerBenchmark.sampler_always thrpt 5 460633.461 ± 23792.691 ops/s ExceptionSamplerBenchmark.sampler_never thrpt 5 65191830.351 ± 10603815.026 ops/s ExceptionSamplerBenchmark.sampler_random_1 thrpt 5 22901381.973 ± 992182.987 ops/s ExceptionSamplerBenchmark.sampler_random_10 thrpt 5 4131608.570 ± 62347.977 ops/s ExceptionSamplerBenchmark.sampler_rateLimited_1 thrpt 5 16322277.831 ± 591082.048 ops/s ExceptionSamplerBenchmark.sampler_rateLimited_10 thrpt 5 15205268.392 ± 339038.406 ops/s ```
Motivation:
Flags.verboseExceptions()
gives a user only two choices - enablingstacktrace for all exceptions or not. We could let a user take
trade-offs by allowing him or her to specify a
Sampler
specification.Modifications:
Sampler
specification string as a value of thecom.linecorp.armeria.verboseExceptions
system property.rate-limited=10
, which allows 10traces per second per exception type.
true
andfalse
are translated intoalways
andnever
.ExceptionSampler
Flags.verboseExceptions()
withverboseExceptionSampler()
and
verboseExceptionSamplerSpec()
Result:
which is a better experience.
true
to the flag manually.the debuggability in a fine-grained manner.
Benchmark result: