FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

gh-121313: multiprocessing: change connection buffer size to 64KiB by methane · Pull Request #123559 · python/cpython · GitHub

/ cpython Public
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .py  (1) .rst  (2) All 2 file types selected
Deleted files Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
20 changes: 4 additions & 16 deletions Lib/multiprocessing/connection.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import io
import itertools
import os
import stat
import sys
import socket
import struct
Expand All @@ -40,7 +39,9 @@
#
#

BUFSIZE = 8192
# 64 KiB is the default PIPE buffer size of most POSIX platforms.
BUFSIZE = 64 * 1024

# A very generous timeout when it comes to local connections...
CONNECTION_TIMEOUT = 20.

Expand Down Expand Up @@ -361,11 +362,6 @@ def _get_more_data(self, ov, maxsize):
f.write(ov.getbuffer())
return f

"""
The default size of a pipe on Linux systems is 16 times the base page size:
https://man7.org/linux/man-pages/man7/pipe.7.html
"""
PAGES_PER_PIPE = 16

class Connection(_ConnectionBase):
"""
Expand All @@ -378,14 +374,11 @@ def _close(self, _close=_multiprocessing.closesocket):
_close(self._handle)
_write = _multiprocessing.send
_read = _multiprocessing.recv
_default_pipe_size = 0
else:
def _close(self, _close=os.close):
_close(self._handle)
_write = os.write
_read = os.read
_base_page_size = os.sysconf(os.sysconf_names['SC_PAGESIZE'])
_default_pipe_size = _base_page_size * PAGES_PER_PIPE
Comment thread
methane marked this conversation as resolved.

def _send(self, buf, write=_write):
remaining = len(buf)
Expand All @@ -400,13 +393,8 @@ def _recv(self, size, read=_read):
buf = io.BytesIO()
handle = self._handle
remaining = size
is_pipe = 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
while remaining > 0:
to_read = min(limit, remaining)
to_read = min(BUFSIZE, remaining)
chunk = read(handle, to_read)
n = len(chunk)
if n == 0:
Expand Down

This file was deleted.

This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Limit the reading size in the :class:`multiprocessing.connection.Connection` class to 64 KiB to prevent memory overallocation and unnecessary memory management system calls.

Back | FazBrowse Home | New Git URL