连接到远程mongodb时,请求时间太慢

时间:2019-06-20 07:26:52

标签: mongodb express mongoose

通过猫鼬连接时,我有Express应用程序

mongoose.connect(process.env.DB_URL,{
    reconnectInterval: 500, // Reconnect every 500ms
    poolSize: 10, // Maintain up to 10 socket connections
    // If not connected, return errors immediately rather than waiting for reconnect
    bufferMaxEntries: 0,
    connectTimeoutMS: 10000, // Give up initial connection after 10 seconds
    socketTimeoutMS: 45000, // Close sockets after 45 seconds of inactivity
    useNewUrlParser: true,
    auto_reconnect: true,
    // useMongoClient: true
})
const db = mongoose.connection
db.on('error', console.error.bind(console, 'connection error:'))
db.once('open', function() {
    console.log('connected to mongoDB')
})


当我使用localhost / dbname时,请求需要7或10毫秒 但是连接到Atlas群集时需要2到4秒

然后我将应用程序部署在heroku上,并悄悄地降低了请求速度

0 个答案:

没有答案