File tree Expand file tree Collapse file tree 1 file changed +22
-0
lines changed Expand file tree Collapse file tree 1 file changed +22
-0
lines changed Original file line number Diff line number Diff line change @@ -87,6 +87,27 @@ def getenv_int(key, default=0):
87
87
return default
88
88
89
89
90
+ def setup_gil ():
91
+ """
92
+ Set extremely long GIL release interval to let threads naturally progress
93
+ through CPU-heavy sequences without forcing the wake of another thread that
94
+ may contend trying to run the same CPU-heavy code. For the new-style work,
95
+ this drops runtime ~33% and involuntary context switches by >80%,
96
+ essentially making threads cooperatively scheduled.
97
+ """
98
+ try :
99
+ # Python 2.
100
+ sys .setcheckinterval (100000 )
101
+ except AttributeError :
102
+ pass
103
+
104
+ try :
105
+ # Python 3.
106
+ sys .setswitchinterval (10 )
107
+ except AttributeError :
108
+ pass
109
+
110
+
90
111
class MuxProcess (object ):
91
112
"""
92
113
Implement a subprocess forked from the Ansible top-level, as a safe place
@@ -147,6 +168,7 @@ def start(cls):
147
168
if faulthandler is not None :
148
169
faulthandler .enable ()
149
170
171
+ setup_gil ()
150
172
cls .unix_listener_path = mitogen .unix .make_socket_path ()
151
173
cls .worker_sock , cls .child_sock = socket .socketpair ()
152
174
atexit .register (lambda : clean_shutdown (cls .worker_sock ))
You can’t perform that action at this time.
0 commit comments