asyncer-io / r2dbc-mysql

Reactive Relational Database Connectivity for MySQL. The official successor to mirromutth/r2dbc-mysql(dev.miku:r2dbc-mysql).
https://r2dbc.io
Apache License 2.0
208 stars 21 forks source link

[bug] Why is r2dbc always executed on the same thread ? #292

Closed threeMonthee closed 1 week ago

threeMonthee commented 2 weeks ago

I used springwebflux + r2dbc-mysql to build the web project. In my tests, I found that most database operations were always performed in the same thread, resulting in 80% cpu load on that thread. I checked the driver and reactor-netty-core source code and found nothing wrong. The eventloopGroup in reactor-netty in the driver is multithreaded, but it turns out that with spring connection pooling, all connected channels are bound to an eventloop.

image

threeMonthee commented 2 weeks ago

my pom:

com.siyuchat.im reactive-remoting-service 1.0-SNAPSHOT
    <dependency>
        <groupId>com.siyuchat.im</groupId>
        <artifactId>message-api</artifactId>
        <scope>runtime</scope>
    </dependency>
    <dependency>
        <groupId>com.websiyu.im.sdk</groupId>
        <artifactId>im-sdk-user-api</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-bootstrap</artifactId>
    </dependency>
    <dependency>
        <groupId>com.alibaba.cloud</groupId>
        <artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
    </dependency>
    <dependency>
        <groupId>com.alibaba.cloud</groupId>
        <artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
    </dependency>
    <dependency>
        <groupId>com.siyuchat.im</groupId>
        <artifactId>sy-connect-user-starter</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-webflux</artifactId>
        <version>3.3.1</version>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-actuator</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-r2dbc</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-redis-reactive</artifactId>
    </dependency>
    <dependency>
        <groupId>org.redisson</groupId>
        <artifactId>redisson-spring-boot-starter</artifactId>
        <exclusions>
            <exclusion>
                <groupId>org.redisson</groupId>
                <artifactId>redisson-spring-data-32</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
    <dependency>
        <groupId>org.redisson</groupId>
        <artifactId>redisson-spring-data-30</artifactId>
    </dependency>
    <dependency>
        <groupId>io.asyncer</groupId>
        <artifactId>r2dbc-mysql</artifactId>
        <version>1.1.3</version>
    </dependency>
    <dependency>
        <groupId>org.apache.commons</groupId>
        <artifactId>commons-lang3</artifactId>
    </dependency>
    <dependency>
        <groupId>com.google.guava</groupId>
        <artifactId>guava</artifactId>
    </dependency>
    <dependency>
        <groupId>com.github.ben-manes.caffeine</groupId>
        <artifactId>caffeine</artifactId>
    </dependency>
    <dependency>
        <groupId>io.opentelemetry</groupId>
        <artifactId>opentelemetry-api</artifactId>
        <version>${version.opentelemetry}</version>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>

    <dependency>
        <groupId>io.micrometer</groupId>
        <artifactId>micrometer-registry-prometheus</artifactId>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-validation</artifactId>
    </dependency>
</dependencies>
jchrys commented 2 weeks ago

Hi, @threeMonthee. It looks like an issue in R2DBC pool. which version of r2dbc-pool are you using? seems latest r2dbc-pool would fix the issue.

threeMonthee commented 2 weeks ago

Hi, @threeMonthee. It looks like an issue in R2DBC pool. which version of r2dbc-pool are you using? seems latest r2dbc-pool would fix the issue.

I use spring-webflux:3.0.2 and r2dbc-pool is 1.0.0.RELEASE.

threeMonthee commented 2 weeks ago

Hi, @threeMonthee. It looks like an issue in R2DBC pool. which version of r2dbc-pool are you using? seems latest r2dbc-pool would fix the issue.

jchrys commented 2 weeks ago

I use spring-webflux:3.0.2 and r2dbc-pool is 1.0.0.RELEASE.

Could you upgrade to version 1.0.2 to see if the issue still occurs?