Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

Pray to God, but keep rowing to shore. -- Russian Proverb


devel / comp.lang.python / Fwd: I/O bound threads got to no chance to run with small CPU bound threads with new GIL

SubjectAuthor
o Fwd: I/O bound threads got to no chance to run with small CPU boundSouvik Ghosh

1
Fwd: I/O bound threads got to no chance to run with small CPU bound threads with new GIL

<mailman.72.1639242909.15287.python-list@python.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=16395&group=comp.lang.python#16395

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!news.szaf.org!fu-berlin.de!uni-berlin.de!not-for-mail
From: souvikgh...@gmail.com (Souvik Ghosh)
Newsgroups: comp.lang.python
Subject: Fwd: I/O bound threads got to no chance to run with small CPU bound
threads with new GIL
Date: Sat, 11 Dec 2021 17:39:12 +0530
Lines: 132
Message-ID: <mailman.72.1639242909.15287.python-list@python.org>
References: <CACaaUvH7OrFSzj3DUcGOO+swtLDAG9ijCDTLOJduHxFs+ZBm7g@mail.gmail.com>
<CACaaUvH0ZOUx8xo6Ms_-8ekhKTfiw-YKZzkZVUcM4Whcj=PX=g@mail.gmail.com>
Mime-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
X-Trace: news.uni-berlin.de FkhyN1rPYE4iWMg+jxLN5Ag8g6qm68A0PnuAfnUF00Bw==
Return-Path: <souvikghosh872@gmail.com>
X-Original-To: python-list@python.org
Delivered-To: python-list@mail.python.org
Authentication-Results: mail.python.org; dkim=pass
reason="2048-bit key; unprotected key"
header.d=gmail.com header.i=@gmail.com header.b=EWmGmQzW;
dkim-adsp=pass; dkim-atps=neutral
X-Spam-Status: OK 0.024
X-Spam-Evidence: '*H*': 0.95; '*S*': 0.00; '(which': 0.04; 'def':
0.04; 'thread': 0.05; 'cpu': 0.07; 'psf,': 0.07; 'queue': 0.07;
'forced': 0.09; 'much,': 0.09; 'subject:run': 0.09;
'subject:small': 0.09; 'threads': 0.09; 'timeout': 0.09; 'coding':
0.13; '&gt;': 0.14; 'import': 0.15; 'demonstrated': 0.16; 'ghosh':
0.16; 'gil': 0.16; 'happen.': 0.16; 'meantime': 0.16; 'python!':
0.16; 'received:209.85.210.52': 0.16; 'received:mail-
ot1-f52.google.com': 0.16; 'seconds.': 0.16; 'subject:GIL': 0.16;
'thats': 0.16; 'threading': 0.16; 'python': 0.16; "can't": 0.17;
'to:addr:python-list': 0.20; 'issue': 0.21; "i've": 0.22;
'returns': 0.22; 'sat,': 0.22; 'version': 0.23; 'code': 0.23;
'run': 0.23; 'url-ip:188.166/16': 0.25; '11,': 0.26;
'subject:Fwd': 0.26; 'mostly': 0.28; 'url-ip:188.166.48.69/32':
0.28; 'url-ip:188.166.48/24': 0.28; 'url:bugs': 0.28; 'email
addr:python.org&gt;': 0.28; 'received:209.85.210': 0.29; 'takes':
0.31; 'dec': 0.31; 'url-ip:188/8': 0.31; "doesn't": 0.32;
'---------': 0.32; 'zero': 0.32; 'message-id:@mail.gmail.com':
0.32; 'but': 0.32; "i'm": 0.33; '----------': 0.33; "didn't":
0.34; 'header:In-Reply-To:1': 0.34; 'received:google.com': 0.34;
'running': 0.34; 'runs': 0.35; 'submitted': 0.35; 'following':
0.35; 'from:addr:gmail.com': 0.35; "it's": 0.37;
'received:209.85': 0.37; 'though': 0.37; 'means': 0.38;
'received:209': 0.39; 'two': 0.39; 'added': 0.39; 'date:': 0.39;
'much.': 0.39; 'skip:u 20': 0.39; 'seconds': 0.40; 'both': 0.40;
'try': 0.40; 'should': 0.40; 'higher': 0.60; 'stated': 0.60; 'url-
ip:142.250.179.164/32': 0.60; 'tell': 0.60; 'method': 0.61;
'skip:0 20': 0.61; 'url-ip:142.250.179/24': 0.61; 'from:': 0.62;
'to:': 0.62; 'love': 0.62; 'lower': 0.62; 'great': 0.63; 'skip:b
20': 0.63; 'between': 0.63; 'skip:b 10': 0.63; 'pass': 0.64;
'among': 0.65; 'look': 0.65; 'years': 0.65; 'numbers': 0.67;
'priority': 0.67; 'skip:t 30': 0.67; 'time,': 0.67; 'exactly':
0.68; 'and,': 0.69; 'times': 0.69; 'within': 0.69; '2021': 0.71;
'care': 0.71; 'chance': 0.71; 'future': 0.72; 'returned': 0.81;
'happens': 0.84; 'email name:&lt;python-list': 0.84; 'responds':
0.84; 'subject: \n ': 0.84; 'subject:got': 0.84; 'subscribing':
0.84; 'switching': 0.84
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112;
h=mime-version:references:in-reply-to:from:date:message-id:subject:to;
bh=jWsOF6+YsryiZvSDQaktJqS7mTrsfugJ/Gmn7ie575w=;
b=EWmGmQzWbxyvT0oG4W1i/fpWbOiIfppUxDKKXrGYmP6E8di9so88Wx/bxvN04CXZjI
nDcrWNnDGVwfzAXccYoBNVap8gfrXUD82nxSucGFF15kaVWkQyu6NC2Tn2uXyv0kU+3Z
+MSIDjeV/aJ0Tim2SfKySV2+nJ29AHHyN0Q7V1e/fq1l3yC5U3+OyGgGj5II9MnUJQVw
Ylh95gq3RQOm2h4FEzFvmKDDa8EBGkQNCcXD3s8g+EdNHcv6aooihbvR99/Q1pYto0Ev
/YgvZOJIzKPwicfJDt5L/0KYps5L9YkJQ2HoeO9uaY27H/nwOexdqqX1nJVxWtUB03/2
azfw==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20210112;
h=x-gm-message-state:mime-version:references:in-reply-to:from:date
:message-id:subject:to;
bh=jWsOF6+YsryiZvSDQaktJqS7mTrsfugJ/Gmn7ie575w=;
b=n8tbnR34xwByxNvYpWEbD8RAa8nJrEN+gGMKNWj705frE8kevthtwBDt6GIvaDBdeF
61UqU0YiOjds7znVtUquvxjCOVKjBxxHR82pKNhZksIH6HyuuXUpZ9kqlnOVOlsYgNgR
pqMCHbVOpYdcjT0YKwvl9+dH8ZAgFAwWlCThGbK1WToN3XPRSLwgBl3PAiluk42bTVJu
ky8xEtQoPMAXIBbWdvM8Ec+QknsqGbeIwEo7Vl0b4WyKrJGZ68lB+ihpWvNvirGJzpAl
kOSVvDvanIjCcWwp3suSU67+4qTaiMYKyBpU0KRlQpiEEBI8z/GSWepyEdNIX2jwtNtK
NyIQ==
X-Gm-Message-State: AOAM530JW8Nq+Q9dvjIZKa9E3FN6st55e/yz9xEbCcb1y9u3RXkKXfYf
eZvW+MyNzjRiOmmL8K/BRY0uqWeC1a3jC3bB59p4408YJqg=
X-Google-Smtp-Source: ABdhPJwCbzypuDJh4nZLUVz7KqJxFuyXQmaaK4mewngZ4eC7p/siSy02cLMJ90Unsyfy/jKJtBgvmTU6Dq1fAtiebcw=
X-Received: by 2002:a05:6830:169a:: with SMTP id
k26mr15905616otr.64.1639224562607;
Sat, 11 Dec 2021 04:09:22 -0800 (PST)
In-Reply-To: <CACaaUvH7OrFSzj3DUcGOO+swtLDAG9ijCDTLOJduHxFs+ZBm7g@mail.gmail.com>
X-Mailman-Approved-At: Sat, 11 Dec 2021 12:15:04 -0500
X-Content-Filtered-By: Mailman/MimeDel 2.1.38
X-BeenThere: python-list@python.org
X-Mailman-Version: 2.1.38
Precedence: list
List-Id: General discussion list for the Python programming language
<python-list.python.org>
List-Unsubscribe: <https://mail.python.org/mailman/options/python-list>,
<mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive: <https://mail.python.org/pipermail/python-list/>
List-Post: <mailto:python-list@python.org>
List-Help: <mailto:python-list-request@python.org?subject=help>
List-Subscribe: <https://mail.python.org/mailman/listinfo/python-list>,
<mailto:python-list-request@python.org?subject=subscribe>
X-Mailman-Original-Message-ID: <CACaaUvH0ZOUx8xo6Ms_-8ekhKTfiw-YKZzkZVUcM4Whcj=PX=g@mail.gmail.com>
X-Mailman-Original-References: <CACaaUvH7OrFSzj3DUcGOO+swtLDAG9ijCDTLOJduHxFs+ZBm7g@mail.gmail.com>
 by: Souvik Ghosh - Sat, 11 Dec 2021 12:09 UTC

*Resending this message after subscribing in python-mail-list*

---------- Forwarded message ---------
From: Souvik Ghosh <souvikghosh872@gmail.com>
Date: Sat, Dec 11, 2021 at 5:10 PM
Subject: I/O bound threads got to no chance to run with small CPU bound
threads with new GIL
To: <python-list@python.org>

Hello PSF,

I'm Souvik Ghosh from India. I've been coding for Python for almost 5
years now. And, I love Python and care about it so much.

The issue is stated below,

According to David Beazley' talk in PyCon'2010 in Atlanta Georgia, he
demonstrated about a new GIL with running CPU bound and I/O bound
threads together.

He said the talk that the threads which are forced to timeout of 5ms,
will have the lower priority(which is CPU bound) and the thread which
suspends the GIL within 5ms will have higher priority (which is I/O
bound).

What happens in the following code is if I set args=(10000000,) (seven
zero after 1) then only I/O bound runs and returns when CPU bound
takes much time to execute. But if I decrease that args to
args=(1000,) then I/O bound got no chance to reaquire the GIL in the
meantime even though the sys.getswitchinterval() is equal to 5ms(By
default). If I/O bound doesn't reacquire GIL with args=(10000,) then
the time to execute to run
only the CPU bound takes 0.42777760000035414 seconds. Thats means
almost ticks 0.42777760000035414/0.005=85 (approx) times to set the
priority in between the two threads. In that case if the I/O got more
priority within that time, it should have returned the value within
that ticks. But I didn't happen.
import threading
from queue import Queue
from timeit import default_timer as timer
import urllib.request

q = Queue() # Queue technique to pass returns among threads while running

def decrement(numbers): # CPU bound
while numbers > 0:
numbers -= 1
if not q.empty():
"""I added this method because this thread will run most of the time
because it's mostly cpu bound"""
print(numbers)
print(q.get(block=False))
print(timer() - start) # It tell after when exactly I/O
bound returns value after both the threads started to run

def get_data(): # I/O bound

with urllib.request.urlopen("https://www.google.com") as dt:
q.put(dt.read(), block=False)

if __name__ == "__main__":
start = timer()
t1 = threading.Thread(target=get_data)
#t2 = threading.Thread(target=decrement, args=(10000000,)) #For
this I/O responds and returns
t2 = threading.Thread(target=decrement, args=(100000,)) # I/O
doesn't responds at all
t1.start()
t2.start()

t1.join()
t2.join()
print(timer() - start)

Look at the second code...

import threading
from queue import Queue
from timeit import default_timer as timer
import urllib.request
import sys

q = Queue() # Queue technique to pass returns among threads while running

def decrement(numbers): # CPU bound
while numbers > 0:
numbers -= 1
if not q.empty():
"""I added this method because this thread will run most of the time
because it's mostly cpu bound"""
print(numbers)
print(q.get(block=False))
print(timer() - start) # It tell after when exactly I/O
bound returns value after both the threads started to run

def get_data(): # I/O bound

with urllib.request.urlopen("https://www.google.com") as dt:
q.put(dt.read(), block=False)

if __name__ == "__main__":
sys.setswitchinterval(0.0000000000000000000000000001)
start = timer()
t1 = threading.Thread(target=get_data)
#t2 = threading.Thread(target=decrement, args=(1000000,)) #I/O
responds with this
t2 = threading.Thread(target=decrement, args=(10000,)) # I/O
doesn't responds at all even with this 0.0000000000000000000000000001
seconds of threads switching interval
t1.start()
t2.start()

t1.join()
t2.join()
print(timer() - start)

Can't we have a more better version of GIL to set I/O threads(overall)
priorities even more better and not to degrade the CPU bound and
better callbacks in response? Or, try to remove the GIL?

The issue I submitted in here:- https://bugs.python.org/issue46046

Thank you so much, great future of Python!

1
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor