How fast can the method write() of writable stream in node.js be called?

On my server side I use writable stream to record the changing data of all the clients that are connected to the server. Here is what I wrote:

function updateLoop () {
    var data = {'timeStep': timeStep, 'playerInfo': playerInfo};
    var text = JSON.stringify(data);
    writeStram.write(text + '\n');
    timeStep += 1;
}
...
updateTimer = setInterval(updateLoop, 50);

So the function updateLoop() is called every 50ms.

It works when 'playerInfo' is small (less than 1KB), for example, after the server side running for 20s, there are 20*1000/50 = 400 lines of data in the output file

But when 'playerInfo' became larger, like 6KB or more, after the server side running for 20s, there only 220 lines of data in the output file. The larger playerInfo is, the lesser lines of successfully recorded data in the output file there is.

I am wondering if there is some limit to the calling rate of the method write()

Thanks a lot for your guys' help!

The issue likely isn't specifically with write, but with setInterval and how timers work in JavaScript.

With the larger data, updateLoop is probably taking longer to finish executing than the set delay of 50 ms. If it take long enough that the intervals overlap each other, where one would be added to the event queue when another is already waiting, the newer interval is skipped (or "dropped").

How fast can the method write() of writable stream in node.js be called?

write shouldn't explicitly throttle performance, but it can be limited by the overall performance Node can achieve on your computer (affected by CPU, RAM, etc.).

You'll have to benchmark and compare the performance of updateLoop with varying amounts of playerInfo. There are a few packages you can use for this, including ben:

ben(1000, updateLoop, function (ms) {
    console.log(ms, 'milliseconds per iteration');
});