Concurrency
Upcoming SlideShare
Loading in...5
×
 

Concurrency

on

  • 385 views

 

Statistics

Views

Total Views
385
Views on SlideShare
382
Embed Views
3

Actions

Likes
0
Downloads
5
Comments
0

1 Embed 3

http://www.linkedin.com 3

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

Concurrency Concurrency Presentation Transcript

  • Parallel Processing A Simple Case StudyArchitecture and Design Series
  • Parallel Processing - What is it?•  Concurrent System –  Two or more actions progressing in parallel –  This can be on a single core•  Parallel System –  Two or more actions executing in parallel –  This requires multiple cores –  Parallel systems are a subset of concurrent systems•  Distributed System –  Two or more actions executing in parallel –  This requires multiple connected machines –  Communication is primarily via messaging http://sieac.blogspot.com/2012/08/terminologies-related-to-concurrent.html
  • Why application developers need to know?•  Multi-core processors•  Large volume of data•  Analytics and other new fields•  Cheaper hardware http://sieac.blogspot.com/2012/08/concurrency-and-why-application_20.html
  • OS Resource Challenges Memory Web DB NW (ROM/ NW Service RAM) DistribuQueue CPU ted Registers Mem Cache
  • Representation of an Application Source Data Transform Data Sink-  UI -  UI-  DB -  DB-  Queue -  Queue-  Network -  Network-  Service -  Service
  • Abstraction of Concurrancy•  Programs are execution of atomic statements•  Concurrent programs are the interleavings of atomic statements•  All possible interleavings should produce the same results•  No process should be excluded from any arbitrary interleaving http://sieac.blogspot.com/2012/08/criteria-that-need-to-be-satisfied-by.html
  • Challenges•  Race Conditions –  http://sieac.blogspot.com/2012/08/challenges-in-concurrent-programming-1.html•  Deadlocks –  http://sieac.blogspot.com/2012/08/challenges-in-concurrent-programming-2.html
  • To go Parallel?•  SpeedUp –  Amdahl’s Law •  Speedup <= 1/((1 – PCTpar) + (PCTpar/P)) –  PCTpar -> percentage of time in parallel –  P -> Number of cores •  75% PCTpar provides 3x speedup on a 8 core –  Gustafson-Barsis’s Law •  Speedup <= P + (1 – P) S –  P -> Number of cores –  S -> Percentage of time spend in serial code•  Efficiency –  Speedup/Cores -> resource utilization as %age http://sieac.blogspot.com/2012/08/stay-serial-or-go-concurrent.html
  • Things to Consider•  Identify independent computations•  Implement concurrancy at the highest level•  Make no assumptions on the cores•  Use the best processing model•  Never assume a particular execution order•  User thread local storage or associate locks to specific data•  Make no assumptions on the order of execution http://sieac.blogspot.com/2012/08/points-to-consider-when.html
  • Methedology•  Start with a tuned and functional serial code•  Analysis: identify possible concurrancy –  Identify hotspots probably using profilers•  Calculate speedup and efficiency•  Design and implementation•  Test for correctness –  Loop executions, rounding errors•  Tune for performance –  Enough work load to compensate for overheads•  Measure Speedup as a multiplier (e.g. 2x faster) –  Serial code elapsed time/parallel code elapsed time http://sieac.blogspot.com/2012/08/steps-to-design-and-develop-concurrent.html
  • Sample Process State Diagram Shared Variable
  • Highlights of Process Development•  Single threaded functional code (Java)•  Threads spawned off for each message –  Data decomposition –  Task decomposition –  Concurrency at the highest level•  Monitor (synchronize) & conditional variable•  Code to ignore deadlocks•  Tested and tuned to remove bottlenecks•  Scalable for any number of cores
  • Monitorpublic class Monitor { private synchronized void decCount () {private static int count = 0; count--; }private static int max = 0; public synchronized void acquire() {public boolean isSemaphoreUsed() try { { while (count == 0) { return (count < max); } Never comes} decCount(); outpublic Semaphore(int num) { } count = num; public synchronized void release() max = num; {} incCount();private synchronized void } incCount() { } count++;}
  • Monitor with Conditional Variablespublic class Monitor { private synchronized void decCount () {private static int count = 0; count--; }private static int max = 0; public synchronized void acquire() {public boolean isSemaphoreUsed() try { { while (count == 0) { return (count < max); this.wait();} }public Semaphore(int num) { decCount(); count = num; } catch (InterruptedException e) max = num; {}} }private synchronized void public synchronized void release() incCount() { { count++; incCount(); this.notify();} } }
  • General Design Guidelines•  Keep it simple stupid (KISS) –  Break the problem into simple components•  Keep the number of layers to minimum –  Don’t add layers since they are hot in industry•  Do the right thing –  Skeptics will provide scenarios to take care
  • Questions?Feedback: bijunair at acm dot org