Performance and Scalability (Chapter 11) Performance and - - PowerPoint PPT Presentation

performance and scalability
SMART_READER_LITE
LIVE PREVIEW

Performance and Scalability (Chapter 11) Performance and - - PowerPoint PPT Presentation

Performance and Scalability (Chapter 11) Performance and Scalability Performance: How long is the latency? Scalability: Do we get higher throughput if we add more resources? Performance and Scalability Performance: How long is the


slide-1
SLIDE 1

Performance and Scalability

(Chapter 11)

slide-2
SLIDE 2

Performance and Scalability

  • Performance: How long is the latency?
  • Scalability: Do we get higher throughput if

we add more resources?

slide-3
SLIDE 3

Performance and Scalability

  • Performance: How long is the latency?
  • Scalability: Do we get higher throughput if

we add more resources?

versus

slide-4
SLIDE 4

Performance and Scalability

  • Performance: How long is the latency?
  • Scalability: Do we get higher throughput if

we add more resources?

versus

CPUs memory storage I/O bandwidth

slide-5
SLIDE 5

How does it scale?

Amdahl’s law

0x 2x 4x 6x 8x 10x 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16

Serial fraction

5 % 10 % 15 %

maximum speedup number of resources

slide-6
SLIDE 6
  • Amdahl’s law shows that serial execution

harms scalability.

  • Locks guarantee serial access.
  • Contended locking harms scalability.
  • How can we reduce lock contention?
slide-7
SLIDE 7

Reducing Lock Contention

  • Narrowing lock scope
  • Reducing lock granularity
  • Lock splitting
  • Lock striping
  • Alternatives to exclusive locks
slide-8
SLIDE 8

Reducing Lock Contention

Narrowing lock scope

@ThreadSafe public class AttributeStore { @GuardedBy("this") private final Map<String, String> attributes = new HashMap<String, String>(); public synchronized boolean userLocationMatches( String name, String regexp) { String key = "users." + name + ".location"; String location = attributes.get(key); if (location == null) return false; else return Pattern.matches(regexp, location); } }

slide-9
SLIDE 9

Reducing Lock Contention

Narrowing lock scope

@ThreadSafe public class AttributeStore { @GuardedBy("this") private final Map<String, String> attributes = new HashMap<String, String>(); public boolean userLocationMatches( String name, String regexp) { String key = "users." + name + ".location"; synchronized (this) { String location = attributes.get(key); } if (location == null) return false; else return Pattern.matches(regexp, location); } }

slide-10
SLIDE 10

Reducing Lock Contention

Reducing lock granularity

@ThreadSafe public class ServerStatus { @GuardedBy("this") public final Set<String> users; @GuardedBy("this") public final Set<String> queries; ... public synchronized void addUser(String u) { users.add(u); } public synchronized void addQuery(String q) { queries.add(q); } public synchronized void removeUser(String u) { users.remove(u); } public synchronized void removeQuery(String q) { queries.remove(q); } }

i n d e p e n d e n t

slide-11
SLIDE 11

Reducing Lock Contention

Reducing lock granularity

@ThreadSafe public class ServerStatus { @GuardedBy("users") public final Set<String> users; @GuardedBy("queries") public final Set<String> queries; ... public void addUser(String u) { synchronized (users) { users.add(u); } } public void addQuery(String q) { synchronized (queries) { queries.add(q); } } // removeUser and removeQuery similarly refactored }

i n d e p e n d e n t

slide-12
SLIDE 12

Reducing Lock Contention

Reducing lock granularity

a = 4 x = –2 b = 0 m = 3 r = 11 z = 7 p = 4

slide-13
SLIDE 13

Reducing Lock Contention

Alternatives to exclusive locks

  • Immutable objects (ch. 3)
  • Concurrent collections (ch. 5)
  • Read-write locks (ch. 13)
  • Atomic variables (ch. 15)
slide-14
SLIDE 14

When should we do this?

NEVER!!!

(Unless your program does not fulfill the performance requirements)

slide-15
SLIDE 15

If the program does not fulfill the performance requirements…

Where should we start?

MEASURE!!!

(To find the bottle neck)

slide-16
SLIDE 16

Thank you

slide-17
SLIDE 17

Exercise

Coming soon…