1

I have a system that has a central computer (server) and a group of small computers. These small computers can only communicate (by internet) with the central computer. No communication should be done between these small ones. It is like a master/slave concept with one master and several slaves but the communication is done from/to server to/from slave. Right now I decided to use a thread in the server for each small computer. If I have 10 small computers, 10 threads should be processing at the same time. Also noting that the server also have an application that can be accessed from browser. The information coming from the devices should be processed in the server and delivered to the application on the browser. Now, my doubt is, taking into account I have several small devices is it correct or mandatory to use 1 thread for each device? Or is there a tool that can manage all these connections? I'm using sockets by the way.

Thanks

1 Answers1

0

No, it is not. What is mandatory is to preserve a unique context per client, assuming a TCP socket, it gonna be an open connection between both. You could rely upon your runtime and/or environment async framework and handle literally tens of thousands of concurrent connections on a single thread.

However, the approach won't work for CPU-bound workflows; in other words, you have to make sure that IO-related losses (mostly, waiting for bytes to come in or get delivered and waiting for some external devices like a hard drive) dominate. Asynchronous way of doing things does not work for CPU-bound kinds of problems (for example, compression or hashing).

Take a look into Erlang, for example. Or Golang. Just for inspiration.

Zazaeil
  • 3,900
  • 2
  • 14
  • 31
  • 1
    Thank you for answering me. So, it is not mandatory, but it is legit, right? I just went to Erlang website and I think I will keep the threads. It would require rewrite all the code in a new language which is not feasible right now. – Pedro Carvalho Mar 15 '23 at 17:18
  • Legit? Yes. Required? No? Gonna be efficient? Probably not. Should you worry about misperformance upfront? It depends upon what load do you expect on your system. – Zazaeil Mar 15 '23 at 17:38