小编Ofe*_*r B的帖子

在node.js中通过node-fetch重用TCP连接

我正在使用这个函数来调用外部API

const fetch = require('node-fetch');

fetchdata= async function (result = {}) {
  var start_time = new Date().getTime();

    let response = await fetch('{API endpoint}', {
      method: 'post',
      body: JSON.stringify(result),
      headers: { 'Content-Type': 'application/json' },
      keepalive: true

    });

  console.log(response) 
  var time = { 'Respone time': + (new Date().getTime() - start_time) + 'ms' };
  console.log(time)
  return [response.json(), time];
  
}
Run Code Online (Sandbox Code Playgroud)

问题是,我不确定每次使用此函数时,node.js 是否都会重用与 API 的 TCP 连接,尽管我定义了 keepalive 属性。

重用 TCP 连接可以显着提高响应时间
任何建议都将受到欢迎。

http fetch node.js node-fetch

8
推荐指数
1
解决办法
1万
查看次数

使用 Node.js 中的 fetch 测量 API 响应时间

我的 Node.js 应用程序中的功能之一是使用 fetch 函数调用外部 API。我正在尝试找到最准确的方法来测量上述 API 的响应时间。

我正在使用“日期”方法来做到这一点:

     let start_time = new Date().getTime();
      fetch('https://jsonplaceholder.typicode.com/posts/1')
  .then((res) => {
    return res.json();
  })
.then((data) => {
  console.log('Response time:', new Date().getTime() - start_time);
Run Code Online (Sandbox Code Playgroud)

有没有更好\更准确的方法来执行 fetch?

performance-testing node.js fetch-api

7
推荐指数
1
解决办法
1万
查看次数

初始化 Apache Airflow docker 时没有名为“airflow”的模块

我正在尝试在 Centos 7 机器上作为 docker 运行 apache airflow。 当我尝试通过运行 docker-compose up airflow-init 来初始化 docker 时,我遵循了此处的所有说明: https: //airflow.apache.org/docs/apache-airflow/stable/start/docker.html

我收到这个错误

[root@centos7 centos]# docker-compose up airflow-init
Creating network "centos_default" with the default driver
Creating volume "centos_postgres-db-volume" with default driver
Creating centos_redis_1    ... done
Creating centos_postgres_1 ... done
Creating centos_airflow-init_1 ... done
Attaching to centos_airflow-init_1
airflow-init_1       | BACKEND=postgresql+psycopg2
airflow-init_1       | DB_HOST=postgres
airflow-init_1       | DB_PORT=5432
airflow-init_1       |
airflow-init_1       | Traceback (most recent call last):
airflow-init_1       |   File "/home/airflow/.local/bin/airflow", line 5, in <module>
airflow-init_1       |     from …
Run Code Online (Sandbox Code Playgroud)

docker-compose airflow

7
推荐指数
1
解决办法
1万
查看次数