Giter Site home page Giter Site logo

Comments (5)

cool-team-official avatar cool-team-official commented on June 19, 2024

已收到您的请求,预计今天排查更新

from cool-admin-midway.

cool-team-official avatar cool-team-official commented on June 19, 2024

这种高频的调用,建议你将连接数提高,

from cool-admin-midway.

hanxiaolong-github avatar hanxiaolong-github commented on June 19, 2024

每个CoolRpcTransaction 打开一个新的数据库连接,这样很浪费数据库连接,会导致系统能同时支持的用户访问数量减少。也不是多麻烦的修改,几句code 就能解决。
下面这个修改我是经过压力测试的。
return (target, propertyKey, descriptor) => {
const method = descriptor.value;
descriptor.value = async function (...args) {
let rpcTransactionId;
let isCaller;

    // 获取传送过来的 rpcTransactionId
    // 尝试从第一个参数中获取。
    if (args[0]) {
      rpcTransactionId = args[0].rpcTransactionId;
    }
    // 尝试从第二个参数中获取
    if(args[1] && !rpcTransactionId){
      rpcTransactionId = args[1];
    }
    
    
    if(rpcTransactionId){
      isCaller = false;
    }
    else{// 如果没有事务ID,手动创建 
      isCaller = true;
      rpcTransactionId = uuid_1.v1();
    }
    
    let data;
    let queryRunner;
    if(global['moleculer.transactions'][rpcTransactionId]){
        queryRunner = global['moleculer.transactions'][rpcTransactionId];
    }else{
        const connection = typeorm_1.getConnection((option === null || option === void 0 ? void 0 : option.connectionName) || 'default');
        queryRunner = connection.createQueryRunner();
        // 使用我们的新queryRunner建立真正的数据库连
        console.log('start connect....')
        await queryRunner.connect();
        console.log('end connect....')
        if (option && option.isolation) {
            await queryRunner.startTransaction(option.isolation);
        }
        else {
            await queryRunner.startTransaction();
        }
    }
    try {
        global['moleculer.transactions'][rpcTransactionId] = queryRunner;
        // 半小时后清除
        setTimeout(() => {
            if(global['moleculer.transactions'][rpcTransactionId]){
                global['moleculer.transactions'][rpcTransactionId].release();
                delete global['moleculer.transactions'][rpcTransactionId];
            }
        }, 1800 * 1000);
        data = await method.apply(this, [
            ...args,
            rpcTransactionId,
            queryRunner,
        ]);
        if (isCaller) {
            global['moleculer:broker'].broadcast('moleculer.transaction', {
                rpcTransactionId,
                commit: true,
            });
        }
        //await queryRunner.commitTransaction();
    }
    catch (error) {
        //await queryRunner.rollbackTransaction();
        if (isCaller) {
            global['moleculer:broker'].broadcast('moleculer.transaction', {
                rpcTransactionId,
                commit: false,
            });
        }
        console.log(error);
        console.log(error.stack);
        throw new core_1.CoolCommException(error.message);
    }
    return data;
};
return descriptor;

};

from cool-admin-midway.

hanxiaolong-github avatar hanxiaolong-github commented on June 19, 2024

还有情况,可能存在在循环中调用CoolRpcTransaction 包裹的方法,这样就是再多是数据库连接也不够浪费的。

from cool-admin-midway.

cool-team-official avatar cool-team-official commented on June 19, 2024

程序设计 不应该存在 循环调用事务,得尽量避免这种情况

from cool-admin-midway.

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.