Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

nodejs/curl http request is slow compared to postman rest client

I call a Rest API from node.js and Postman-Rest Client (chrome app). Always using the same computer, same endpoint and same parameters.

In node.js I get ~400ms for http and ~700ms for https. In Postman I get ~250ms for http and https.

Libraries I used in node.js: http, https, request, kinvey (node client of the api). All of them got the the same result more or less.

Why my node is slower?

node.js 0.10.36

Edit: it's not about node, i get the same result with curl. when running in browser using XMLHttpRequest i get better times. from analysing the logs I found that TCP connect and SSL handshake takes about 500ms. It may be that TCP connect and SSL handshake works differently in browser.

like image 286
taminov Avatar asked Sep 11 '26 19:09

taminov


1 Answers

Here you can find some help. I am also facing issues with nodejs application server on linux instance. But dont blame nodejs as real issue is in linux systems.

Issue : any outbound request from machine need to find the domain , hence it always lookup the DNS entries & always handshakes with secure/unsecure protocols. This is actually the time taking scenario. You can verify by doing CURL request.

curl --trace-time -v https://outboundserver.com

Solution : We have to White List IP of outbound server in our own DNS entries. take a look below ...

IN Windows : automatically does the mapping of servers in own dns entries.

IN Linux : We have to manually add the hosts corresponding to IP Address. Manually add an entry in /etc/hosts file below any configuration like localhost.

127.0.0.1 localhost outbound.servers.ip.address www.outboundserver.com

Finally check with the curl request again, it should give faster response.

curl --trace-time -v https://outboundserver.com

like image 65
Akshay Avatar answered Sep 13 '26 07:09

Akshay



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!