| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
|
cc @nodejs/collaborators @nodejs/streams |
Sorry, something went wrong.
| // Asynchronously read data into `buf.slice(offset, offset + length)` | ||
| // Invoke continuation with either error (`err`) or number of bytes | ||
| // read (`length`) | ||
| stream.readInto(buf, offset, length, (err, length) => { |
There was a problem hiding this comment.
It may be worthwhile going ahead and passing buf, offset and length to the callback as additional arguments. (or buf.slice(offset, offset + length)
Sorry, something went wrong.
There was a problem hiding this comment.
Agree, though passing slice will probably be in contrary to the performance reasons of this feature.
Sorry, something went wrong.
There was a problem hiding this comment.
Yeah, agreed. simply passing the additional buf and offset arguments on should be good enough.
Sorry, something went wrong.
There was a problem hiding this comment.
Ack.
Sorry, something went wrong.
|
|
||
| * [Public C++ Streams](001-public-stream-base.md) | ||
| * [ES6 Module Interoperability](002-es6-modules.md) | ||
| * [stream.Readable#readInto()](003-readable-read-into.md) |
There was a problem hiding this comment.
Could you remove this line and rename 003-* to XXX-*? Whoever merges the PR changes those, since another might land before this and all. :)
Sorry, something went wrong.
There was a problem hiding this comment.
Ack. 👍
Sorry, something went wrong.
|
Totally dig the idea. |
Sorry, something went wrong.
|
So, does it mean that I need to change "DRAFT" to "ACCEPTED"? What is required for this? |
Sorry, something went wrong.
|
@indutny Well, if it were possibly considered controversial then it would need to be voted on by the CTC. I would at least like to see more of the CTC give their thoughts before it's ACCEPTED. Meaning, if an EP reaches ACCEPTED then the PR accompanying it will definitely be accepted, and there shouldn't be much if any discussion between CTC members about the PR landing (this doesn't include other devs who feel the need to chime in). |
Sorry, something went wrong.
|
@trevnorris makes sense. Thank you! |
Sorry, something went wrong.
|
cc @nodejs/ctc then |
Sorry, something went wrong.
|
Fwiw, I'm +1 on this.
|
Sorry, something went wrong.
|
Who is expected to call ._readInto? .read(), or a new public .readInto()? Does this interact with .pipe? |
Sorry, something went wrong.
|
(Also: is it possible that we define this for a subset of streams — maybe just net.Socket?) |
Sorry, something went wrong.
readInto() call ._readInto if present, .read() calls it if ._read is not present. It does interact in quite the same way as the readable streams work right now. |
Sorry, something went wrong.
Personally, I don't have much preference, but it seems to be better to have a wider support for it. |
Sorry, something went wrong.
|
This is something I would have used plenty of times (readInto). I'm +1 on this and it would make my life easier. The proposal itself sounds reasonable to me. I'd make some stylistic changes to the code samples in the proposal but that's really not important. |
Sorry, something went wrong.
|
@indutny just have a section clarifying the relationship with pipe. |
Sorry, something went wrong.
|
This proposal still has the issue that you need at least as many buffers as you have streams, doesn't it? Ideally, it would be possible to have a single buffer and read into that on demand. E.g.: const streams = [ /* ... */ ];
const buffer = new Buffer(256);
for (const stream of streams) {
stream.on('readable', () => {
const n = stream.readInto(buffer, 0, buffer.length);
if (n < 0)
handleError(stream, n);
else
handleData(stream, buffer, n);
});
} |
Sorry, something went wrong.
| ### 2.2 Core Perspective | ||
|
|
||
| TLS, HTTP is now performed mostly within the C++ layer, raising the complexity | ||
| and making things less observable for the JavaScript user code. `readInto` may |
There was a problem hiding this comment.
"may be" is not very confidence building here
Sorry, something went wrong.
|
It's such a leaky abstraction tho, I'm not really keen on increasing the complexity of streams tbh and this certainly does that. I'd prefer if this were something we could keep private in core for its own use until we're comfortable that the wins are big enough to share with users. |
Sorry, something went wrong.
|
@rvagg that will be hard, mainly because it will probably leak into readable-stream at the next release. My concern is mainly related to the current non applicability of this to pipe(), to get "global" benefits. I'll be more than happy to "port" some of my MQTT stuff to readInto to check if I get benefits. |
Sorry, something went wrong.
|
@rvagg What's unfortunate is that the idea is conceptually simple. Streams are what make everything else more complicated. I'd like to see this in core. Creating many buffers for incoming packets is the limiting throughput factor for TCP I/O. @bnoordhuis That's sort of the API I was hoping for. Problem is the 'readable' event only fires once data has already been read in. So the Buffer that will hold the data needs to be supplied before the 'readable' event fires. I see the flow going something like so:
Well, that's a rough outline of what I was thinking. |
Sorry, something went wrong.
|
Any progress on this? This would be really awesome. |
Sorry, something went wrong.
|
I'm still very interested in this as well. FWIW I just wrote my own implementation that is strictly limited to sockets and bypasses streams altogether to make things simple and straight-forward (although the 'end' event should still be emitted during socket close). This means that the socket is either always using a single Buffer during its lifetime or it's always in "malloc mode." A Buffer and a callback are both needed to activate the new behavior. I see almost 2x throughput in benchmark/net-s2c.js with this new mode. It works like this: const socket = net.connect({
port: 12345,
buffer: Buffer.alloc(65535),
onread: (nread, buffer) => {
// buffer argument === buffer property above
// return `false` explicitly to stop reading, `socket.read(0)`
// or similar should restart it
}
});Example "malloc mode" result: net/net-s2c.js dur=5 recvbuf=0 type="buf" len=102400: 15.772152211480213 Example new mode result: net/net-s2c.js dur=5 recvbuf=65535 type="buf" len=102400: 28.297843930773467 |
Sorry, something went wrong.
|
I would love to have something like this implemented. I just do not see how we can achieve that with the current stream API. I'm open to suggestions. This might be relevant to the discussion: https://github.com/mcollina/syncthrough. It's like Transform but sync (it respects the Streams 3 contract, apart from the buffering). Because it's sync, we can guarantee that the chunk has been processed afterwards. |
Sorry, something went wrong.
|
Perhaps we will have to just skip streams to make it simple and/or doable. I think starting with net.Socket will go a long way, as there are lots of existing modules that could benefit just from that (e.g. database drivers). |
Sorry, something went wrong.
|
Thanks @mscdex, would you be able to provide me with a copy of that code (even very raw)? I don't mind doing more work to open source it. |
Sorry, something went wrong.
|
@jorangreef I just pushed what I currently have to https://github.com/mscdex/io.js/tree/net-socket-static-buffer. I'm sure some of the C++ changes could be designed better but meh... |
Sorry, something went wrong.
|
Closing as this seems inactive. By all means, comment or re-open if this is still an ongoing concern, although I suspect it should be moved to a more active repository (probably the main node repo) if that's the case. |
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
See: nodejs/node#6923