performance and scalability
play

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


  1. Performance and Scalability (Chapter 11)

  2. Performance and Scalability • Performance: How long is the latency? • Scalability: Do we get higher throughput if we add more resources?

  3. Performance and Scalability • Performance: How long is the latency? versus • Scalability: Do we get higher throughput if we add more resources?

  4. Performance and Scalability • Performance: How long is the latency? versus • Scalability: Do we get higher throughput if we add more resources? storage I/O bandwidth CPUs memory

  5. Serial fraction How does it scale? 5 % Amdahl’s law 10 % 15 % 10x 8x maximum speedup 6x 4x 2x 0x 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 number of resources

  6. • Amdahl’s law shows that serial execution harms scalability. • Locks guarantee serial access. • Contended locking harms scalability. • How can we reduce lock contention?

  7. Reducing Lock Contention • Narrowing lock scope • Reducing lock granularity • Lock splitting • Lock striping • Alternatives to exclusive locks

  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); } }

  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); } }

  10. Reducing Lock Contention Reducing lock granularity i n d e @ThreadSafe p e n d e n public class ServerStatus { t @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); } }

  11. Reducing Lock Contention Reducing lock granularity i n d e @ThreadSafe p e n d e n public class ServerStatus { t @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 }

  12. Reducing Lock Contention Reducing lock granularity p = 4 a = 4 x = –2 b = 0 m = 3 r = 11 z = 7

  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)

  14. When should we do this? NEVER!!! (Unless your program does not fulfill the performance requirements)

  15. If the program does not fulfill the performance requirements… Where should we start? MEASURE!!! (To find the bottle neck)

  16. Thank you

  17. Exercise Coming soon…

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend