python - multithreading performance issue -
possible duplicate: multithreading performance overhead
i have piece of code run slower on multithread , faster while using 1 thread.
output 1 thread:
batch 0 finished in 0.0970576110595 batch 1 finished in 0.712632355587 batch 2 finished in 2.16707853982 batch 3 finished in 5.13259954359 batch 4 finished in 9.54205263734 total running time approx 17second
output using multi-thread
thread 0 finished in 60.4911733611 thread 1 finished in 62.5297083217 thread 2 finished in 65.5614617838 thread 3 finished in 66.8199233683 thread 4 finished in 66.8426577103 total running time 66 second.
what being done in each process take 100 lines of text, split tokens, remove stopwords , generate patterns using algorithm, have experience or ways me identify went wrong?
@mac's answer covers why, we'll need of code give more help. may want try, use multiprocessing instead of threading, have data access issues...
threading in python on non-blocking io you have 1 active thread per python process.
multiprocessing useful making use of cores, start have worry locks , race conditions , else.
Comments
Post a Comment