java - Consequences of creating a large fixed thread pool -


i'm working on standard server application. processing of each request broken down several stages (the second stage requires first finished, , on). now, 1 of these stages takes rather long time can broken down several dozen or tasks, not depend on each other, , hence parallelizable. add thread pool slowstageservice, , wondering how best size it. best thread pool have @ least 1 vacancy of time, implies must process tasks fast or faster server receiving requests; yields reasonable lower bound on size of thread pool. however, generous sizing, since many of numbers involved in calculation change.

so question is: downside of making pool large (say factor of 3 or 4), , having many idle threads? understand wastes resources, doesn't reserve cpu , make thereby unavailable other requests, right? how slack in practice 1 can have? i've calculated 6 threads minimum need; safe go 12 on 24-core box under medium load?

as i'm writing this, sounds maybe need threadpoolexecutor narrow (3 or 4x) range?

you should refer section 8.2 book java concurrency in practice brian goetz.

if stages compute intensive stages , have little i/o optimal size of threadpool = number of cpu cores + 1 (so in case 25). if there i/o bound tasks within stages best applicable size threadpool achieve optimum response times depends on various factors :

  1. number of cpus - n
  2. target utilization of cpu - uc
  3. the ratio of wait time (blocking state) i/o operations (w) compute time (c).

num_threads = n * uc * (1+(w/c))

in addition above metrics other factors affect calculation of pool size memory requirements, size of connection pools, file handles , socket handles.

given above theory behind sizing threadpools; experience suggests best way come optimal pool size profiling application @ various work loads , come pool sizes light, medium , heavy workload sizes.

also, never ever hard-code max threadpool size - should configurable parameter can adjusted in field per workloads encountered.


Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -