1 / 8

CSC 480 - Multiprocessor Programming, Spring, 2012

CSC 480 - Multiprocessor Programming, Spring, 2012. Chapter 8 – Applying Thread Pools Dr. Dale E. Parson, week 10. Types of tasks requiring specific execution policies. Dependent tasks

trella
Télécharger la présentation

CSC 480 - Multiprocessor Programming, Spring, 2012

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CSC 480 - Multiprocessor Programming, Spring, 2012 Chapter 8 – Applying Thread Pools Dr. Dale E. Parson, week 10

  2. Types of tasks requiring specific execution policies • Dependent tasks • Interacting tasks require more careful execution management than independent tasks. The Executor must manage their interaction dynamics. • Tasks that exploit thread confinement may require a single-threaded Executor. • Response-time-sensitive tasks require sufficient parallelism for responsiveness. • Current latency-driven assignment. • ThreadLocal should not be used in pool threads to communicate values between tasks.

  3. Thread Starvation Deadlock • Executing interdependent tasks in an Executor may lead to thread starvation deadlock if the Executor schedules tasks in a way that causes waits on tasks that never run. • Long running tasks can cause responsiveness problems for thread pools. • Sizing thread pools Nthreads = Ncpu x Ucpu * (1 + W / C) where Ncpu is number of CPUs, Ucpu is target CPU utilization, 0 <= Ucpu <= 1 W / C is ratio of wait time to compute time

  4. Configuring ThreadPoolExecutor • ThreadPoolExecutor is the base implementation for cached thread pool, fixed thread pool, and scheduled executor. • It supports configuration of core and max pool sizes, keep alive time, a work queue, a thread factory, and a rejected execution handler. • Creating and maintaining a custom Executor is complicated.

  5. ThreadPoolExecutor Heuristics • LinkedBlockQueue is the default. It does not throttle back the task submitter(s). • A bounded queue throttles back submitters. A large bounded queue coupled with a small thread pool reduces memory usage, CPU usage and context switching, potentially at the cost of throughput. • Use a Semaphore to throttle submitter threads. • For large or unbounded pools SyncronousQueue is an option. It is practical only if the pool is effectively unbounded or if rejecting excess tasks is acceptable. • Bounding the thread pool or work queue is suitable only when tasks are independent.

  6. Saturation Policies • Full bounded work queue == saturation. • Abort policy causes execute to throw unchecked RejectedExecutionException. • Caller-runs policy borrows the submitting thread instead of using a pool thread. • Discard policy silently discards submissions. • Discard oldest policy silently discards the oldest waiting submission, retries execute.

  7. ThreadFactory and Thread subclasses • Custom Thread subclass with extensions. • Build an UncaughtExceptionHandler. • Debug logging. Set up custom ThreadLocal data. • ThreadPoolExecutor can be customized after construction. • It can be subclassed to extend beforeExecute and afterExecute to add logging, timing, monitoring or statistics gathering.

  8. Parallelizing recursive algorithms • See examples from Summer 2010 handout. • Loop parallelization. void processSequentially(List<Element> elements) { for (Element e : elements) process(e); } void processInParallel(Executor exec, List<Element> elements) { for (final Element e : elements) exec.execute(new Runnable() { public void run() { process(e); } }); }

More Related