Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/amazon-web-services/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js 当我的nodejs应用程序非常快时,为什么我的ttfb非常高?_Node.js_Amazon Web Services_Amazon Ec2_Amazon Ecs - Fatal编程技术网

Node.js 当我的nodejs应用程序非常快时,为什么我的ttfb非常高?

Node.js 当我的nodejs应用程序非常快时,为什么我的ttfb非常高?,node.js,amazon-web-services,amazon-ec2,amazon-ecs,Node.js,Amazon Web Services,Amazon Ec2,Amazon Ecs,我有提供html文件的nodejs应用程序: const index = resolve('public/index.html'); const html = fs.existsSync(index) ? fs.readFileSync(index, 'utf-8') : ''; app.get('*', (req, res) => { res.set('Content-Type', 'text/html'); res.send(html); res.end(); //

我有提供html文件的nodejs应用程序:

const index = resolve('public/index.html');
const html = fs.existsSync(index) ? fs.readFileSync(index, 'utf-8') : '';
app.get('*', (req, res) => {

  res.set('Content-Type', 'text/html');
  res.send(html);
  res.end();
  // res.sendFile(resolve('public/index.html'));
});
我的应用程序在aws中:web->ALB(aws)->nginx->nodejs

我的问题是ttfb对于所有资源来说都太长了

从cloudwatch查看
/
url:

同时从我的devtools(大约157ms):

这就是我如何知道处理请求需要多少时间:

  const startHrTime = process.hrtime();

  res.on('finish', () => {
    const elapsedHrTime = process.hrtime(startHrTime);
    const elapsedTimeInMs = elapsedHrTime[0] * 1000 + elapsedHrTime[1] / 1e6;
    console.log('%s : %fms', req.path, elapsedTimeInMs);
  });

那么,为什么我会得到这么高的
ttfb
,我能做些什么呢?

您是否尝试过在生产模式下运行Node?这真是太快了。它处于生产模式,而且,您正在读取一个文件(同步地,在此之上)。所以,这需要时间不,不,对不起,我的错误。我编辑我的问题。我不会每次都读取该文件,这是在我的生产服务器中读取该文件的方式