Measuring Camel Performance

29 views Asked by At

I'm suspicious of my times to process messages due to it varying widely regardless of number of consumers and numbers of threads.

My code is:

@Component
@Scope("prototype")
public class ThreadStopWatch {
    private long startCpuTime = -1;
    private long stopCpuTime = -1;
    public Long start() {
        startCpuTime = System.nanoTime();
        stopCpuTime = startCpuTime;
    }
    public getElapsedTime() {
        stopCpuTime = System.nanoTime();
        return stopCpuTime - startCpuTime;
    }
}
...
private ThreadStopWatch threadStopWatch;

public configure(...) {
    for(Endpoint endpoint: myendpoints) {
        if(endpoint !=null) {
            from(endpoint).to(aggregate)
        }
    }
    from(aggregate).routeId(ROUTEBUILDER_ID)
        .log("Payload ${body}")
        .process(e->threadStopWatch.start())
        .bean(config, "unmarshalObject")
        .bean(mapper, "map")
        .marshal()
        .json(JsonLibrary.Gson)
        .threads(min_size,max_size).id(ROUTEBUILDER_THREAD_ID)
        .process(e-> {
            long elapsedTime = threadStopWatch.getElapsedTime();
            e.getIn().setHeader("elapsedTime",elapsedTime);
        })
        .log("Elapsed time: ${header.elapsedTime} nanoseconds")
        .end();
}

I was spending a lot of time figuring out the Apache Camel inside of a Spring Boot application to create a stopwatch for that specific message. While I thought I did it properly, I'm not certain that each message will get a new ThreadStopWatch and a valid time. I'd like to have a valid ThreadStopWatch for each message.

System.nanoTime is going to give wall time and I realize this is a shortcoming, especially since it's a multi-threaded app. What would be a better timing mechanism less polluted with other threads?

0

There are 0 answers