0

Js is single-threaded so I have vehicles connected with socket io So these vehicles will send location every second or less and update MySQL with it and some things too, Which better approach to do these heavy load things? Like Node.Js should be single-threaded and I have many things in the same Node.Js process So I think it could be bad? is Python better? Like maybe having 2 servers 1 node 2 python I have no idea what to do and which is better? if anything I didn't mention is better than these please mention it like java or smth any ideas?

BKSO
  • 23
  • 1
  • 5

1 Answers1

1

First of all , you have to know you are the developer and you have to choose what makes your needs .

Anyway lets say my oponion about this.

If you want to create high load realtime server you have to learn about multi threading and none blocking sockets.

Why multi threading ? To handle jobs in their own thread. Ok it seems easy but not ! You have to know how to share threads and manage them. Creating many threads make mistake and overload on server so you need to manage them correctly. For example if you have many databse update its better to put this jobs in a queue and execute one after another but not create a new thread for each one. Ofcourse many of this things handled and implemented at low level layer of libraries.

Why none blocking socket ? To make server communication async. It can be related to the first section (multi threading). If you use blocking-socket you will need to open a new thread per socket for reading message (and maybe you will lock other threads for send packets ...) so if you have 1000 concurrent client you need 1000 threads! It is so bad. In other hand we have none blocking socket that you can handle many connections in just one thread(Related Question).

Which programming language ? In realtime servers performance is a big mistake. Interpreted languages can make performance issues and I prefer to use a compiled programming language liked Java , C , Go and ... . For better exprience in multithreading you can use GO and Erlang that have their own light threads and handle async operations like a sync operations. We can say these langs are care about how threads create , share and ... .

Remember this in your mind that there is many tools are exists to handle this type of jobs . Even if you want to develop it by your hand , It's not a bad idea to work with one of these tools to help you about your concept.

If you work with java :

Netty(transport lib) ,

Hazelcast(cluster(failure tolerance - horizontal scale and ...)) ,

Kafka(message broker) ,

Cassendra(db) ,

and ...

Last word : just do it.

Alireza Akhoundi
  • 214
  • 3
  • 12