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

bpo-36051: drop GIL during large b''.join operations #17757

Merged
merged 6 commits into from Jan 29, 2020
Merged

Conversation

@bmerry
Copy link
Contributor

bmerry commented Dec 30, 2019

Improve multi-threaded performance by dropping the GIL in the fast path
of bytes.join. To avoid increasing overhead for small joins, it is only
done if the output size exceeds a threshold.

https://bugs.python.org/issue36051

Improve multi-threaded performance by dropping the GIL in the fast path
of bytes.join. To avoid increasing overhead for small joins, it is only
done if the output size exceeds a threshold.
@bmerry

This comment has been minimized.

Copy link
Contributor Author

bmerry commented Dec 30, 2019

For now I've only made the change for the b''.join fast-path, but if there is agreement I could also add it to the general case (non-empty separator).

I think the code is safe against another thread mutating the sequence while the GIL is dropped (because the setup code takes it own refs to all the items), but it would be good if someone could double-check it.

bmerry added 3 commits Dec 31, 2019
The existing stress test is increased in size to exceed GIL_THRESHOLD,
and a new stress test is added with an empty separator (since that is a
separate code path).
The GIL is now also dropped in the code path with non-empty separator,
but it is *not* dropped if any of the items is not a `bytes` object (see
discussion in bpo-36051 for reasoning).
Benchmarking shows that for smaller thresholds the multi-threading
performance tends to be worse, or at least not much better.
@bmerry bmerry requested a review from methane Jan 27, 2020
@@ -0,0 +1 @@
Drop the GIL during large ``bytes.join`` operations.

This comment has been minimized.

Copy link
@methane

methane Jan 28, 2020

Member

Add your name in ACKS (see https://devguide.python.org/pullrequest/#crediting),
and add "Patch by ...." here.

This comment has been minimized.

Copy link
@bmerry

bmerry Jan 29, 2020

Author Contributor

I've already added myself to ACKS, but have now added "Patch by ...".

This comment has been minimized.

Copy link
@methane

This comment has been minimized.

Copy link
@bmerry

bmerry Jan 29, 2020

Author Contributor

That's the master version of ACKS. I'm adding myself in this pull request: https://github.com/bmerry/cpython/blob/bpo-36051/Misc/ACKS#L1109

@methane methane merged commit d07d9f4 into python:master Jan 29, 2020
8 of 9 checks passed
8 of 9 checks passed
Docs
Details
Windows (x86)
Details
Windows (x64)
Details
macOS
Details
Ubuntu
Details
continuous-integration/travis-ci/pr The Travis CI build could not complete due to an error
Details
Azure Pipelines PR #20200129.11 succeeded
Details
bedevere/issue-number Issue number 36051 found
Details
bedevere/news News entry found in Misc/NEWS.d
@bmerry bmerry deleted the bmerry:bpo-36051 branch Jan 29, 2020
@bedevere-bot

This comment has been minimized.

Copy link

bedevere-bot commented Jan 29, 2020

⚠️⚠️⚠️ Buildbot failure ⚠️⚠️⚠️

Hi! The buildbot PPC64LE Fedora 3.x has failed when building commit d07d9f4.

What do you need to do:

  1. Don't panic.
  2. Check the buildbot page in the devguide if you don't know what the buildbots are or how they work.
  3. Go to the page of the buildbot that failed (https://buildbot.python.org/all/#builders/11/builds/259) and take a look at the build logs.
  4. Check if the failure is related to this commit (d07d9f4) or if it is a false positive.
  5. If the failure is related to this commit, please, reflect that on the issue and make a new Pull Request with a fix.

You can take a look at the buildbot page here:

https://buildbot.python.org/all/#builders/11/builds/259

Failed tests:

  • test_largefile

Failed subtests:

  • test_it - test.test_largefile.TestCopyfile
  • test_it - test.test_largefile.TestSocketSendfile
  • setUpClass - test.test_asyncio.test_base_events.BaseLoopSockSendfileTests

Summary of the results of the build (if available):

== Tests result: FAILURE then FAILURE ==

406 tests OK.

10 slowest tests:

  • test_mailbox: 8 min 18 sec
  • test_shelve: 6 min 14 sec
  • test_multiprocessing_spawn: 2 min 51 sec
  • test_concurrent_futures: 2 min 45 sec
  • test_posix: 2 min 40 sec
  • test_capi: 2 min 35 sec
  • test_tokenize: 2 min 26 sec
  • test_unparse: 2 min 24 sec
  • test_lib2to3: 2 min 7 sec
  • test_multiprocessing_forkserver: 1 min 55 sec

1 test failed:
test_largefile

13 tests skipped:
test_devpoll test_ioctl test_kqueue test_msilib test_ossaudiodev
test_startfile test_tix test_tk test_ttk_guionly test_winconsoleio
test_winreg test_winsound test_zipfile64

2 re-run tests:
test_asyncio test_largefile

Total duration: 42 min 12 sec

Click to see traceback logs
Traceback (most recent call last):
  File "/home/shager/cpython-buildarea/3.x.edelsohn-fedora-ppc64le/build/Lib/test/test_largefile.py", line 195, in run
    f.write(chunk)
OSError: [Errno 28] No space left on device


Traceback (most recent call last):
  File "/home/shager/cpython-buildarea/3.x.edelsohn-fedora-ppc64le/build/Lib/test/test_largefile.py", line 161, in test_it
    shutil.copyfile(TESTFN, TESTFN2)
  File "/home/shager/cpython-buildarea/3.x.edelsohn-fedora-ppc64le/build/Lib/shutil.py", line 270, in copyfile
    _fastcopy_sendfile(fsrc, fdst)
  File "/home/shager/cpython-buildarea/3.x.edelsohn-fedora-ppc64le/build/Lib/shutil.py", line 163, in _fastcopy_sendfile
    raise err from None
  File "/home/shager/cpython-buildarea/3.x.edelsohn-fedora-ppc64le/build/Lib/shutil.py", line 149, in _fastcopy_sendfile
    sent = os.sendfile(outfd, infd, offset, blocksize)
OSError: [Errno 28] No space left on device: '@test_38097_tmp' -> '@test_38097_tmp2'


Traceback (most recent call last):
  File "/home/shager/cpython-buildarea/3.x.edelsohn-fedora-ppc64le/build/Lib/test/test_largefile.py", line 161, in test_it
    shutil.copyfile(TESTFN, TESTFN2)
  File "/home/shager/cpython-buildarea/3.x.edelsohn-fedora-ppc64le/build/Lib/shutil.py", line 270, in copyfile
    _fastcopy_sendfile(fsrc, fdst)
  File "/home/shager/cpython-buildarea/3.x.edelsohn-fedora-ppc64le/build/Lib/shutil.py", line 163, in _fastcopy_sendfile
    raise err from None
  File "/home/shager/cpython-buildarea/3.x.edelsohn-fedora-ppc64le/build/Lib/shutil.py", line 149, in _fastcopy_sendfile
    sent = os.sendfile(outfd, infd, offset, blocksize)
OSError: [Errno 28] No space left on device: '@test_10521_tmp' -> '@test_10521_tmp2'


Traceback (most recent call last):
  File "/home/shager/cpython-buildarea/3.x.edelsohn-fedora-ppc64le/build/Lib/test/test_largefile.py", line 209, in test_it
    client.sendfile(f)
  File "/home/shager/cpython-buildarea/3.x.edelsohn-fedora-ppc64le/build/Lib/socket.py", line 483, in sendfile
    return self._sendfile_use_sendfile(file, offset, count)
  File "/home/shager/cpython-buildarea/3.x.edelsohn-fedora-ppc64le/build/Lib/socket.py", line 400, in _sendfile_use_sendfile
    raise err from None
  File "/home/shager/cpython-buildarea/3.x.edelsohn-fedora-ppc64le/build/Lib/socket.py", line 386, in _sendfile_use_sendfile
    sent = os_sendfile(sockno, fileno, offset, blocksize)
BrokenPipeError: [Errno 32] Broken pipe


Traceback (most recent call last):
  File "/home/shager/cpython-buildarea/3.x.edelsohn-fedora-ppc64le/build/Lib/test/test_asyncio/test_base_events.py", line 1986, in setUpClass
    with open(support.TESTFN, 'wb') as fp:
OSError: [Errno 28] No space left on device: '@test_43782_tmp'


Traceback (most recent call last):
  File "/home/shager/cpython-buildarea/3.x.edelsohn-fedora-ppc64le/build/Lib/threading.py", line 944, in _bootstrap_inner
    self.run()
  File "/home/shager/cpython-buildarea/3.x.edelsohn-fedora-ppc64le/build/Lib/threading.py", line 882, in run
    self._target(*self._args, **self._kwargs)
  File "/home/shager/cpython-buildarea/3.x.edelsohn-fedora-ppc64le/build/Lib/test/test_largefile.py", line 195, in run
    f.write(chunk)
OSError: [Errno 28] No space left on device
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants
You can’t perform that action at this time.