node.js - 在 alpine 中运行 curl 需要很长时间才能开始

标签 node.js linux alpine-linux

我有一个 node:8.9.2-alpine 图像,我尝试在其中运行

curl -o /dev/null -s -w 'Total: %{time_total}\n' 'https://feed.theplatform.com/' -v

通话需要 6 秒。如果我在本地运行相同的 curl,大约需要 0.5 秒。

我发现nslookup需要一些时间,所以我跑了

RUN apk add --update --no-cache bind-tools

但是我的 curl 仍然需要 6 秒。

/ # curl -o /dev/null -s -w 'Total: %{time_total}\n' 'https://feed.theplatform.com/' -v --trace-time
10:13:54.843110 *   Trying 199.27.170.188...
10:13:54.843198 * TCP_NODELAY set
10:13:54.938974 * Connected to feed.theplatform.com (199.27.170.188) port 443 (#0)
10:13:54.939222 * ALPN, offering http/1.1
10:13:54.950969 * successfully set certificate verify locations:
10:13:54.951041 *   CAfile: /etc/ssl/certs/ca-certificates.crt
  CApath: none
10:13:54.951198 * TLSv1.2 (OUT), TLS handshake, Client hello (1):
10:13:54.951222 } [512 bytes data]
10:13:55.046650 * TLSv1.2 (IN), TLS handshake, Server hello (2):
10:13:55.046875 { [85 bytes data]
10:13:55.047031 * TLSv1.2 (IN), TLS handshake, Certificate (11):
10:13:55.047063 { [3984 bytes data]
10:13:55.047965 * TLSv1.2 (IN), TLS handshake, Server finished (14):
10:13:55.047990 { [4 bytes data]
10:13:55.048175 * TLSv1.2 (OUT), TLS handshake, Client key exchange (16):
10:13:55.048197 } [262 bytes data]
10:13:55.048233 * TLSv1.2 (OUT), TLS change cipher, Client hello (1):
10:13:55.048253 } [1 bytes data]
10:13:55.048338 * TLSv1.2 (OUT), TLS handshake, Finished (20):
10:13:55.048358 } [16 bytes data]
10:13:55.147028 * TLSv1.2 (IN), TLS change cipher, Client hello (1):
10:13:55.147077 { [1 bytes data]
10:13:55.147205 * TLSv1.2 (IN), TLS handshake, Finished (20):
10:13:55.147227 { [16 bytes data]
10:13:55.147273 * SSL connection using TLSv1.2 / AES256-SHA256
10:13:55.147295 * ALPN, server did not agree to a protocol
10:13:55.147339 * Server certificate:
10:13:55.147395 *  subject: C=US; ST=Washington; L=Seattle; O=thePlatform, LLC; OU=Network Operations; CN=feed.theplatform.com
10:13:55.147423 *  start date: Oct 22 22:05:39 2015 GMT
10:13:55.147451 *  expire date: Jan  5 22:35:38 2019 GMT
10:13:55.147495 *  subjectAltName: host "feed.theplatform.com" matched cert's "feed.theplatform.com"
10:13:55.147531 *  issuer: C=US; O=Entrust, Inc.; OU=See www.entrust.net/legal-terms; OU=(c) 2012 Entrust, Inc. - for authorized use only; CN=Entrust Certification Authority -L1K
10:13:55.147553 *  SSL certificate verify ok.
10:13:55.147650 > GET / HTTP/1.1
10:13:55.147650 > Host: feed.theplatform.com
10:13:55.147650 > User-Agent: curl/7.60.0
10:13:55.147650 > Accept: */*
10:13:55.147650 >
10:13:55.244488 < HTTP/1.1 403 Forbidden
10:13:55.244544 < Date: Fri, 13 Jul 2018 10:13:55 GMT
10:13:55.244576 < Content-Type: text/html;charset=ISO-8859-1
10:13:55.244606 < Cache-Control: must-revalidate,no-cache,no-store
10:13:55.244637 < Content-Length: 1365
10:13:55.244668 < Connection: close
10:13:55.244699 < Server: Jetty(8.1.16.2)
10:13:55.244730 <
10:13:55.244760 { [1225 bytes data]
10:13:55.244901 * Closing connection 0
10:13:55.245043 * TLSv1.2 (OUT), TLS alert, Client hello (1):
10:13:55.245079 } [2 bytes data]
Total: 5.915162

enter code here

enter code here

如果我调用 http 版本,它仍然需要很长时间:

/ # curl -o /dev/null -s -w 'Total: %{time_total}\n' 'http://feed.theplatform.com/' -v --trace-time
10:12:29.865144 *   Trying 199.27.170.188...
10:12:29.865215 * TCP_NODELAY set
10:12:29.961021 * Connected to feed.theplatform.com (199.27.170.188) port 80 (#0)
10:12:29.961119 > GET / HTTP/1.1
10:12:29.961119 > Host: feed.theplatform.com
10:12:29.961119 > User-Agent: curl/7.60.0
10:12:29.961119 > Accept: */*
10:12:29.961119 >
10:12:30.057339 < HTTP/1.1 403 Forbidden
10:12:30.057395 < Date: Fri, 13 Jul 2018 10:12:30 GMT
10:12:30.057425 < Content-Type: text/html;charset=ISO-8859-1
10:12:30.057453 < Cache-Control: must-revalidate,no-cache,no-store
10:12:30.057482 < Content-Length: 1365
10:12:30.057505 < Connection: close
10:12:30.057527 < Server: Jetty(8.1.16.2)
10:12:30.057554 <
10:12:30.057578 { [1365 bytes data]
10:12:30.057666 * Closing connection 0
Total: 5.705922

如果我使用 node:8.11.3-alpine,我会遇到同样的问题

如时间所示,是通话开始时出现问题。 我该如何解决这个问题?

最佳答案

这是我的名称服务器的问题。 通过添加 %{time_namelookup} 并运行

curl -o /dev/null -s -w 'Total: %{time_total}\nTime Namelookup: %{time_namelookup}\n' 'http://feed.theplatform.com/' -v --trace-time

我得到时间名称查找:5.514205

我尝试将名称服务器更改为 googles,然后我在 0.5 秒内得到了结果。

关于node.js - 在 alpine 中运行 curl 需要很长时间才能开始,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51321315/

相关文章:

node.js - js中的console.log()和console.error()有什么区别?

linux - Loop on Unix,几何图形的基本计算器

tar - 使用 docker Alpine 时出现 "tar: not found in archive"错误

linux - 脚本从上次运行中获取参数

linux - 无法在 docker Alpine 中添加具有高 UID 的用户

javascript - 如何从 Firebase 函数将触发器放置到另一个 Firebase 数据库?

javascript - 在不同文件中导出不同路由的实际函数

node.js - Node 中同步 I/O 是如何实现的?

c - 重定向execl函数的结果

c++ - const char* 与字符串文字的使用