Comments (5)
已收到您的请求,预计今天排查更新
from cool-admin-midway.
这种高频的调用,建议你将连接数提高,
from cool-admin-midway.
每个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.
还有情况,可能存在在循环中调用CoolRpcTransaction 包裹的方法,这样就是再多是数据库连接也不够浪费的。
from cool-admin-midway.
程序设计 不应该存在 循环调用事务,得尽量避免这种情况
from cool-admin-midway.
Related Issues (20)
- /admin/base/open/eps restful function returns empty object
- @cool-midway/task 有重大bug
- 腾讯COS文件上传不可用,一直403,阿里云正常 HOT 1
- 创建一个视图的实体类后, 运行会报错。
- 编译后部署启动报错,提示缺少 config.ts 文件
- cool-search模糊搜索问题
- 在文件管理中上传视频,服务端报错 HOT 3
- v7的本地开发遇到的关于swagger问题 HOT 1
- 新版本,兼容Mysql、PostgreSQL、Sqlite 非管理员用户,登录获取菜单有问题 HOT 4
- sqlite不支持json格式字段,当使用slqite时,插件系统功能受影响
- 建议插件增加安装时执行插件__install__,卸载时执行__uninstall__函数,用于插件内部进行安装卸载的自定义操作 HOT 2
- 模块的加载与否可以通过配置文件设置
- 请问一下,这个项目支持单文件构建吗? HOT 1
- 7.1 使用 sqlite 时区问题
- 上传返回的图片路径是不是不太对? HOT 1
- 为什么 onetomany manytoone 无效 HOT 1
- v7的本地开发遇到的关于swagger没有参数
- 请问支持多表关联查询API吗?有没有例子 HOT 1
- 最新7.X 配置多数据源,报错 HOT 2
- dev启动报错 HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cool-admin-midway.