Incredibly slow outbound HTTPS requests - node.js

I am using Node 0.12.2 with Express 4.13.3 as the frontend for a RESTful layer. Calling the API's from cURL/Postman takes ~9ms. However, using Request 2.60.0 to make the call from Node, it takes ~60ms. These are HTTPS calls. Removing HTTPS and using just HTTP brings Node down to ~7ms. Both the curl/Postman calls and the Node.js calls are happening on the same machine in the same environment under no load. I cannot seem to find what's causing Node to be so much slower than everything else. Any help would be greatly appreciated.

Updating to Request 2.61.0 fixed the issue. Looks like there was an issue with their agent pool.

Related

expressjs server hangs at random

I am running an express application which uses imagemagick to take a screenshot of a webpage and upload the result to S3 and insert a row into our database.
The service works well however after a few requests eventually the server just hangs upon request. There is no response, but the server is technically not 'down'.
Is there any way for me to see logs, or anything that can be causing this such as memory leak?
You should profile your application to check when the bottleneck happens and where it happens in your code. A good starting point is with node's integrated V8 stack profiling module.

Requests to api on Heroku-hosted NodeJS app not making it to app

I'm hosting a NodeJS+Express+Mongoose app on Heroku and have been struggling to understand why some of my GET requests are serving stale data, after repeated changes to resources using the api. The changes only get reflected through the GET call after about half an hour or if I restart the server.
The stale resource data gets returned for requests from multiple clients, my Angular JS webapp as well as curl. So, I'm guessing it isn't something to do with caching on the client.
Based on the logging it looks like the requests aren't even making it to the Express app routes, so I'm guessing there's some kind of caching that's happening on the server. I don't see this behaviour on my local system, so is it something that can be disabled on Heroku?
Generally, if you are using Express then your request passes through multiple Express Middleware before actually reaching your app routes. You have to see if there is some error in any of those middleware or there is some validation error for the data which you feed in.
I would suggest you to exhaustively test the data which failed on the heroku app on your local app too.

Does socket.io and node.js's performance get affected on heroku's server (with no websocket)?

Since heroku server doesn't support websocket, does it mean if we run a node.js + io.socket app on it, expecting many concurrent users, some in effectiveness will happen when there are more users?
I was building a multiuser app and suddenly notice that heroku is using long poll instead of websockets. I couldn't see much delay in my prototype but I am worried, should i be building my app on a server that supports real websockets?
... should i be building my app on a server that supports real websockets?
Probably.
http://websocket.org/quantum.html, says "HTML5 Web Sockets can provide a 500:1 or—depending on the size of the HTTP headers—even a 1000:1 reduction in unnecessary HTTP header traffic and 3:1 reduction in latency."
Long polling is old and inefficient, and is slowly being replaced by sockets. They are supported by every server. Most of latest browsers have already added support too. Heroku will do that too, soon hopefully. You can continue with your prototype, maybe websocket support will be added before you finish it.
The advantages websocket are given here

how to log OUTGOING https requests from node within webstorm

I'm hacking together some node.js code that calls an external webservice and I'm getting bad results. I'd like to log the raw request and response so that I can inspect it.
Here's the thing: I'm not consuming the http library directly, I'm consuming it through an OAuth library.
I'm already adding debug statements in the oauth library code and I don't like it. Now it looks like I'm going to have to go into http library and start messing with that? This can't be correct.
If I was on windows, I'd fire up fiddler. A friend mentioned wireshark but wireshark tells me I have to install X11. Really? I'm not going down that rabbit hole.
Then I tried node-inspector, but I think that is for server code not client code. It says your suppose to start your node process before attaching. Well my node process is a test case (vows) that ends shortly after is starts... so no luck there.
I guess this would difficult with any stack but jeez, it makes me miss .net!
So, how can I inspect what's going over the wire when using node.js as client to external webservice on mountain lion?
thanks!
Dan
Managed to install a hook on http/https request for the same reason.
function requestLogger(httpModule){
var original = httpModule.request
httpModule.request = function(options, callback){
console.log(options.href||options.proto+"://"+options.host+options.path, options.method)
return original(options, callback)
}
}
requestLogger(require('http'))
requestLogger(require('https'))
You can check out the global-request-logger module, which uses the same technique that #uiron mentioned, but with more details.

Accessing inbound HTTP headers in meteor?

I'm working on an application that relies on data that the browser sends within the HTTP headers (and there's no way around this). This also happens to be my first time working with something node.js based, so it's very likely I'm completely missing something simple!
Basically what I want to be able to do is call a method on the server from the client, and in that method read the HTTP headers that the client sent.
Meteor doesn't yet provide a supported API for serving HTTP from your app. This is intentional: in the not-too-distant future, your app server is likely to not be just a single process directly serving end users, but an arbitrarily parallelizable service behind a proxy tier. So we'll need to provide a supported API for responded to HTTP requests (REST, eg) that continues to work in such a setting.
Are you sure it needs to be HTTP and that you can't just use a Meteor method?
If you really need to accept direct HTTP requests now, take a peek at how packages/accounts-oauth-helper/oauth_server.js uses __meteor_bootstrap__.app to hook into the Connect middleware framework. This will work for now, but we don't promise that Meteor will always be powered by Connect :)

Resources