Skip to content

Implementation of multipart-pipe-reader - #15056

Closed
gilmishal wants to merge 58 commits into
dotnet:masterfrom
gilmishal:gilmishal/multipart-pipe-reader
Closed

gilmishal wants to merge 58 commits into
dotnet:masterfrom
gilmishal:gilmishal/multipart-pipe-reader

Conversation

@gilmishal

Copy link
Copy Markdown

Summary of the changes (Less than 80 chars)

  • Created MultipartPipeReader based on FormPipeReader and MultipartReader
  • Implemented some of the tests, to make sure that I am on the right track

Remaining

  • Recreate, and pass all unit and performance tests from MultipartReader`.
  • Recreate some of the tests from FromPipeReader to insure reads in different memory scenarios
  • Update FormFeature to use the new MultipartPipeReader

Not Sure

  • Today the MultipartReader Returns a MultipartSection with a Stream as Body - I believe the stream capabilities should remain to not create a breaking change - I created a memory stream which might be costly in terms of performance, and I think I should probably create a stream similar to the buffered stream - If you have any other ideas including getting rid of the stream altogether I can do that.
  • Handle Fast Parsing when I don't handle it now- I am assuming that it has some performance benefits.
  • Do something about all these private methods - It seems to me that I have copied and pasted way too much code to create all the reading capabilities over ReadonlySequence<> and I would suggest creating some sort of a utility class that handles these reads (should probably affect FormPipeReader too)

Addresses #11377 (in this specific format)

@dnfclas

dnfclas commented Oct 16, 2019 •

Copy link
Copy Markdown

CLA assistant check
All CLA requirements met.

@Tratcher Tratcher left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

An ambitious start, but mutlipart is much more work to parse efficiently than form data.

@davidfowl davidfowl added the api-suggestion Early API idea and discussion, it is NOT ready for implementation label Oct 17, 2019
@gilmishal

Copy link
Copy Markdown
Author

@Tratcher I will try to address all the comments you added and create a commit. I noticed a few bugs when I updated the tests and already began work on fixing some of what you mentioned.

@analogrelay analogrelay added this to the 5.0.0-preview1 milestone Oct 17, 2019

@gfoidl gfoidl left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Move all know delimiters (end of line, colon, ...) to static fields.

@gilmishal

gilmishal commented Oct 22, 2019 •

Copy link
Copy Markdown
Author

I think that I got the hang of PipeReader.

This update should work relatively well and it should take into account most of the differences between a Stream and a PipeReader, it also passes all tests.

Issues

  • I commented out the test that makes sure that an exception is thrown when the buffer size is too small because it makes no sense
  • I had an issue with pipeReader.TryRead that it returned false even though the result isn't completed. This results in an empty buffer, even though there is still more to read - I am not sure what to do in this case, other than maybe create an endless loop until it returns true. for that reason I replaced a Read call to a ReadAsync in one of the tests. I am not sure how important it is to support synchronous Read, but currently it's working unexpectedly.

Still to be done

  • Make sure that I handle all edge cases and throw the correct exceptions (i.e final block, invalid data)
  • I used an accumulator to set the BaseStreamOffset - I need to make sure that

Suggestions

  • Replace MultipartPipeReaderStream to another type - it makes little sense to use Stream in this situation. This would of course require changes to FormMultipartSection and FormFeature

@gilmishal

Copy link
Copy Markdown
Author

I added an IOException when there is not enough data to comply with the failing test - however it still fails because I do things a little differently than the MultipartReaderStream.
I currently don't return a result from ReadAsync unless I fully find a match for the boundary or fill the buffer. Now I could either return a result and keep a similar functionality or throw an exception earlier and just update the test to pass because I am not sure if my way is worse (I can think of why it's better since it throws the exception before any parsing that aren't required anymore will take action).

@gilmishal

Copy link
Copy Markdown
Author

I think I created something that is somewhat production ready. I need to create the Performance tests to make sure that this is an improvement.
I do think that in order to take full advantage of this MPR I would need to make changes to the way DrainAsync works (use advance instead of read) and there should be changes to FormMultipartSection

@gilmishal

Copy link
Copy Markdown
Author

I updated FormFeature to use MultipartPipeReader, however the test won't pass when buffering isn't enabled - the reason for this is that I always set a BaseStreamOffset (since I can't set a position on MultipartPipeReaderStream, because PipeReaders don't support it) - Now since the test use NonSeekableStream as the body, which their position also cannot be set, the tests fail. I am not really sure how to address this issue, and your guidance would be appreciated.

@Tratcher Tratcher self-assigned this Nov 5, 2019
@gilmishal

Copy link
Copy Markdown
Author

@Tratcher any update on what should I do next? Specifically regarding the tests that aren't passing?

and what do you think about updating FormMultipartSection to take advantage of pipeReader?
or changing DrainAsync to not allocate those byte arrays?

@jkotalik jkotalik left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Did you manage to get perf numbers? Curious how this is looking.

@gilmishal

Copy link
Copy Markdown
Author

Did you manage to get perf numbers? Curious how this is looking.

image

this are the numbers when running the test I created - you can see the code to decide whether the tests are representative enough

@Tratcher Tratcher removed this from the 5.0.0-preview2 milestone Apr 13, 2020
@Tratcher
Tratcher marked this pull request as draft April 13, 2020 16:58
@analogrelay analogrelay added this to the 5.0.0-preview5 milestone Apr 20, 2020
@Tratcher

Copy link
Copy Markdown
Member

@gilmishal thanks for the effort you put into this, but I don't think any of us have the time to finish it right now. I'm going to close this PR until we can come back to it.
I'm saving a copy of the changes over at https://github.com/Tratcher/aspnetcore/tree/tratcher/multipart-pipe-reader.

@Tratcher Tratcher closed this May 19, 2020
@gilmishal

Copy link
Copy Markdown
Author

@Tratcher If I do find time to try and work on it, should I work on it? What's left to do?

@Tratcher

Copy link
Copy Markdown
Member

Go head. You'll want to pick up my branch though, it had some changes I hadn't pushed here. I don't remember the details, it's been too long since I worked on it, but there were still some failing test cases.

@davidfowl

davidfowl commented May 20, 2020 •

Copy link
Copy Markdown
Member

@gilmishal I have some ideas. I think we should do this still, if you're willing, lets design the API and start another PR. I don't think this was too far off but to take more baby steps I think we should do a fully streaming API and not touch the FormFeature to begin with.

We should design a more efficient version of the existing MultiPartReader that doesn't buffer beyond the pipe buffer itself.

@gilmishal

Copy link
Copy Markdown
Author

@davidfowl I am not sure if this is still relevant, but I would love to pick this up again. However I think we should do it differently this time and verify we are on the same page before I start working on it again. Should I come up with a design and let you review it? Should we work on one together? Do you have a design that I can follow?

@Tratcher

Copy link
Copy Markdown
Member

FYI I still have the old version in a branch:
https://github.com/Tratcher/aspnetcore/tree/tratcher/multipart-pipe-reader

Yes it's still relevant, and as David said, if we can start with the lowest level APIs (e.g. MultipartReader) to make sure those are solid, then we can work up from there.

@gilmishal

Copy link
Copy Markdown
Author

@Tratcher I started working on it.
Since we want to start only the changes to MultipartPipeReader and MultipartSectionPipeReader - I decided not to Rebase the entire branch onto master, and start from scratch - as it would take a few hours work, and is quite a bit error prawn. I did checkout these specific files and their tests, but sadly it didn't keep the history - however, my changes after are visible.

Anyways, I got most of the tests working - but I do have quite a bit of questions before I can continue. Should I create a new PR and shall we discuss the next steps there?

@ghost

ghost commented Dec 30, 2020

Copy link
Copy Markdown

Hi @gilmishal. It looks like you just commented on a closed PR. The team will most probably miss it. If you'd like to bring something important up to their attention, consider filing a new issue and add enough details to build context.

@Tratcher

Copy link
Copy Markdown
Member

@gilmishal if you have design questions then please start with an issue. If you have code questions then open a draft PR.

@ghost

ghost commented Dec 30, 2020

Copy link
Copy Markdown

Hi @Tratcher. It looks like you just commented on a closed PR. The team will most probably miss it. If you'd like to bring something important up to their attention, consider filing a new issue and add enough details to build context.

@amcasey amcasey added area-networking Includes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions and removed area-runtime labels Aug 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api-suggestion Early API idea and discussion, it is NOT ready for implementation area-networking Includes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants