socket.bufferSize
writable.writableLength
。此属性显示为写入而缓冲的字符数。 缓冲器中可能包含字符串,其编码后的长度是未知的。 因此,此数字仅是缓冲器中字节数的近似值。
net.Socket
具有该属性时,则 socket.write()
始终可用。
这是为了帮助用户快速启动并运行。
计算机不能总是跟上写入套接字的数据量。
网络连接也可能太慢。
Node.js 将会在内部将写入套接字的数据进行排队,并在可能的情况下将其发送出去。
这种内部缓冲的结果是内存可能会增加。
对于遇到 bufferSize
太大或不断增加的用户,应尝试使用 socket.pause()
和 socket.resume()
来对其程序中的数据流进行节流。
writable.writableLength
instead.This property shows the number of characters buffered for writing. The buffer may contain strings whose length after encoding is not yet known. So this number is only an approximation of the number of bytes in the buffer.
net.Socket
has the property that socket.write()
always works. This is to
help users get up and running quickly. The computer cannot always keep up
with the amount of data that is written to a socket. The network connection
simply might be too slow. Node.js will internally queue up the data written to a
socket and send it out over the wire when it is possible.
The consequence of this internal buffering is that memory may grow.
Users who experience large or growing bufferSize
should attempt to
"throttle" the data flows in their program with
socket.pause()
and socket.resume()
.