Merge branch 'master' into dev

This commit is contained in:
ciniao 2023-12-14 11:28:52 +08:00
commit 941d74195d
3 changed files with 95 additions and 5 deletions

View File

@ -29,6 +29,25 @@ if (env.SERVER_ID) {
//读取服务配置
const config = fs.existsSync(path.resolve(__dirname, 'config.json')) ? JSON.parse(fs.readFileSync(path.resolve(__dirname, 'config.json'), 'utf-8')) : {};
const dis = config.serverId != undefined ? config.serverId : '0';
let instancesNum = 8;
if(config.openTime){
let openDate = new Date(config.openTime);
//计算openTime距离今天的天数
let today = new Date();
// 获取两个日期之间的毫秒差
let timeDiff = today.getTime() - openDate.getTime();
// 将毫秒差转换为天数
let daysDiff = Math.floor(timeDiff / (1000 * 3600 * 24));
console.log(`已开服天数:${daysDiff}`);
//如果开服超过3天的区则只开区2个进程
if(daysDiff > 3){
instancesNum = 2;
}
}
const localApps = [
{
// 应用程序名称
@ -38,7 +57,7 @@ const localApps = [
// 应用程序所在的目录
cwd: './',
//集群实例数量0表示根据cpu核心数自动控制
instances: 8,
instances: instancesNum,
// 传递给脚本的参数
args: '-serverType msg',
// 是否启用监控模式默认是false。如果设置成true当应用程序变动时pm2会自动重载。这里也可以设置你要监控的文件。

View File

@ -9,7 +9,7 @@ async function connGameLogDB() {
}else{
logDBUrl = "mongodb://root:lyMaple525458@10.0.1.20:27017/heijiao_gamelog?authSource=admin";
}
let client = await MongoClient.connect(logDBUrl);
let client = await MongoClient.connect(logDBUrl,{maxPoolSize:10});
logDB = client.db(`gameLog${G.config.serverId}`);
return logDB;
}

View File

@ -5,6 +5,7 @@ import {
IndexDescription,
IndexSpecification,
MongoClient,
MongoClientOptions,
ObjectId,
OptionalId
} from 'mongodb';
@ -16,6 +17,7 @@ import {MongodbCollections} from './module/mongodb';
import {HuoDongFun} from './public/huodongfun';
import {zbsGroup} from './api_s2c/hbzb/zbs/fun';
import {clusterRunOnce} from './clusterUtils';
import { PublicShared } from './shared/public/public';
const indexs: Partial<{ [k in keyof MongodbCollections]: IndexDescription[] }> = {
item: [
@ -349,9 +351,37 @@ const indexs: Partial<{ [k in keyof MongodbCollections]: IndexDescription[] }> =
};
const crossIndexs: Partial<{ [k in keyof MongodbCollections]: IndexDescription[] }> = {
email: [
{
key: {sid: 1}
},
{
key: {uid: 1}
}
],
fightLog: [
{
key: {uid: 1, type: 1}
},
{
key: {uid: 1}
},
{
key: {ttl: 1}, expireAfterSeconds: 7 * 24 * 3600
}
],
hbzb_user_cross: [
{
key: {uid: 1}, unique: true
},
{
key: {jifen: 1}
},
{
key: {rank: 1}
},
{
key: {zbsgroup: 1}
}
],
hbzb_user_zbs: [
@ -377,13 +407,52 @@ const crossIndexs: Partial<{ [k in keyof MongodbCollections]: IndexDescription[]
rankList: [
{
key: {type: 1, idKey: 1}, unique: true
}
},
{
key: {valArr: -1}
},
],
wzry_fight: [
{
key: {jifen: 1}
},
{
key: {uid: 1}
},
{
key: {zkey: 1}
},
],
wzry_user_cross: [
{
key: {jifen: 1}
},
{
key: {uid: 1}
},
{
key: {zkey: 1}
},
]
};
export async function initMongoDB() {
//mongodb连接数说明https://blog.csdn.net/for_cxc/article/details/116859714
//可结合查看node_modules\mongodb\lib\connection_string.js
//maxPoolSize默认值100
let option:MongoClientOptions;
//跨服只有1个直接采用默认配置就行
if(G.argv.serverType != 'cross'){
if(PublicShared.getOpenServerDay() > 3){
option = {
maxPoolSize: 10
}
}
}
console.log('connect mongodb ......');
let client = await MongoClient.connect(G.argv.serverType == 'cross' ? G.config.crossMongodbUrl : G.config.mongodbUrl);
let client = await MongoClient.connect(G.argv.serverType == 'cross' ? G.config.crossMongodbUrl : G.config.mongodbUrl, option);
G.mongodb = new _mongodb(client.db(G.config.dbName || ''));
console.log('connect mongodb succ');
@ -391,7 +460,9 @@ export async function initMongoDB() {
if (G.argv.serverType != 'cross') {
console.log('connect crossmongodb ......');
//本服里,维持住跟跨服数据库的链接
let crossClient = await MongoClient.connect(G.config.crossMongodbUrl);
let crossClient = await MongoClient.connect(G.config.crossMongodbUrl,{
maxPoolSize:10
});
G.crossmongodb = new _mongodb(crossClient.db(G.config.corssDBName || ""));
console.log('connect crossmongodb succ');
}