Coder Social home page Coder Social logo

Comments (2)

wangyu096 avatar wangyu096 commented on April 28, 2024
image

耗时比较长的这个,主要就是批量写入 task_instance_host 表, DAO 层是使用 Jooq。代码如下:

    public void saveTaskInstanceHosts(long taskInstanceId,
                                      Collection<HostDTO> hosts) {
        BatchBindStep batchInsert = ctx.batch(
            ctx.insertInto(TASK_INSTANCE_HOST, TASK_INSTANCE_HOST.TASK_INSTANCE_ID,
                TASK_INSTANCE_HOST.HOST_ID, TASK_INSTANCE_HOST.IP, TASK_INSTANCE_HOST.IPV6)
                .values((Long) null, null, null, null)
        );

        for (HostDTO host : hosts) {
            batchInsert = batchInsert.bind(
                taskInstanceId,
                host.getHostId(),
                host.getIp(),
                host.getIpv6()
            );
        }
        batchInsert.execute();
    }

from bk-job.

wangyu096 avatar wangyu096 commented on April 28, 2024

原因

如果 jdbc 为设置rewriteBatchedStatements= false (默认), 那么即使是调用 Statement.executeBatch(), 也是逐个执行 SQL。关于rewriteBatchedStatements这个参数的介绍:

MySQL的JDBC连接的url中要加rewriteBatchedStatements参数,并保证5.1.13以上版本的驱动,才能实现高性能的批量插入。MySQL JDBC驱动在默认情况下会无视executeBatch()语句,把我们期望批量执行的一组sql语句拆散,一条一条地发给MySQL数据库,批量插入实际上是单条插入,直接造成较低的性能。只有把rewriteBatchedStatements参数置为true, 驱动才会帮你批量执行SQL。另外这个选项对INSERT/UPDATE/DELETE都有效。

参考

from bk-job.

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.