Git Product home page Git Product logo

Comments (7)

ttddyy avatar ttddyy commented on May 28, 2024 2

@binakot wrote a wiki page for that.
https://github.com/ttddyy/datasource-proxy/wiki/Logging-slow-queries

from datasource-proxy.

ttddyy avatar ttddyy commented on May 28, 2024

Regular query logging listeners write out query after execution has finished. So, it has time populated.
For slow query loggers, it writes out query when it passed threshold time. For example, if a query takes 10min and threshold time is set to 1min, the slow query logger prints out query when it passed 1 min while query is still running.

Currently, slow query logger is not updating execution time(elapsed time). So, it'll always show 0 in time.
I'll update to populate the time with current elapsed time. So, for slow queries, it will show threshold time(or threshold time +alpha based on when scheduler execute the thread) in time field.
(1min for above example).

Meanwhile, you can update slow query class like this to achieve same behavior:

SLF4JSlowQueryListener slowQueryListener = new SLF4JSlowQueryListener(...) {
    @Override
    protected void onSlowQuery(ExecutionInfo execInfo, List<QueryInfo> queryInfoList, long startTimeInMills) {
        execInfo.setElapsedTime(System.currentTimeMillis() - startTimeInMills);
        super.onSlowQuery(execInfo, queryInfoList, startTimeInMills);
    }
};

from datasource-proxy.

nhoughto avatar nhoughto commented on May 28, 2024

from datasource-proxy.

ttddyy avatar ttddyy commented on May 28, 2024

Ok, so you want to log queries after they have finished which includes actual query execution time, only when they exceed threshold time.

In that case, you can use regular query logging listeners extending them to write query only when it took longer than threshold.

long thresholdInMills = ...
SLF4JQueryLoggingListener listener = new SLF4JQueryLoggingListener(){
    @Override
    public void afterQuery(ExecutionInfo execInfo, List<QueryInfo> queryInfoList) {
        if (execInfo.getElapsedTime() >= thresholdInMills) {
            super.afterQuery(execInfo, queryInfoList);
        }
    }
};
listener.setLogLevel(SLF4JLogLevel.WARN);

from datasource-proxy.

nhoughto avatar nhoughto commented on May 28, 2024

Perfect thanks

from datasource-proxy.

binakot avatar binakot commented on May 28, 2024

I was confused with that too. Good that I checked closed issues.
An hour ago I was ready to submit a new bug. 😄
I think this information should to add in the documentation with this example.

from datasource-proxy.

binakot avatar binakot commented on May 28, 2024

@ttddyy Awesome! Thanks!

from datasource-proxy.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.