Skip to content

Slow multithreading #928

@DrJimFan

Description

@DrJimFan

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]

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions