bpo-41279: Add StreamReaderBufferedProtocol#21446
Conversation
d594f7a to
af23da7
Compare
July 11, 2020 17:38
af23da7 to
c533f08
Compare
July 14, 2020 20:49
c533f08 to
806b335
Compare
July 14, 2020 22:28
806b335 to
62da6f0
Compare
July 14, 2020 22:41
62da6f0 to
ac1418d
Compare
July 14, 2020 22:54
ac1418d to
71ea0a6
Compare
July 15, 2020 08:04
71ea0a6 to
2a4a9eb
Compare
July 16, 2020 23:30
2a4a9eb to
38704db
Compare
July 17, 2020 10:45
0f02cac to
90b9e44
Compare
July 19, 2020 23:21
|
I still need to fix the |
Sorry, something went wrong.
|
I am not sure global_buffer is the correct name. Also not sure if it's better or not, but maybe buffer_size=0 (which can be the default) instead of using another variable ? Also maybe word better " Use carefully as each client connected to the server will allocate a 64k Stating that when using this buffer, each stream will pre-allocated a buffer (by default 64k) which will be used for the lifetime of the stream, even when no data is passed, which might stress memory in heavy concurrent stream usages. |
Sorry, something went wrong.
|
BTW, speaking of this performance, I've tried coding a zero allocation + zero copying data structure in Python to get rid of those allocations (by using an optional global pool) and copies: https://github.com/tzickel/chunkedbuffer In theory this can be used directly in the readinto part, and be exposed outside in the streamreader interface itself (without another copying like here). |
Sorry, something went wrong.
I thought about doing it inside streamreader, so I wrote it locally and saw an improvement but not as much as in this branch (I wanted to maybe create a new PR after this one that) About a memory pool, that's also good but requires a lot of planning of where it would sit + what would happen if we run out of memory in the pool but we still need to make a read call, that's another issue.
You are probably right, I'll just do buffer_size=0, and no I don't think it should be default. |
Sorry, something went wrong.
1st1
left a comment
There was a problem hiding this comment.
This is one high quality PR, thanks for working on it. The fixes in proactor_events.py alone are great. I've left a couple comments.
Sorry, something went wrong.
|
@asvetlov is going to take a look in a couple of days. Let's give this time until next Tuesday. |
Sorry, something went wrong.
|
A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated. Once you have made the requested changes, please leave a comment on this pull request containing the phrase |
Sorry, something went wrong.
|
Hey, just remembered that I did this, bumping! :) |
Sorry, something went wrong.
This class gets better performance as BufferedProtocol uses read_into into a buffer allocated before, instead of allocating a new buffer each time read is called.
…pythonGH-21446) The transport did not know how to use the proper api exported by BufferedProtocol. Added a new callback function that calls getbuffer() and buffer_updated() instead of data_received() when the protocol given to it is of type BufferedProtocol. This is exactly the same way _SelectorSocketTransport handles a BufferedProtocol.
…port (pythonGH-21446) In the __init__ function if the protocol is of instance BufferedProtocol instead of creating a buffer object, we call get_buffer on the protocol to get its buffer. In addition _loop_reading now calls _data_received as soon as there is actual data instead of calling only after adding a recv_into event. The reason for this change is because read_into could call it's callback immediatly meaning overriding the data on the buffer before we actually call _data_received on it, which fixes the potential issue of missed data.
|
I'll fix the ssl tests sometime this weekend |
Sorry, something went wrong.
|
@tontinton You can turn your PR into a draft and not worry about timeframes. |
Sorry, something went wrong.
…pythonGH-21446) When calling set_protocol to change the protocol you can now change the type of the protocol from BufferedProtocol to Protocol or vice versa. start_tls needed this feature as it could read into a buffered protocol at first and then change the protocol to SSLProto which is a regular protocol.
|
This PR is stale because it has been open for 30 days with no activity. |
Sorry, something went wrong.
https://bugs.python.org/issue41279
I got way better performance on
await reader.read()using this branch on linux (check out the chart on theserver.pyscript's comments).The way I tested was writing a server / client:
server.py:client.py: