node icon indicating copy to clipboard operation
node copied to clipboard

net: add writeQueueSize

Open theanarkh opened this issue 1 year ago • 7 comments

add writeQueueSize for net.js.

  • [x] make -j4 test (UNIX), or vcbuild test (Windows) passes
  • [x] tests and/or benchmarks are included
  • [x] documentation is changed or added
  • [x] commit message follows commit guidelines

theanarkh avatar Aug 06 '22 20:08 theanarkh

Review requested:

  • [ ] @nodejs/net

nodejs-github-bot avatar Aug 06 '22 20:08 nodejs-github-bot

CI: https://ci.nodejs.org/job/node-test-pull-request/45898/

nodejs-github-bot avatar Aug 07 '22 11:08 nodejs-github-bot

CI: https://ci.nodejs.org/job/node-test-pull-request/45906/

nodejs-github-bot avatar Aug 07 '22 18:08 nodejs-github-bot

CI: https://ci.nodejs.org/job/node-test-pull-request/45912/

nodejs-github-bot avatar Aug 08 '22 02:08 nodejs-github-bot

CI: https://ci.nodejs.org/job/node-test-pull-request/45913/

nodejs-github-bot avatar Aug 08 '22 03:08 nodejs-github-bot

CI: https://ci.nodejs.org/job/node-test-pull-request/45914/

nodejs-github-bot avatar Aug 08 '22 05:08 nodejs-github-bot

I think it makes more sense to undeprecate socket.bufferSize and add socket._handle.writeQueueSize to the count instead of adding a new field.

lpinca avatar Aug 08 '22 16:08 lpinca

@pinca I've read the source code. I think 'bytesWritten' is equal to the length of all written bytes, which includes the data has been sent and data is waiting to be sent. And 'writeQueueSize' indicates the length of bytes waiting to be sent in Libuv.

theanarkh avatar Aug 23 '22 14:08 theanarkh

@theanarkh I was talking about socket.bufferSize and I meant something like this:

diff --git a/lib/net.js b/lib/net.js
index eaa5e594e5..ce02019a75 100644
--- a/lib/net.js
+++ b/lib/net.js
@@ -637,7 +637,7 @@ ObjectDefineProperty(Socket.prototype, 'bufferSize', {
   __proto__: null,
   get: function() {
     if (this._handle) {
-      return this.writableLength;
+      return this._handle.writeQueueSize + this.writableLength;
     }
   }
 });

instead of creating a new property.

lpinca avatar Aug 23 '22 15:08 lpinca

Oh. Thanks. bufferSize = this.bytesWritten - this._bytesDispatched + this._handle.writeQueueSize is it right ?

theanarkh avatar Aug 23 '22 15:08 theanarkh

It seems socket.bytesWritten = socket._bytesDispatched + socket.<writableBuffer byte length> + <length of data written before connect> so yes it should be correct, but I think it is unnecessarily complex.

socket.writableLength should take into account socket.<writableBuffer byte length> + <length of data written before connect>

$ node
Welcome to Node.js v18.7.0.
Type ".help" for more information.
> var socket = net.createConnection({ port: 8080, lookup() {} });
undefined
> socket.write('foo')
true
> socket.bytesWritten
3
> socket.writableLength
3
>

I would just use socket._handle.writeQueueSize + socket.writableLength.

I also think that socket.bytesWritten could be simplified by using socket.writableLength but that is a different issue.

lpinca avatar Aug 23 '22 16:08 lpinca