English 中文(简体)
采用同一集合体进行硬处理
原标题:Make shard processes use the same pool
The bounty expires in 6 days. Answers to this question are eligible for a +50 reputation bounty. Hasan Kayra wants to draw more attention to this question.

我想在我的硬性管理人(服务器)中建立一个人才库,然后通过硬程序(机器人)。 这里是我的hard夫经理(服务器):

var clientMysqlEvent = require( ./database/botpool.js ).connection;
const flatted = require( flatted );
const clientMysqlEventserialized = flatted.stringify(clientMysqlEvent);
const { ShardingManager } = require( discord.js );
  const shard = new ShardingManager( ./bot.js , {
    token: config.token,
    respawn: true,
  });
  shard.spawn({ amount: splen, delay: 100, timeout: 120000 }); 
    //console.log(`[DEBUG/SHARD] Shard ${shard.id} connected to Discord s Gateway.`)
    // Sending the data to the shard.
    shard.on("ready", () => {
      console.log(`[SHARD] Shard ${formatedShardId} connected to Discord s Gateway.`)
      // Sending the data to the shard.
      shard.send({type: "shardId", data: {shardId: shard.id, shardTotal: splen}});
      shard.send({type: "myDb", data: {dbManager: clientMysqlEventserialized}});
});

底部:

const mysql  = require( mysql );
    var connection = mysql.createPool({
      connectionLimit : 20,
      host     :  localhost ,
      user     :  user ,
      password :  pass ,
      database :  db 
    });
    connection.on( release , function (connection1) {
        console.log( BOT: Connection %d released , connection1.threadId);
      });
    connection.on( acquire , function (connection1) {
        console.log( BOT: Connection %d acquired , connection1.threadId);
      });
    connection.on( connection , function (connection1) {
        console.log( BOT: Connection %d connected , connection1.threadId);
      });
    connection.on( enqueue , function () {
        console.log( BOT: Waiting for available connection slot );
      });
    exports.connection = connection;

伊斯兰教进程(下院):

const flatted = require( flatted );
var mysql = null;
process.on( message , message => {
  if (!message.type) return false;
  if (message.type == "shardId") {
    console.log(`The shard id is: ${message.data.shardId + Number(1)}`);
    console.log(`Total shard number is: ${message.data.shardTotal}`)
    clientShardId = message.data.shardId + Number(1)
    totalShardIds = message.data.shardTotal
    console.log("Captured data: "+clientShardId+"/"+totalShardIds)
    client.user.setPresence({ activities: [{ name: `${config.activities} [${message.data.shardId + Number(1)} / ${message.data.shardTotal}]` }] });
} else if (message.type == "myDb") {
    //mysql = message.data.dbManager;
    mysql = flatted.parse(message.data.dbManager);
    //console.log("mysql:")
    //console.log(mysql)
};
})

令人痛心的是,这种做法没有做我所想要的,而艰难的过程(下士)却创造了自己的人才。

问题回答

Let me try to solve your problem but I can t confirm if it is correct. The reason your approach is not working is that you are creating the pool connection in the shard manager and then trying to send the connection object to the shard process. However, the connection object cannot be serialized and sent over the IPC channel.

根据上述观点,你可以尝试:

  1. Create the pool connection in the shard process (bot.js) instead of the shard manager (server.js).
  2. Send the database connection configuration (such as the host, user, password, and database name) to the shard process.
  3. Use the database connection configuration in the shard process to create the pool connection.




相关问题
SQL SubQuery getting particular column

I noticed that there were some threads with similar questions, and I did look through them but did not really get a convincing answer. Here s my question: The subquery below returns a Table with 3 ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

php return a specific row from query

Is it possible in php to return a specific row of data from a mysql query? None of the fetch statements that I ve found return a 2 dimensional array to access specific rows. I want to be able to ...

Character Encodings in PHP and MySQL

Our website was developed with a meta tag set to... <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> This works fine for M-dashes and special quotes, etc. However, I ...

Pagination Strategies for Complex (slow) Datasets

What are some of the strategies being used for pagination of data sets that involve complex queries? count(*) takes ~1.5 sec so we don t want to hit the DB for every page view. Currently there are ~...

Averaging a total in mySQL

My table looks like person_id | car_id | miles ------------------------------ 1 | 1 | 100 1 | 2 | 200 2 | 3 | 1000 2 | 4 | 500 I need to ...

热门标签