Everywhere, it mentions as Node.js has No Buffering feature. For instance from Tutorials Point:
No Buffering − Node.js applications never buffer any data. These applications simply output the data in chunks.
But what does it signifies? Node.js has a Buffer class and as per Buffer class definition
Pure JavaScript does not handle straight binary data very well, though JavaScript is Unicode friendly. When dealing with TCP streams and reading and writing to the filesystem, it is necessary to deal with purely binary streams of data.
Which holds true.
So, what is the feature of "No Buffering
" in Node.js?
And how does Node.js holds to No Buffering? Can anyone explain with an example?
What Are Buffers? The Buffer class in Node. js is designed to handle raw binary data. Each buffer corresponds to some raw memory allocated outside V8. Buffers act somewhat like arrays of integers, but aren't resizable and have a whole bunch of methods specifically for binary data.
Buffers in Streams In Node Js, buffers are used to store raw binary data. A buffer represents a chunk of memory that is allocated on our computer. The size of the buffer, once set, cannot be changed. A buffer is used to store bytes.
The Buffer. alloc() method creates a new buffer object of the specified size.
Buffering is the practice of pre-loading segments of data when streaming video content. Streaming — the continuous transmission of audio or video files from a server to a client — is the process that makes watching videos online possible.
Typical streaming is done by creating a callback which receives data over a period of time, does something with that data, or handles it off to another stream.
This means that the consumer of the data can get it more readily without having to wait for the entire operation to complete.
This is what TutorialPoint was eluding to, although poorly said — and for the most part, incorrect.
Bufferring is actually key to working with streamable data. In the sense that the actual data will reside in a Buffer until your Callback pulls the data out of the stream to work with.
This is why Node.JS has Buffer classes and libraries such as stream-buffers, to facilitate stream data access.
This is when you have a data stream with a Producer and a Consumer, but due to load issues, your Consumers are falling behind in consuming the data at a fast enough pace compared to the rate of the Producers pumping data into the stream.
This causes the so called "back pressure" effect, and can bring down a system if the Producers are not rate limited.
Back pressure is relevant to the discussion because it is caused by the buffer being filled faster than your callback can push out data back to the user or another stream.
Therefore, bufferring — at some level or another— is essential to the operation of Node.js and is how it handles continuous streams of data. That is why Buffer class exists, as well as Streaming buffers — to facilitate the movement of data between callbacks.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With