-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Closed
Labels
Description
From my understanding, Redis-py is mostly doing network IO under the hood. Python's GIL should not kick in for network IO. However, it looks like multithreading is as slow as single-threaded sequential version. Am I missing anything?
r = StrictRedis()
def test():
for i in range(10000):
key = 'mykey'+str(i)
r.set(key, 'ibvjaiuj65s4fa4sd8ear4')
r.get(key)
r.delete(key)
def bench1():
for _ in range(5):
test()
def bench2(): # as slow as bench 1
ts = [threading.Thread(target=test) for i in range(5)]
[t.start() for t in ts]
[t.join() for t in ts]
def bench3(): # much faster, which means GIL is in play
ts = [multiprocessing.Process(target=test) for i in range(5)]
[t.start() for t in ts]
[t.join() for t in ts]