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

Implemented readuntil in StreamResponse #4734

Merged
merged 8 commits into from
Nov 2, 2020

Conversation

WisdomPill
Copy link
Member

@WisdomPill WisdomPill commented May 11, 2020

What do these changes do?

Added readuntil method, heavily mimicking asyncio.streams and recycling the code of readline in current StreamResponse class. With this change readline uses readuntil with \n as a separator
Same for the tests that just use different separators.

Are there changes in behavior for the user?

New way to wait for new data

Related issue number

#4054

Checklist

  • I think the code is well written
  • Unit tests for the changes exist
  • Documentation reflects the changes
  • If you provide code modification, please add yourself to CONTRIBUTORS.txt This change is inside another PR I submitted AioHTTPTestCase more async friendly #4732
  • Add a new news fragment into the CHANGES folder
    • name it <issue_id>.<type> for example (588.bugfix)
    • if you don't have an issue_id change it to the pr id after creating the pr
    • ensure type is one of the following:
      • .feature: Signifying a new feature.
      • .bugfix: Signifying a bug fix.
      • .doc: Signifying a documentation improvement.
      • .removal: Signifying a deprecation or removal of public API.
      • .misc: A ticket has been closed, but it is not of interest to users.
    • Make sure to use full sentences with correct case and punctuation, for example: "Fix issue with non-ascii contents in doctest text files."

@WisdomPill WisdomPill requested a review from asvetlov as a code owner May 11, 2020 08:14
@psf-chronographer psf-chronographer bot added the bot:chronographer:provided There is a change note present in this PR label May 11, 2020
@WisdomPill
Copy link
Member Author

I need to check if documentation work is needed or if it is automatic, meanwhile if somebody can clear my mind about this before I check it is welcome

not_enough = True

while not_enough:
while self._buffer and not_enough:
offset = self._buffer_offset
ichar = self._buffer[0].find(b'\n', offset) + 1
# Read from current offset to found b'\n' or to the end.
ichar = self._buffer[0].find(separator, offset) + 1
Copy link
Contributor

Choose a reason for hiding this comment

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

asyncio has much more effective solution. Why not to copy-paste it ?

Copy link
Member Author

Choose a reason for hiding this comment

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

I did not want to change much the code.

What do you think should be copied from asyncio implementation?

Copy link
Member

Choose a reason for hiding this comment

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

I think sync the implementation with asyncio would be great!
asyncio doesn't incrementally copy data to the buffer in a loop but calculates boundaries and move bytes once.

Copy link
Member Author

Choose a reason for hiding this comment

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

Okay, I will fix it

@codecov-io
Copy link

codecov-io commented Oct 21, 2020

Codecov Report

Merging #4734 into master will decrease coverage by 0.02%.
The diff coverage is 85.71%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #4734      +/-   ##
==========================================
- Coverage   97.56%   97.54%   -0.03%     
==========================================
  Files          43       43              
  Lines        8779     8784       +5     
  Branches     1412     1413       +1     
==========================================
+ Hits         8565     8568       +3     
- Misses        100      101       +1     
- Partials      114      115       +1     
Flag Coverage Δ
unit 97.54% <85.71%> (-0.03%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
aiohttp/streams.py 97.43% <85.71%> (-0.49%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 488b375...e94b827. Read the comment docs.

Copy link
Member

@asvetlov asvetlov left a comment

Choose a reason for hiding this comment

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

I can live with not the-fast-possible implementation but the documentation update is required for merging.

Please update docs/streams.rst

@WisdomPill
Copy link
Member Author

Yes, okay, this weekend I will have some time to fix it

@WisdomPill
Copy link
Member Author

Hello,

I tried to mimic more the asyncio implementation but it appears to me that it is quite difficult task and a lot of code will be changed.

Simply copying the data from self._buffer using boundaries is not possible as self._buffer is a deque.
To change this I can try by making self._buffer a bytearray which seems to me that it will lead to an improvement in performance but will need a lot of code rewrite.

I added the docs by the way.

@asvetlov asvetlov self-assigned this Nov 2, 2020
@WisdomPill
Copy link
Member Author

@asvetlov do you think the StreamReader could be written in a better and more performant way inheriting StreamReader from asyncio?

docs/streams.rst Outdated Show resolved Hide resolved
docs/streams.rst Outdated Show resolved Hide resolved
@asvetlov
Copy link
Member

asvetlov commented Nov 2, 2020

Thanks for the patience!

@asvetlov asvetlov merged commit db1a2cd into aio-libs:master Nov 2, 2020
github-actions bot pushed a commit that referenced this pull request Nov 2, 2020
@github-actions
Copy link
Contributor

github-actions bot commented Nov 2, 2020

💚 Backport successful

The PR was backported to the following branches:

asvetlov added a commit that referenced this pull request Nov 2, 2020
Co-authored-by: Andrew Svetlov <[email protected]>

Co-authored-by: Anas <[email protected]>
Co-authored-by: Andrew Svetlov <[email protected]>
commonism pushed a commit to commonism/aiohttp that referenced this pull request Apr 27, 2021
commonism pushed a commit to commonism/aiohttp that referenced this pull request Apr 27, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bot:chronographer:provided There is a change note present in this PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants