Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

net: add writeQueueSize #44157

Closed

Conversation

theanarkh
Copy link
Contributor

add writeQueueSize for net.js.

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

@nodejs-github-bot
Copy link
Collaborator

Review requested:

  • @nodejs/net

@nodejs-github-bot nodejs-github-bot added needs-ci PRs that need a full CI run. net Issues and PRs related to the net subsystem. labels Aug 6, 2022
Copy link
Contributor

@ShogunPanda ShogunPanda left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@theanarkh theanarkh force-pushed the add_write_queue_size_for_net branch from 7c1308d to 4277c46 Compare August 7, 2022 02:28
@theanarkh theanarkh force-pushed the add_write_queue_size_for_net branch from 4277c46 to 04b23b0 Compare August 7, 2022 06:52
Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@theanarkh theanarkh added the request-ci Add this label to start a Jenkins CI on a PR. label Aug 7, 2022
@github-actions github-actions bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Aug 7, 2022
@nodejs-github-bot

This comment was marked as outdated.

@theanarkh theanarkh force-pushed the add_write_queue_size_for_net branch 2 times, most recently from 04cead9 to 342d0f6 Compare August 7, 2022 14:43
@theanarkh theanarkh added the request-ci Add this label to start a Jenkins CI on a PR. label Aug 7, 2022
@github-actions github-actions bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Aug 7, 2022
@nodejs-github-bot

This comment was marked as outdated.

@theanarkh theanarkh force-pushed the add_write_queue_size_for_net branch from 342d0f6 to 277a76f Compare August 7, 2022 19:43
@theanarkh theanarkh added the request-ci Add this label to start a Jenkins CI on a PR. label Aug 8, 2022
@github-actions github-actions bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Aug 8, 2022
@nodejs-github-bot

This comment was marked as outdated.

@nodejs-github-bot

This comment was marked as outdated.

@nodejs-github-bot
Copy link
Collaborator

// because the socket is connecting currently in libuv, so libuv will
// insert the write request into write queue, then we can get the
// size of write queue by `socket.writeQueueSize`.
socket.connecting = false;
Copy link
Member

@lpinca lpinca Aug 8, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a way to test the feature without this hack? I mean, how would socket.writeQueueSize be used in the real world? The test should simulate that.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it is difficult to write the test, and i think this test is not good.writeQueueSize means how many bytes are waiting to write in libuv. and add socket._handle.writeQueueSize to the count of bytesWritten maybe a good idea. I'll take a look later, thanks !

@lpinca
Copy link
Member

lpinca commented Aug 8, 2022

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

@theanarkh theanarkh added the blocked PRs that are blocked by other issues or PRs. label Aug 8, 2022
@theanarkh
Copy link
Contributor Author

@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.

@lpinca
Copy link
Member

lpinca commented Aug 23, 2022

@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.

@theanarkh
Copy link
Contributor Author

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

@lpinca
Copy link
Member

lpinca commented Aug 23, 2022

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.

@aduh95 aduh95 added the stalled Issues and PRs that are stalled. label May 11, 2024
Copy link
Contributor

This issue/PR was marked as stalled, it will be automatically closed in 30 days. If it should remain open, please leave a comment explaining why it should remain open.

@theanarkh theanarkh closed this May 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
blocked PRs that are blocked by other issues or PRs. needs-ci PRs that need a full CI run. net Issues and PRs related to the net subsystem. stalled Issues and PRs that are stalled.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants