Which reads files 10 times slower — Java or Node.js? Both

Node.js clearly excels at I/O operations but does not use the disk cache. Java gets fast when the files are the disk cache

Marian C.
5 min readJan 27, 2022

Node.js is believed to be efficient at disk or network operations because, unlike Java, in Node.js all I/O operations are non-blocking unless you intentionally choose a synchronous method. In Java disk or network operations are always blocking execution of the only or additional threads. If you want to make concurrent HTTP requests you will save time if you do not use Java.

In this post I compare how fast Node.js and Java read files. The efficiency of reading files might be important for some applications. If Node.js or Java is used to run a web server, they will have to read disk to serve static contents. Since the servers keep reading the same files, caching files improves the performance of the server. Another task that I routinely face is indexing many files. For such a task a file cache is not useful.

For my experiments I use a virtual machine with CentOS 8 on the Google cloud — a nice place for playing with processors. I first make measurements on a machine with 2 CPUs and 8 GB. Then I confirm the results on on the same machine but after increasing the number of processors to 16.

--

--

Marian C.
Marian C.

Written by Marian C.

Java, JavaScript and SQL developer. Interested in data collection and visualization.

Responses (3)