Answer the question
In order to leave comments, you need to log in
Node.js async vs Java, what's the catch?
Good afternoon, help me understand, I read:
What is the advantage of Node?(if you need a source - google it, it doesn't allow you to insert links)
Node is easier to scale. With thousands of users connected to the server at the same time, Node works asynchronously, that is, it prioritizes and allocates resources more intelligently. Java, for example, allocates a separate thread for each connection.
Answer the question
In order to leave comments, you need to log in
Well, firstly, Java has a lot of different greenlet and other technologies, where explicit asynchrony is not needed (it is inconvenient)
Secondly, separate workers in Apache are needed only for those backends that need it.
If you want to maximize the number of requests that can be executed in parallel by the backend, then obviously you need to look for another way, without Apache workers. For example, https://habrahabr.ru/company/itsumma/blog/337346/
Thirdly, for a better understanding, mentally isolate the task and generally exclude Apache here. We consider the possibilities of only the Node itself and the JVM itself.
Fourthly, holivar is absolutely meaningless, since a specific application will be implemented taking into account the capabilities of a specific execution environment. We are talking about quality implementation, of course. And the programmer will take into account the features of Noda or JVM. If he is qualified.
Fifth, no magic tool will help an unskilled programmer.
Sixth, ceteris paribus (with equally good knowledge of the programmer in both systems) - the JVM will always be faster. For she is not far behind S-something.
Seventh, but it is impossible not to pay attention to the fact that using the Node you can get by with the knowledge of one language. Actually, the rise of Noda is due to this. That there are a lot of front-end developers who want to write the back-end. And we have already written a bunch of auxiliary tools / libraries for it, etc. There is nothing more magical in Nod.
Sheer stupidity! At the moment: and for good, for at least 10 years, there are a bunch of asynchronous frameworks and network libraries that work exactly on the same principle as nodejs.
Examples, we have them:
- frameworks jooby.org, sparkjava, springboot
- libraries (servers) netty, undertow, akka
Performance is not inferior to nodejs.
Well, how does it all work? There are two types of programming that can be combined:
Old and widely used
- the server is waiting for a network connection
- as soon as the connection is made, the server starts a process / thread and passes an open connection to it.
In this case, we are limited by the number of threads / processes in the system, we have a large overhead for creating a process / thread. But we do not need to care much about working with sockets.
New hype/modern
- at startup, data handlers (our services/applications) are registered in the server
- the server opens a socket and listens to all the sockets it has previously opened, hangs waiting for the data arrival / transmission event on the select / poll / epoll method or similar.
- as soon as the server has received a response, it calls the registered handler and transfers a portion of the received data there, receives this data back and sends it to the network to the desired connection
In this case, the server works in one thread, simply calling the handlers sequentially and giving them data. Fast, very fast, nimble, no overhead. But if a handler tries to perform a blocking operation, all other handlers hang, so the handlers communicate with the server by messages and try not to take up a lot of processor resources. Programming is complex.
You can also combine these two approaches by doing both a thread pool and working in asynchronous mode.
To read here for example - https://en.wikipedia.org/wiki/Epoll
Then the question is, how miraculously does Node avoid this? If possible , please explain how everything happens there
HOST: toster.ru
GET: /q/500685
nodeJs does not require a separate web server as it has its own built-in one.
Firstly, it does not process requests from Node with Java, but from the server.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question