Skip to content

gh-123557: Limit the reading size from Unix sockets to same limit pipes use #123558

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

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
108e65b
Add clean code
aplaikner Jul 3, 2024
37ca606
Fix linting error & sysconf unsupported error
aplaikner Jul 3, 2024
df4f307
Merge branch 'main' into feature-smaller-pipe-buffer-pull-request
aplaikner Jul 3, 2024
89936c2
📜🤖 Added by blurb_it.
blurb-it[bot] Jul 3, 2024
31c65b4
Fix news
aplaikner Jul 3, 2024
0a4e4a3
Make page size non static
aplaikner Jul 3, 2024
7afde51
Merge branch 'main' into feature-smaller-pipe-buffer-pull-request
aplaikner Jul 3, 2024
8d9b16e
Merge branch 'main' into feature-smaller-pipe-buffer-pull-request
aplaikner Jul 3, 2024
e6c64fe
Remove redundant call to pymin
aplaikner Jul 4, 2024
936b601
Shift pipe check to connection.py _recv
aplaikner Jul 5, 2024
49d8adb
Make pipe size dependant on systems page size
aplaikner Jul 5, 2024
43e19dd
Only execute fstat in case reading size is bigger than default pipe size
aplaikner Jul 5, 2024
b0b86e5
Update news message
aplaikner Jul 7, 2024
2b6ff24
Make imports order alphabetical
aplaikner Jul 7, 2024
e726f51
Shift calculation for pipe size to existing if _winapi check
aplaikner Jul 7, 2024
59cff4d
Fix linting error
aplaikner Jul 7, 2024
da10f8e
Merge branch 'main' into feature-smaller-pipe-buffer-pull-request
aplaikner Jul 7, 2024
94d4c4a
Create constant for default number of pages per pipe
aplaikner Jul 7, 2024
ed7fdac
Extend pipes fix to Unix sockets
aplaikner Jul 13, 2024
54f3d5a
Merge branch 'feature-smaller-socket-buffer-pull-request' into featur…
aplaikner Sep 1, 2024
481d6ee
Merge pull request #1 from aplaikner/feature-smaller-socket-buffer
aplaikner Sep 1, 2024
d130d8f
📜🤖 Added by blurb_it.
blurb-it[bot] Sep 1, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions Lib/multiprocessing/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -400,11 +400,12 @@ def _recv(self, size, read=_read):
buf = io.BytesIO()
handle = self._handle
remaining = size
is_pipe = False
is_pipe = is_socket = False
if size > self._default_pipe_size > 0:
mode = os.fstat(handle).st_mode
is_pipe = stat.S_ISFIFO(mode)
limit = self._default_pipe_size if is_pipe else remaining
is_socket = stat.S_ISSOCK(mode)
limit = self._default_pipe_size if is_pipe or is_socket else remaining
Copy link
Member

Choose a reason for hiding this comment

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

How about use the limit for all connection, instead of socket and pipe?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If there are no performance drawbacks for other types of connections, then it's a solid solution. I've only analyzed pipes and sockets.

Copy link
Member

Choose a reason for hiding this comment

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

I don't know connection other than pipe and socket.
But mmap+mremap+munmap overhead is very common issue for all streams.
So using chunked read by default and override it in special connection class seems better solution.

while remaining > 0:
to_read = min(limit, remaining)
chunk = read(handle, to_read)
Expand Down
Copy link
Member

Choose a reason for hiding this comment

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

How about updating Misc/NEWS.d/next/C API/2024-07-03-10-11-53.gh-issue-121313.D7gARW.rst instead of adding new changelog?
Changelog is part of Python documentation. It should be readable than commitlog for Python users.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was prompted by the blurp it bot to create a summary of the changes via the separate website.

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This PR would fix the problem of overallocating memory when reading from Unix sockets, extending the merged PR regarding pipes.
Loading