Skip to content

Latest commit

 

History

History
137 lines (97 loc) · 3.54 KB

README-EN.md

File metadata and controls

137 lines (97 loc) · 3.54 KB

🖥️ Multi-DataSource Query Counter

한국어 | English

🖥️ Introduction

This project is a simple tool to measuring query counts in a JDBC API(Spring Data JPA(Hibernate), MyBatis, ...) environment.
You can seamlessly measure query counts also in a Multi-DataSource environment.

Hibernate: 
    select
        id,
        name
    from
        example 
        
Hibernate: 
    select
        count(id) 
    from
        example
                 
ERROR --- 'GET /examples' - totalQueryCount: 2, totalSpendTime: 7ms

🖥️ How to use?

1. Add dependency

Important

Spring Boot 3.x uses jakarta.* packages while Spring Boot 2.x uses javax.* packages. Make sure to select the compatible library version for your project.

Choose the appropriate version based on your Spring Boot version:

Spring Boot Version Library Version
Spring Boot 2.x 2.x.x-spring-boot-2
Spring Boot 3.x 2.x.x-spring-boot-3

In Java Gradle(Groovy DSL)

repositories {
    mavenCentral()
    maven { url 'https://jitpack.io' }
}

dependencies {
    // For Spring Boot 2.x
    implementation 'com.github.Hyeon9mak:multi-datasource-query-counter:2.3.2-spring-boot-2'

    // For Spring Boot 3.x
    // implementation 'com.github.Hyeon9mak:multi-datasource-query-counter:2.3.2-spring-boot-3'
}

In Kotlin Gradle(Kotlin DSL)

repositories {
    mavenCentral()
    maven { url = uri("https://jitpack.io") }
}

dependencies {
    // For Spring Boot 2.x
    implementation("com.github.Hyeon9mak:multi-datasource-query-counter:2.3.2-spring-boot-2")

    // For Spring Boot 3.x
    // implementation("com.github.Hyeon9mak:multi-datasource-query-counter:2.3.2-spring-boot-3")
}

2. Add logging options

The priority order is as follows: error > warn > info.
The default value for enable is false, and the default value for count is 1.

query-counter.logging.level:
  error:
    enable: true
    count: 5
  warn:
    enable: true
    count: 2
  info:
    enable: false

3. Specify the target API

@CountQueries annotation is used to specify the API you want to measure.

@CountQueries
@GetMapping("/examples")
public List<Example> getExamples() {
    return repository.getExamples();
}

4. Check the log

Start the application and check the log.

ERROR --- 'GET /examples' - totalQueryCount: 2, totalSpendTime: 7ms

Enjoy it! 🎉


🖥️ In asynchronous environments


🖥️ Core concepts

image

It's based on the JDBC API and Spring AOP, CGLib proxy.
... That's it!


🖥️ Recommended articles