[New-bugs-announce] [issue15139] Speed up threading.Condition wakeup

Kristján Valur Jónsson report at bugs.python.org
Fri Jun 22 17:38:32 CEST 2012


New submission from Kristján Valur Jónsson <kristjan at ccpgames.com>:

This patch is based on work previously done locally in python 2.7, see http://blog.ccpgames.com/kristjan/2012/05/25/optimizing-python-condition-variables-with-telemetry/

The idea is to acquire the signaling Lock() of the threading.Condition object _and_ the outer lock, without releasing and re-aquiring the GIL in between that is, as an atomic operation from the program's point of view.

_thread.LockType objects, used by the Condition object, now have an _acquire_condition method which knows how to do it for LockType and RLock objects.

Both lock types grow _release_save and _acquire_restore methods, the latter of which is a no-op.

_acquire_coindition() will ignore any other kinds of locks, including subclasses (if such things exist).

The result of this is a very marked improvement in signaling time on a contested machine.  A file, queuetest.py is provided which measures the wakeup delay.

Typical before the change:
best:    totaltime: 0.167006, avg delay: 0.004766, delay_stddev: 0.002058
typical: totaltime: 0.154271, avg delay: 0.027621, delay_stddev: 0.007479

after the change
typical: totaltime: 0.169217, avg delay: 0.001410, delay_stddev: 0.000722

----------
components: Interpreter Core, Library (Lib)
files: condition.patch
keywords: patch
messages: 163423
nosy: kristjan.jonsson
priority: normal
severity: normal
status: open
title: Speed up threading.Condition wakeup
type: performance
versions: Python 3.3
Added file: http://bugs.python.org/file26085/condition.patch

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue15139>
_______________________________________


More information about the New-bugs-announce mailing list