3

I am designing a Node JS program to develop a real time system which has 10,000 sockets on data input side and some on the client app side ( dynamic as client app/web apps might not be running).

I transform input data to a readable output form. E.g an analog temperature sensor reading converted to Celsius scale.

I will be hosting this on google cloud Platform.

My question is whether the Node JS server will be able to handle the following tasks in parallel 1) registering web sockets 2) fixing/repairing web sockets 2.1) updating data in memory 2.2) accepting incoming daya 3) transforming data 3.1) sending tranformed data 4) dumping data to a database every 5 minutes

My question is whether Node JS is appropriate technology or do I need multi threaded technology like java

Learner_101
  • 131
  • 4
  • Yes, node can handle all this in general. If you make sure your app is stateless, then you can just spin up multiple instances of the app if one instance is not enough. But without knowing more specifics, I can give you more specifics. – Andrew Eisenberg Apr 14 '19 at 05:29
  • As for “in parallel”, no, it technically won’t since it will only run one thing at a time. So depends on a lot of other things if it will work (how often data is sent, connections coming, how the transformation works, what machine it’s run on etc etc) that you’ll have to test. – Sami Kuhmonen Apr 14 '19 at 06:15

1 Answers1

0

My question is whether Node JS is appropriate technology

To be short, yes, Node will work.

Node.js, like most modern javascript frameworks, supports asynchronous programming. What does it mean for a program to be "asynchronous"? Well, to understand what it means to be asynchronous, it's best to understand what it means to be "synchronous". Taken from Eloquent Javascript, a book by Marijn Haverbeke, available here:

In a synchronous programming model, things happen one at a time. When you call a function that performs a long-running action, it returns only when the action has finished and it can return the result. This stops your program for the time the action takes.

In other words, operations happen one at a time. If I used a synchronous program to run a ticket counter at a county faire, customer 1 would be served first, then customer 2, then customer 3, etc, etc,. Each person in front of the line would add wait time to all other persons.

An asynchronous model allows multiple things to happen at the same time. When you start an action, your program continues to run. When the action finishes, the program is informed and gets access to the result.

Going back to the ticket counter example, if done asynchronously, all persons in line would be served at the same time and it would be of little significance on any given person if there are other persons in line.

Hopefully that makes sense. With that idea fresh, let's consider how to implement a asynchronous program. As mentioned earlier, Node does support asynchronous programs, however, framework support isn't enough, you will need to deliberately build your program asynchronously.

I can provide some in depth examples of how this can be accomplished in Node, but I'm not sure what requirements/restraints you have. Feel free to add more details in a comment to this response and I can assist you more. If you need something to get started, take some time reviewing promises and callback functions

  • But how does being async relate to the question? And I would disagree with the implications of async mentioned here. It won’t magically run things at the same time at all, especially in JavaScript. – Sami Kuhmonen Apr 14 '19 at 06:17
  • @SamiKuhmonen, I see your point. You've made the correct distinction that operations running asynchronously are not necessarily running in parallel. Asynchronous programming would not allow for all 10,000 sockets to magically be served at once, they would be need to be queued in some way. If a CPU can handle one operation per second and you have 100 operations, even an asynchronous program couldn't get them all done in one second; it's simply not possible. – Zachary David Saunders Apr 14 '19 at 06:29
  • Would it just be easier in Java to have a thread pool which handles these 6 tasks in 6 different threads? Wouldn’t the program structure be easier? – Learner_101 Apr 14 '19 at 14:33