I want to read the file which is of size 200 MB and it takes 60 seconds to read with other technologies(i used java's Spring boot). so as node says it is asynchronous it will use callback when your file is done reading so what is the next step it will do, will it directly displaying the success message before reading file or what else it will do.
-
Node isn't faster at reading/writing than other files. It is just easier for you to write code that utilises multiple I/O operations concurrently in Node. You're not going to get extremely fast file reading just by using Node (at least, it's not likely); that's going to be gated to your HDD speed regardless of language. – Dan Apr 28 '16 at 05:44
-
1In theory, multi-threaded programs use locks, semaphores and other tools to synchronize code execution and concurrent data access. One CPU core can only run one thread of execution at a time, and the way it is implemented is context switching. If you use many threads, then the cost of context switching can be high, and reduce overall I/O performance. For I/O bound tasks, using async I/O is faster. But there are other async libs out there, not just node.js – nagylzs Apr 28 '16 at 05:47
2 Answers
I want to read the file which is of size 200 MB and it takes 60 seconds to read with other technologies(i used java's Spring boot)
There is no way that Java needs 60 seconds to read a 200 MB file. It's not the language or the implementation of the language which is slow--it's your code.
Node is not a particularly fast platform for file I/O. Some people even find it difficult to program for. But it looks like you happened to write some fast Node code, and some slow Java code.

- 239,568
- 38
- 324
- 436
Very interesting question - while all the responses are great, I want to touch on this part of the question: 'will it directly displaying the success message before reading file or what else it will do.'
The whole idea in this case is to do other works if any, while the file reading infrastructure is being setup.
If that includes displaying a success message, yes - it will do that as well, but that is not appropriate, as it is wrong to say that the operation is over. Ideally, one would write code which is unrelated and which can run chronologically independant with the status of file operation. Node will run that code, while it waits for the I/O. And this is where it gains 'apparent' performance gain - that is, my multiplexing tasks within one thread.
If the whole activity in the app is to read a huge file, the performance difference between Node and Java will not be visible, as it will escape from the language implementation specifics and enter into the low level system and device operations where everything runs in the same manner without regarding the caller's identity.
If the activity in the app is a huge set of computations, then Node will start performance very poor compared to Java etc. This is because, the dynamic typing of the JS language will start affecting the performance through additional activities required in the code.
If the activity in the app is a natural mix of computations and I/O, then Node will outperform others, as the multiplex effect mentioned earlier will start visible.
A further detailed explanation of this Node behavior with activities under the hood is explained here
Hope this helps.

- 1
- 1

- 1,344
- 8
- 18