how do developers use parallel libraries? semih okur & danny dig university of illinois at...

47
How do developers use parallel Libraries? Semih Okur & Danny Dig University of Illinois at Urbana-Champaign

Upload: lynn-randall

Post on 11-Jan-2016

214 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: How do developers use parallel Libraries? Semih Okur & Danny Dig University of Illinois at Urbana- Champaign

How do developers use parallel Libraries?

Semih Okur & Danny Dig

University of Illinois at Urbana-Champaign

Page 2: How do developers use parallel Libraries? Semih Okur & Danny Dig University of Illinois at Urbana- Champaign

2 Why

Parallel HARDWARE is Everywhere NOW

2004

Page 3: How do developers use parallel Libraries? Semih Okur & Danny Dig University of Illinois at Urbana- Champaign

3 Why

Parallel programming is hard

[From “The Practice of Parallel Programming” book cover]

• Requires balancing two

conflicting forces

(1) Thread-safe

(2) Scalable

• Makes the code more

complex

Page 4: How do developers use parallel Libraries? Semih Okur & Danny Dig University of Illinois at Urbana- Champaign

4 Why

parallel libraries are widespread

PPL & ConcRTjava.util.concurr

ent

Page 5: How do developers use parallel Libraries? Semih Okur & Danny Dig University of Illinois at Urbana- Champaign

5 Why

which parallel libraries are you most familiar with?

A) OpenMP for C/C++

B) Intel TBB for C/C++

C) java.util.concurrent package for

Java

D) Microsoft Parallel Libraries for C#

E) None of them

Page 6: How do developers use parallel Libraries? Semih Okur & Danny Dig University of Illinois at Urbana- Champaign

6 Why

We know nothing about how developers use these libraries

No empirical study on a large-

scale so far

4 different communities strongly need

such a study

Page 7: How do developers use parallel Libraries? Semih Okur & Danny Dig University of Illinois at Urbana- Champaign

7 Why

DevelopersWithout such a study

Page 8: How do developers use parallel Libraries? Semih Okur & Danny Dig University of Illinois at Urbana- Champaign

8 Why

Miss educational resources

Cannot decide whether to invest time to learn API

DevelopersWithout such a study

Page 9: How do developers use parallel Libraries? Semih Okur & Danny Dig University of Illinois at Urbana- Champaign

9 Why

Page 10: How do developers use parallel Libraries? Semih Okur & Danny Dig University of Illinois at Urbana- Champaign

10 Why

Researchers

Miss educational resources

Cannot decide whether to invest time to learn API

DevelopersWithout such a study

Page 11: How do developers use parallel Libraries? Semih Okur & Danny Dig University of Illinois at Urbana- Champaign

11 Why

Make wrong assumptions

Researchers

Miss educational resources

Cannot decide whether to invest time to learn API

DevelopersWithout such a study

Page 12: How do developers use parallel Libraries? Semih Okur & Danny Dig University of Illinois at Urbana- Champaign

12 Why

Library Designers

Stephen Toub

Make wrong assumptions

Researchers

Cannot decide whether to invest time to learn API

DevelopersWithout such a study

Miss educational resources

Page 13: How do developers use parallel Libraries? Semih Okur & Danny Dig University of Illinois at Urbana- Champaign

13 Why

In danger of designing error-prone, hard to use APIs

Library Designers

Make wrong assumptions

Researchers

Cannot decide whether to invest time to learn API

DevelopersWithout such a study

Miss educational resources

Page 14: How do developers use parallel Libraries? Semih Okur & Danny Dig University of Illinois at Urbana- Champaign

14 Why

Tool Vendors

In danger of designing error-prone, hard to use APIs

Library Designers

Make wrong assumptions

Researchers

Cannot decide whether to invest time to learn API

DevelopersWithout such a study

Miss educational resources

Page 15: How do developers use parallel Libraries? Semih Okur & Danny Dig University of Illinois at Urbana- Champaign

15 Why

Don’t know what to automate

Tool Vendors

In danger of designing error-prone, hard to use APIs

Library Designers

Make wrong assumptions

Researchers

Cannot decide whether to invest time to learn API

DevelopersWithout such a study

Miss educational resources

Page 16: How do developers use parallel Libraries? Semih Okur & Danny Dig University of Illinois at Urbana- Champaign

16 Why

Are developers embracing multi-threading?How quickly do developers start using the newly released parallel libraries? Which parallel constructs do developers use most often?

How do developers protect accesses to shared variables?

Which parallel patterns do developers embrace?

Which advanced features do developers use?

Do developers make their parallel code unnecessarily complex? Are there constructs that developers commonly mis-use?

Page 17: How do developers use parallel Libraries? Semih Okur & Danny Dig University of Illinois at Urbana- Champaign

17 Why

Are developers embracing multi-threading?How quickly do developers start using the newly released parallel libraries? Which parallel constructs do developers use most often?

How do developers protect accesses to shared variables?

Which parallel patterns do developers embrace?

Which advanced features do developers use?

Do developers make their parallel code unnecessarily complex? Are there constructs that developers commonly mis-use?

Page 18: How do developers use parallel Libraries? Semih Okur & Danny Dig University of Illinois at Urbana- Champaign

18

•Why C#

•What is our data?

•How do we gather information from the data?

How

Why

Page 19: How do developers use parallel Libraries? Semih Okur & Danny Dig University of Illinois at Urbana- Champaign

19 How

Rising trend: C# parallel

Page 20: How do developers use parallel Libraries? Semih Okur & Danny Dig University of Illinois at Urbana- Champaign

20 Why

which one does not belong to C# parallel

libraries?

A) Concurrent Collections

B) Task Parallel Library (TPL)

C) Threading

D) Parallel Patterns Library (PPL)

E) Plinq

Page 21: How do developers use parallel Libraries? Semih Okur & Danny Dig University of Illinois at Urbana- Champaign

21 How

C# Parallel api2010

.NET 4.0 is released

Collections.ConcurrentPLINQTPL

2002

.NET 1.0 is released

Threading

OldNew

Page 22: How do developers use parallel Libraries? Semih Okur & Danny Dig University of Illinois at Urbana- Champaign

22 How

corpus of data

• Downloaded all C# projects as of January 31, 2012.

Filters:1.Discarded toy applications (less than 1000 non-

comment SLOC)

• Compilable and targeting .NET 4.0

• After all, got 7778 applications

Page 23: How do developers use parallel Libraries? Semih Okur & Danny Dig University of Illinois at Urbana- Champaign

23 How

corpus of dataSize According to SLOC

=>

Small(1K-10K)

Medium(10K-100K)

Large(>100K

)Total

Multi-threaded Applications

1761 916 178 2855Focused on the apps adopted new parallel libraries: TPL & PLINQ

655 applications = 17.6M SLOC by1609 programmers

# Apps in Colored Area: 655

Page 24: How do developers use parallel Libraries? Semih Okur & Danny Dig University of Illinois at Urbana- Champaign

24 How

AUTOMATED STATIC analysisbased on Microsoft Roslyn Project

•syntactic (lexical) analysis: traversing AST nodes used Syntax API of Roslyn

•semantic analysis: get type and object binding information used Symbol and Binding APIs of Roslyn

Collected the usage details for each construct in 4 libraries patterns based on heuristics

Page 25: How do developers use parallel Libraries? Semih Okur & Danny Dig University of Illinois at Urbana- Champaign

25

Present the results for 3 of our 8 research questions

Why

What

How

Page 26: How do developers use parallel Libraries? Semih Okur & Danny Dig University of Illinois at Urbana- Champaign

26 What

Rq1: Are developers embracing multi-threading?

Should we learn how to use parallel libraries, or should we avoid them because they are a passing fad?

We built multicores but do developers exploit parallelism?

Page 27: How do developers use parallel Libraries? Semih Okur & Danny Dig University of Illinois at Urbana- Champaign

27 What

Rq1: Are developers embracing multi-threading?

SmallMediu

mLarge Total

Applications compilable and targeting .NET 4.0

6020 1553 205 7778

Multi-threaded Applications

1761 916 178 2855

37%87%

Page 28: How do developers use parallel Libraries? Semih Okur & Danny Dig University of Illinois at Urbana- Champaign

28 What

39% 74%13%

RQ1: HOW MANY APPS USE PARALLELISM VS CONCURRENCY?

Concurrency

FromAsync, TaskCompletion- Source, UI event dispatching thread

Parent thread does not wait for worker threads

Parallelism

Parallel.For, PLINQ constructs

Parent thread forks worker threads and waits for them to finish

Page 29: How do developers use parallel Libraries? Semih Okur & Danny Dig University of Illinois at Urbana- Champaign

29 What

Many applications have embraced multi-threading, however many of them use

it for concurrency rather than parallelism.

RQ1: ARE DEVELOPERS EMBRACING MULTI-THREADING?

• Developers will not be able to avoid multi-threaded programming for much longer

• Intel should be happy. Developers are taking advantage of multicores

Page 30: How do developers use parallel Libraries? Semih Okur & Danny Dig University of Illinois at Urbana- Champaign

30 What

RQ7: Do developers make their parallel code

unnecessarily complex? Parallel code is much more complex than sequential code.

Why is my parallel code so complex?

Can we simplify the parallel code?

Page 31: How do developers use parallel Libraries? Semih Okur & Danny Dig University of Illinois at Urbana- Champaign

31 What

RQ7: Do developers make their parallel code unnecessarily complex?

for (int i = 1; i <= threadCount; i++) { var copy = i; var taskHandle = Task.Factory.StartNew( () => DoInsert(...));tasks.Add(taskHandle);}Task.WaitAll(tasks);

Parallel.For(1,threadCount,(i)=>DoInsert(..))

29% of all cases creating tasks in loop could have used Parallel.For or Parallel.ForEach

“ravendb” [github.com/ravendb/ravendb]

Page 32: How do developers use parallel Libraries? Semih Okur & Danny Dig University of Illinois at Urbana- Champaign

32 What

RQ7: Do developers make their parallel code unnecessarily complex?

•Refactorings to improve the readability of parallel code are desperately needed

Despite the fact that parallel programs are

already complex, developers make them

even more complex than they need to be.

Page 33: How do developers use parallel Libraries? Semih Okur & Danny Dig University of Illinois at Urbana- Champaign

33 What

RQ8: Are there constructs that developers commonly

misuse?

Why does not my code get any speedup with parallel constructs?

What are these constructs that developers misuse?

Page 34: How do developers use parallel Libraries? Semih Okur & Danny Dig University of Illinois at Urbana- Champaign

34 What

Q8: Are there constructs that developers commonly misuse?

Page 35: How do developers use parallel Libraries? Semih Okur & Danny Dig University of Illinois at Urbana- Champaign

35 What

RQ8: Are there constructs that developers commonly

misuse?

Why does not my code get any speedup with parallel constructs?

Which constructs do developers misuse?

Page 36: How do developers use parallel Libraries? Semih Okur & Danny Dig University of Illinois at Urbana- Champaign

36 What

RQ8: Are there constructs that developers commonly misuse?

assembly.GetTypes().AsParallel(). Where(t => t.IsSubclassOf(...)). ForAll(t => controllersCache.Add(...));

AsParallel() from PLINQ

Corre

ct

Page 37: How do developers use parallel Libraries? Semih Okur & Danny Dig University of Illinois at Urbana- Champaign

37 What

RQ8: Are there constructs that developers commonly misuse?

foreach (var module in Modules.AsParallel()) module.Refresh();

• The foreach proceeds sequentially.

• 12% of all AsParallel usages are incorrect

Inco

rrec

t

“profit” [profit.codeplex.com]

Page 38: How do developers use parallel Libraries? Semih Okur & Danny Dig University of Illinois at Urbana- Champaign

38 What

RQ8: Are there constructs that developers commonly misuse?

Misuse of parallel constructs can lead to code

with parallel syntax but sequential execution.

Page 39: How do developers use parallel Libraries? Semih Okur & Danny Dig University of Illinois at Urbana- Champaign

39 So What

so what?

Page 40: How do developers use parallel Libraries? Semih Okur & Danny Dig University of Illinois at Urbana- Champaign

40 So What

Library designers

Learn how to make the APIs easier and less error-prone to

useConfirmed that our

suggestions are useful and will influence the future

development of the libraries

Page 41: How do developers use parallel Libraries? Semih Okur & Danny Dig University of Illinois at Urbana- Champaign

41 So What

Tool vendors & researchers

Focus on their efforts on widely (mis)used constructs

and patterns

Page 42: How do developers use parallel Libraries? Semih Okur & Danny Dig University of Illinois at Urbana- Champaign

42 So What

http://LearnParallelism.NET

FOR DEVELOPERS

3700 unique organic visitors from 88 different countries generates 20231 page views in 4 months

we created

Page 43: How do developers use parallel Libraries? Semih Okur & Danny Dig University of Illinois at Urbana- Champaign

43 So What

Page 44: How do developers use parallel Libraries? Semih Okur & Danny Dig University of Illinois at Urbana- Champaign

44 So What

Page 45: How do developers use parallel Libraries? Semih Okur & Danny Dig University of Illinois at Urbana- Champaign
Page 46: How do developers use parallel Libraries? Semih Okur & Danny Dig University of Illinois at Urbana- Champaign
Page 47: How do developers use parallel Libraries? Semih Okur & Danny Dig University of Illinois at Urbana- Champaign

47 So What

conclusion• First large-scale empirical study on the usage

of parallel librariesWe answered 8 research questions related to adoption, frequently (mis)used constructs, and patterns.

• Implications for • Developers: http://LearnParallelism.NET• Library Designers: awareness of API

problems• Researchers & Tool Vendors: know what to

automate