Multiple timeouts (lots of...)

51 views
Skip to first unread message

Alain Mouette

unread,
Sep 18, 2016, 4:47:14 AM9/18/16
to nod...@googlegroups.com
Hi,

I have a problem to control a few thousand websocket connections, for that I need a timer for each one...

first option) on every event I create a setTimeout() and delete the last one, once every 60s, 5000 timers, once every 12ms average.
My QUESTION IS: will I have a big overhead for having all these timers? and will I gar a lot of GC

second option) create a single setInterval() for each connection that will wake me up every 30s and I just check if everyting is ok.
My QUESTION IS: will I have a big overhead for having all these timers? I surely will get less garbage, right?

Any different suggestion?

Please help,

Alain, from Brazil


  

Sven Sauleau

unread,
Sep 18, 2016, 2:30:06 PM9/18/16
to nodejs

Hi,


Seems possible and fine. Have you already run your programme at your scale ? Did you profile it ? Are you using multiple nodejs processes ?


This might guide you : https://www.jayway.com/2015/04/13/600k-concurrent-websocket-connections-on-aws-using-node-js/.


Regards,

Sven

Zlatko

unread,
Sep 19, 2016, 6:49:31 AM9/19/16
to nodejs
5000 timers per se should not be a problem to measure nor a problem to the app. It's not even a strain to the connections: it amounts to approximately 83 pings per sec, which is not too much.

But the bigger question is why do you want this? Just to keep sockets alive? You can set this option in your websocket implementation of choice (well, the most used ones, at least). Tell ws to do it's own keepalive and you don't have to do bookkeeping.

If it's to relay changes in some sort of state to all the clients, then again - why not simply sending updates as they happen? That's kind of the advantage of websockets - if you wanted timers, you could simply schedule regular REST requests on the client and not mess with all of this.

Alain Mouette

unread,
Sep 19, 2016, 8:19:46 PM9/19/16
to nod...@googlegroups.com
Hi Zlatko, thanks for the detailed answer :)

My client is IoT and this brings some limitations...
First I am limited by what libs I can find on the hardware side, then
the IoT can be switched off without proper signaling. And I need to
control that and react on connection loss.

I couldn't find any option for keepalive on either side of the
comunication, I am using:
IoT side: https://github.com/Links2004/arduinoWebSockets
Node.js: https://github.com/websockets/ws

We have just moved to WebSockets, I am implementing from scratch and I
am gathering information because I don't want to go through a bad path

If you or anyone, has any idea, I would be glad to hear :)
Thanks (again),

Alain Mouette
=== Projetos especiais: <http://lnkd.in/dEu8cNq> ===

Rick Waldron

unread,
Sep 19, 2016, 9:20:39 PM9/19/16
to nod...@googlegroups.com
You should hop in https://gitter.im/rwaldron/johnny-five and introduce yourself—there's lots of people willing to help with node.js and iot projects
--
Job board: http://jobs.nodejs.org/
New group rules: https://gist.github.com/othiym23/9886289#file-moderation-policy-md
Old group rules: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
---
You received this message because you are subscribed to the Google Groups "nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nodejs+un...@googlegroups.com.
To post to this group, send email to nod...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/nodejs/57E001D8.9060902%40bonseletrons.com.br.
For more options, visit https://groups.google.com/d/optout.

Marek Jaskot

unread,
Sep 22, 2016, 2:09:43 PM9/22/16
to nodejs
Hi  Alain,


W dniu wtorek, 20 września 2016 02:19:46 UTC+2 użytkownik Alain Mouette napisał:
Hi Zlatko, thanks for the detailed answer :)

My client is IoT and this brings some limitations...
First I am limited by what libs I can find on the hardware side, then
the IoT can be switched off without proper signaling. And I need to
control that and react on connection loss.

I couldn't find any option for keepalive on either side of the
comunication, I am using:
IoT side: https://github.com/Links2004/arduinoWebSockets
Node.js
: https://github.com/websockets/ws

About websockets/ws maybe that talk will help you:) https://github.com/websockets/ws/issues/459
The ws module don't have keepalive for now, but the module use socket module from node.js :) and you can implement your keepalavie method by yourself : https://nodejs.org/api/net.html#net_socket_setkeepalive_enable_initialdelay
Reply all
Reply to author
Forward
0 new messages