为什么我写入 MongoDB Atlas 的 Azure 函数的冷启动时间超过 70 秒?
Why does my Azure Function to write to MongoDB Atlas have >70s cold start time?
请问是不是我的函数有通用问题,导致冷启动这么久。 Mongoose 已作为依赖项安装,这可能会增加时间。但是 70 年代?!?加油...
这是我的代码。真的很简单。只想写一些东西给 MongoDB。感谢任何反馈。
module.exports = function(context, req) {
context.log("Function started!");
// Database interaction.
const mongoose = require('mongoose');
const DATABASE = process.env.MongodbAtlas;
// Connect to our Database and handle any bad connections
mongoose.connect(DATABASE);
mongoose.Promise = global.Promise; // Tell Mongoose to use ES6 promises
mongoose.connection.on('error', (err) => {
context.log(`ERROR→ ${err.message}`);
});
// Portfolio Schema.
require('./portfolioModel');
const Portfolio = mongoose.model('Portfolio');
//Create a Portfolio object.
var portfolio = new Portfolio();
portfolio.fiat = "EUR";
portfolio.token[0] = {
crypto_ticker: "BTC",
crypto_name: "Bitcoin",
crypto_qty: 50,
crypto_invested_sum: 9000
};
// Save to db.
portfolio.save();
context.done();
};
使用 Azure Functions extension for VS Code. The extension is automatically creating a package file and sets WEBSITE_RUN_FROM_PACKAGE=1 (some in-depth infos regarding packaging) 后,冷启动时间减少到 3 秒左右。
现在 "Functions as a Service" 变得更有趣了。
请问是不是我的函数有通用问题,导致冷启动这么久。 Mongoose 已作为依赖项安装,这可能会增加时间。但是 70 年代?!?加油...
这是我的代码。真的很简单。只想写一些东西给 MongoDB。感谢任何反馈。
module.exports = function(context, req) {
context.log("Function started!");
// Database interaction.
const mongoose = require('mongoose');
const DATABASE = process.env.MongodbAtlas;
// Connect to our Database and handle any bad connections
mongoose.connect(DATABASE);
mongoose.Promise = global.Promise; // Tell Mongoose to use ES6 promises
mongoose.connection.on('error', (err) => {
context.log(`ERROR→ ${err.message}`);
});
// Portfolio Schema.
require('./portfolioModel');
const Portfolio = mongoose.model('Portfolio');
//Create a Portfolio object.
var portfolio = new Portfolio();
portfolio.fiat = "EUR";
portfolio.token[0] = {
crypto_ticker: "BTC",
crypto_name: "Bitcoin",
crypto_qty: 50,
crypto_invested_sum: 9000
};
// Save to db.
portfolio.save();
context.done();
};
使用 Azure Functions extension for VS Code. The extension is automatically creating a package file and sets WEBSITE_RUN_FROM_PACKAGE=1 (some in-depth infos regarding packaging) 后,冷启动时间减少到 3 秒左右。
现在 "Functions as a Service" 变得更有趣了。