-
Notifications
You must be signed in to change notification settings - Fork 2
ContinuousProfiling2
Zoltan Farkas edited this page Dec 26, 2019
·
4 revisions
As seen at, using the spf4j profiler, you can materialize the request attributed samples of a slow request to your log file and visualize it easily. For fast requests however request attribution will work only at an aggregate level. You can customize the spf4j profiler together aggregate together samples according to your application needs.
Here is an example where we aggregate the samples by the HTTP method:
// Enable Continuous profiling aware ExecutionContext
System.setProperty("spf4j.execContext.tlAttacherClass", ProfilingTLAttacher.class.getName());
System.setProperty("spf4j.execContext.factoryClass", ProfiledExecutionContextFactory.class.getName());
Sampler sampler = new Sampler(Integer.getInteger("app.profiler.sampleTimeMillis", 10),
(t) -> new TracingExecutionContexSampler(contextFactory::getCurrentThreadContexts,
(ctx) -> {
// group by for the sample aggregations.
// profiles will be aggregated across the HTTP method of the request.
// There will be a ssdump3 file with samples broken down by http method.
String name = ctx.getName();
if (name.startsWith("GET")) {
return "GET";
} else if (ctx.getName().startsWith("POST")) {
return "POST";
} else {
return "OTHER";
}
}));
sampler.start();
When deploying your app with the profiler actuator your app will be able to serve it's profiling information.
You can see what profiling aggregation groups you have, you can see the profile raw data, and ultimately visualize the data.
The example links above are served by a live demo running on GKE.
Enjoy.