
Tracking down a memory leak in Node.js and Socket.IO - jpallen
http://jpallen.net/2013/03/08/tracking-down-a-memory-leak-in-node-js-and-socket-io/
======
exratione
I suspect that most folk, such as myself, have blissfully skated past such
issues in ignorance because using Node.js to field SSL traffic isn't the
standard setup. Instead you run an http.Server - with or without Socket.IO
latched to it - behind a websocket-capable, ssl-terminating proxy like
HAProxy.

[http://www.exratione.com/2012/12/websockets-over-ssl-
haproxy...](http://www.exratione.com/2012/12/websockets-over-ssl-haproxy-
nodejs-nginx/)

Because you're going to need all the proxy features like failover, clustering,
etc, etc, anyway, so why put Node.js right up front?

(Nginx recently added support for websockets, so that's now a viable
alternative to HAProxy in this role, but it was aggravating for a while that
it wasn't).

~~~
beck5
(I work on the same site/problem as author)

We would prefer node did not deal with the https, I actually did a previous
blog post showing how performance degraded
[https://www.sharelatex.com/blog/posts/nodejs_http_vs_https.h...](https://www.sharelatex.com/blog/posts/nodejs_http_vs_https.html).

Options like Ngnix and haproxy without pound/stud are quite recent and we have
not gotten around to trying them out.

In regards to clustering, running socket.io in a cluster with redis store is
another world of memory leaking pain. Hopefully socket.io 1.0 with engine.io
will solve this but its been nearly released for several months now.

I am now starting to question the value of websockets, long polling is a lot
simpler in many ways and robust.

~~~
exratione
I can recommend HAProxy based on my experiences.

If you want to go with established tech over newer stuff (and the Nginx
websocket support is definitely too new for me - give it another 6 months at
least), then you can Rube Goldberg a fun setup with Stunnel and Varnish
replacing HAProxy.

[http://www.exratione.com/2012/08/websockets-over-ssl-
stunnel...](http://www.exratione.com/2012/08/websockets-over-ssl-stunnel-
varnish-nginx-nodejs/)

I haven't had any unpleasant happenings myself with clustering Socket.IO and
Redis; that'd be a topic I'd like to see a post on from your lot, given that
I'm presently working on the cluster code for a demi-framework for clustered
single page Node/Socket apps:

<https://github.com/exratione/thywill>

------
quarterto
Great writeup. I especially like the Telnet REPL trick:

    
    
      require("net")
        .createServer (socket) ->
          repl = require('repl')
          repl.start("my-node-process>", socket)
        .listen 5000, "localhost"

~~~
jpallen
Thanks. I didn't invent the telnet REPL trick, but I've forgotten where I
found it so I can't give credit where it's due, sorry.

~~~
sebastianmck
It's in the docs. <http://nodejs.org/api/repl.html#repl_repl_start_options>

------
Sembiance
A great alternative to socket.io is sock.js <http://sockjs.org> I've been
using it in production now for a few weeks on <http://worldofcardgames.com>
with no issues.

