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

Suggestion: stream.read(buffer, offset, length, callback) #3403

Closed
jorangreef opened this issue Oct 16, 2015 · 9 comments
Closed

Suggestion: stream.read(buffer, offset, length, callback) #3403

jorangreef opened this issue Oct 16, 2015 · 9 comments
Labels
blocked PRs that are blocked by other issues or PRs. feature request Issues that request new features to be added to Node.js. stream Issues and PRs related to the stream subsystem.

Comments

@jorangreef
Copy link
Contributor

I am not sure if this is possible with the design of libuv and Node, but it would be great to be able to do:

stream.read(buffer, offset, length, callback)

buffer is the buffer that the data will be written to.

offset is the offset in the buffer to start writing at.

length is an integer specifying the number of bytes to read.

Especially for net and tls sockets.

I am not sure if Node itself currently manages and re-uses the underlying buffers for net sockets? But if not, then this would make it possible to do static memory allocation in a server. In the past, streams did not support pull mode at all, now they support pull mode, but the user still has no control over the allocation of the underlying buffers, so this creates more allocations and more work for the GC.

I am working on a client-side program at the moment and am finding that V8's GC is just too lazy. Things work and eventually get collected but memory usage climbs and climbs. I would like to have more control and rather statically allocate buffers and re-use them. This would also have a positive side-effect of controlling queue sizes and workloads in various parts of the program more explicitly.

@mscdex mscdex added stream Issues and PRs related to the stream subsystem. feature request Issues that request new features to be added to Node.js. labels Oct 16, 2015
@Fishrock123
Copy link
Contributor

cc @nodejs/streams

@chrisdickinson
Copy link
Contributor

Something like this would be cool. WHATWG currently has "getByobReader", which implements something similar. I would advise we watch how that pans out closely to see if there are any rough edges we should know about before implementing such a thing ourselves.

On Oct 20, 2015, at 6:08 AM, Jeremiah Senkpiel notifications@github.com wrote:

cc @nodejs/streams


Reply to this email directly or view it on GitHub.

@bnoordhuis
Copy link
Member

Apropos nothing:

I am not sure if this is possible with the design of libuv

Request-driven reading is not the model that libuv currently uses but it can be modeled reasonably efficiently by selectively calling uv_read_start() and uv_read_stop().

That's what libuv's socks5-proxy example does in fact and it's the most natural model for most applications. The plan is to implement it natively in libuv v2.x.

@Trott
Copy link
Member

Trott commented May 26, 2016

Anything new to add to this issue in the past 7 months?

@jhamhader
Copy link
Contributor

Looking into it.
Need to think on how this API makes sense in the case of objectMode or stringMode (encoding set) on the readable stream.

@vkurchatkin
Copy link
Contributor

#6923

@Trott
Copy link
Member

Trott commented Jul 7, 2017

This issue has been inactive for sufficiently long that it seems like perhaps it should be closed. Feel free to re-open (or leave a comment requesting that it be re-opened) if you disagree. I'm just tidying up and not acting on a super-strong opinion or anything like that.

@Trott Trott closed this as completed Jul 7, 2017
@jorangreef
Copy link
Contributor Author

This issue is blocked on libuv v2.x and nodejs/node-eps#27 which may take some time.

Can we re-open?

We definitely need a way to do more static allocation in Node specifically when working with TCP.

@TimothyGu TimothyGu reopened this Jul 21, 2017
@Trott Trott added the blocked PRs that are blocked by other issues or PRs. label Jul 21, 2017
@refack
Copy link
Contributor

refack commented Nov 11, 2018

Put into https://github.com/nodejs/node/projects/13 backlog

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. feature request Issues that request new features to be added to Node.js. stream Issues and PRs related to the stream subsystem.
Projects
None yet
Development

No branches or pull requests

10 participants