How to check the number of open connections in node.js

2,501 views
Skip to first unread message

Sharief Shaik

unread,
Jul 9, 2010, 11:59:34 AM7/9/10
to nodejs
Hello there!

I have a machine running node.js with a tcp server (tcp.createServer)
and a http server (http.createServer). The http server is hit by long
polling requests (lasting 50 sec each) from a comet based application
on port 80. And there are tcp socket connections on port 8080 from an
iphone application for the same purpose.

It was found that the server was not able to handle more connections
(especially the tcp connections while the http connections appeared
fine!!??) for a while and was normal only after a restart.

For load testing the connections I took the reference of Petes
examples in the other post here to see how may connections my server
can handle [
http://groups.google.com/group/nodejs/browse_thread/thread/bb464045d05c67d0/d7c1f5dbea3c9759?hl=en&lnk=gst&q=tcp+createServer#d7c1f5dbea3c9759
]

...and figured that the connections starting to fail after the max
file descriptor limit on machine is reached (default 1024). Which is a
really very small number.

So, a novice question here: How do I scale my application to handle
more number of connections on node.js and how I handle this issue.

Is there a way to find out how many active connections are there at
the moment?

Thanks
Sharief

Александр Лозовюк

unread,
Jul 9, 2010, 12:29:22 PM7/9/10
to nod...@googlegroups.com
Use ulimit command (http://ss64.com/bash/ulimit.html)

You need the ulimit -n params (number of open file description). set
it to max (e.g. 65536) before start your server

2010/7/9 Sharief Shaik <shar...@gmail.com>:

> --
> You received this message because you are subscribed to the Google Groups "nodejs" group.
> To post to this group, send email to nod...@googlegroups.com.
> To unsubscribe from this group, send email to nodejs+un...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/nodejs?hl=en.
>
>

--
C уважением, Александр Лозовюк
Alpha-Beta-Release Blog
http://abrdev.com

Peter Griess

unread,
Jul 9, 2010, 12:45:28 PM7/9/10
to nod...@googlegroups.com
On Linux, you can use the lsof(8) command to see which files a process has open.

As Александр mentioned earlier, ulimit(1) command will allow you to increase the number of open files for a process. However, this command will only get you so far: it itself has a ceiling. You can bump the ceiling that ulimit allows you on Linux by mucking with /etc/security/limits.conf. See limits.conf(5) for more details. I don't recall if you need to reboot after making this change.

Peter

Sharief Shaik

unread,
Jul 9, 2010, 12:52:49 PM7/9/10
to nodejs
I was able to increase the ulimit file descriptor value to 10k to do
the load testing and the connections appeared to rise accordingly.
Then what should be the ideal value to go with? Does that matter or
just as per my need? Also some way that I could find the current
number of active connections would be great.

And again I forgot to mention the version of node.js I'm using. Its
v0.1.32.

Sharief

On Jul 9, 9:29 pm, Александр Лозовюк <aleks.rai...@gmail.com> wrote:
> Use ulimit command (http://ss64.com/bash/ulimit.html)
>
> You need the ulimit -n params (number of open file description). set
> it to max (e.g. 65536)  before start your server
>
> 2010/7/9 Sharief Shaik <sharie...@gmail.com>:
>
>
>
> > Hello there!
>
> > I have a machine running node.js with a tcp server (tcp.createServer)
> > and a http server (http.createServer). The http server is hit by long
> > polling requests (lasting 50 sec each) from a comet based application
> > on port 80. And there are tcp socket connections on port 8080 from an
> > iphone application for the same purpose.
>
> > It was found that the server was not able to handle more connections
> > (especially the tcp connections while the http connections appeared
> > fine!!??) for a while and was normal only after a restart.
>
> > For load testing the connections I took the reference of Petes
> > examples in the other post here to see how may connections my server
> > can handle [
> >http://groups.google.com/group/nodejs/browse_thread/thread/bb464045d0...
> > ]
>
> > ...and figured that the connections starting to fail after the max
> > file descriptor limit on machine is reached (default 1024). Which is a
> > really very small number.
>
> > So, a novice question here: How do I scale my application to handle
> > more number of connections on node.js and how I handle this issue.
>
> > Is there a way to find out how many active connections are there at
> > the moment?
>
> > Thanks
> > Sharief
>
> > --
> > You received this message because you are subscribed to the Google Groups "nodejs" group.
> > To post to this group, send email to nod...@googlegroups.com.
> > To unsubscribe from this group, send email to nodejs+un...@googlegroups.com.
> > For more options, visit this group athttp://groups.google.com/group/nodejs?hl=en.

Александр Лозовюк

unread,
Jul 9, 2010, 12:56:26 PM7/9/10
to nod...@googlegroups.com
of couse, upgrade your NodeJS to latest, the network stack rewritten
and patched to use at hi-load project

2010/7/9 Sharief Shaik <shar...@gmail.com>:

> For more options, visit this group at http://groups.google.com/group/nodejs?hl=en.

Sharief Shaik

unread,
Jul 9, 2010, 1:15:38 PM7/9/10
to nodejs
Thank you Александр!

Which version do you suggest is stable enough to go with? I have been
using the 0.1.32 version in production for a while now for my long
polling requests on http server. Earlier when in development phase of
my application, I have faced a problem with version 0.1.33 with the
TCP connectivity, which prevented the connectivity to redis server
that I was using along with the node.js modules. So, I was hesitant to
keep upgrading my node.js version later on.

On Jul 9, 9:56 pm, Александр Лозовюк <aleks.rai...@gmail.com> wrote:
> of couse, upgrade your NodeJS to latest, the network stack rewritten
> and patched to use at hi-load project
>
> 2010/7/9 Sharief Shaik <sharie...@gmail.com>:

Timothy Caswell

unread,
Jul 9, 2010, 1:19:08 PM7/9/10
to nod...@googlegroups.com
node v0.1.100 seems pretty stable to me. I haven't seen any issues in the last several versions. i think the last unstable for me on howtonode.org was v0.1.97

Александр Лозовюк

unread,
Jul 9, 2010, 1:29:50 PM7/9/10
to nod...@googlegroups.com
Yes, iam recommended latest version 0.1.100 - in the 0.1.3х net module
has been rewritten and we have some troubleshoting to rewrite own
application with next version (in my app we use latest version and
tested new from git each week)

2010/7/9 Timothy Caswell <t...@creationix.com>:

Sharief Shaik

unread,
Jul 9, 2010, 1:40:59 PM7/9/10
to nodejs
Thanks everyone! I'll try the latest version.

Regards
Sharief
> >> For more options, visit this group athttp://groups.google.com/group/nodejs?hl=en.
>
> > --
> > You received this message because you are subscribed to the Google Groups "nodejs" group.
> > To post to this group, send email to nod...@googlegroups.com.
> > To unsubscribe from this group, send email to nodejs+un...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages