Java multithreading - 6 threads or 30 threads? -
this question has answer here:
- optimal number of threads per core 12 answers
i'm working on multithreaded application needs perform optical character recognition. requirement of app must work really, fast.
at 1 time, have simultaneously read 6 different words. i'm doing is, starting 6 threads, 1 thread dedicated reading each word.
however, i'm wondering if should go further, , start 1 thread each character within word. e.g, if have 6 words , each word has 5-6 characters, mean 30-36 threads (possibly upto 50-70 threads longer words).
to process each individual character, seems take between 10-30 milliseconds, total of 200-300 milliseconds per word. (i need bring down 100 milliseconds or less per word).
which strategy give me better performance? 1 thread per word, or 1 thread per character?
which strategy give me better performance? 1 thread per word, or 1 thread per character?
the answer highly dependent on hardware architecture , processing being done. processing completely cpu bound or there logging or other io? best way answer performance runs trying various different thread settings number of trials see 1 better. accurate results, test runs should longer couple of seconds rule out jit , other java initialization.
couple other thoughts:
as mentioned @sotirios , others, throwing more threads @ problem may run slower because of context switching overhead.
you should use
executorservicethread-pool not forking , reaping threads every time. thread startup/shutdown not insignificant process.
Comments
Post a Comment