-
Notifications
You must be signed in to change notification settings - Fork 30.2k
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
Making C++ streams API public #921
Comments
Does this allow addon authors to create streams3 streams from C++? If so, what does the js-land part look like for hooking up to the generic C++ stream binding? |
@mscdex not yet, but a good suggestion. Current API is about doing efficient wrapping of the underlying socket to implement some protocol: tls, (maybe) http2, spdy, mysql... |
Conceptually +1 to having a public c++ streams base class. |
@piscisaureus why not? alloc/read is the whole point of this thing, because it allows efficient reading straight into the prepared memory. In fact, this is the reason why TLSSocket is faster than legacy tls in v0.10 node.js . AfterWrite could be shaved off, I guess. |
@piscisaureus here is a first pass on making it suitable as a user API: #957 . I'm not yet sure how to kill AfterWrite. |
@indutny We've been attempting to optimize a very performance-critical portion of our code base related to streams (specifically, stream transformations) and the idea of moving our implementation to C++ has been tossed around. Do you think your latest additions puts the code close to the point where a C++ streams3 implementation is possible? If you could provide a little guidance on what might be left to be done on the Node side, I'm sure we can spare some time to help out move the ball forward. |
@sgerace this StreamBase C++ API saves lots of time that is usually spent on allocating intermediate data, and copying values around. This proved to be very useful for TLS and HTTP, but I can't say for sure that every use case will benefit from it. Right now there are several blockers to exposing it:
Another important thing is user feedback. I have used this API in two places in core so far, and am pretty much happy about how it works. But, perhaps, your use-case requires more flexibility from it. Let me know if you have any ideas for improvements! Thanks! |
@indutny Perhaps if I provide a little bit more information about our exact use case, you might be able to guide us down the correct path. Basically, we are trying to validate (both against the JSON spec and our own schema definitions), hash (in a consistent way) and gzip very large JSON objects in a streaming manner. This whole thing actually came about because our initial implementation simply read the data, called a |
@sgerace do this JSON objects come over TCP socket? |
@indutny Yeah, the input streams come from both HTTP requests and direct TCP sockets and the output is ultimately piped to an external (permanent) data store (such as hard disk or S3). |
@sgerace this is very interesting use case. I think it could probably be solved by using two StreamBase instances (one for receiving data, and one for sending data to another socket), and connecting them in C++. The idea of StreamBase is to eliminate networking <-> JS code interaction, and do processing in C++. However please be aware that the networking API is very low-level there, so it may be more complicated to implement it there. |
@indutny So, let me see if I understand what you are saying; basically, we would create an add-on function (in C++) that accepts, as two of its arguments, two StreamBase instances (which would obviously be provided as Streams from JS) and then somehow read the data from the first stream, process it, and write the result to the second stream which would then find its way back to JS-land. Am I understanding that correctly? |
@sgerace not exactly
This way - JS maybe skipped altogether. If you want to leave sending data to JS, you may use just a single StreamBase instance to process incoming data and emit processed data like it has been received on that socket. |
@indutny Okay, so I'm starting to get a better picture of this, but now I've got a few more questions.
|
|
@indutny Thanks for the summary, I think after looking over everything (and spending a few more days playing around with the code), we've decided to go with a more traditional |
Thanks for collaboration! |
See: nodejs/node-eps#2 |
Close on the assumption that nodejs/node-eps#2 supersedes this issue. There's not been much movement here in the last four months either. |
As of b968623 we finally have something that might be useful for external bindings. I'd like to eventually make this API public.
What are your thoughts on this? What should be improved/changed in order to make it more useful?
cc @iojs/collaborators @iojs/community-members @iojs/streams @iojs/tc
The text was updated successfully, but these errors were encountered: