150 likes | 251 Views
Performance Pitfalls . Paul Lockwood. About the Presenter. Über -geek First computer in 1981 First fulltime IT job in 1989 Clipper/Dbase IV, PowerBuilder, Java, C# Contracted most of career Lived/ worked in four different countries Vast exposure to different approaches
E N D
Performance Pitfalls Paul Lockwood
About the Presenter • Über-geek • First computer in 1981 • First fulltime IT job in 1989 • Clipper/Dbase IV, PowerBuilder, Java, C# • Contracted most of career • Lived/ worked in four different countries • Vast exposure to different approaches • Stand on Shoulders of Giants
Causes are Well Known • Memory Issues • Mainly leaks, sometimes churn/ GC issues • I/O • Disk, network • 100% CPU • Runaway threads • Bad SQL, very poor DB Design • Blocking lock around cache reads • Knock on effect of spin-waits, waiting on I/O
Performance Basics • Orders of Magnitude • Services are thousands, even millions of times slower • Architecture can guarantee poor performance • Typical Tuners think in milliseconds • We Look for Big Mistakes • Generally Ignore: • Value/reference boxing • Static method vs v-table lookup • Most marshaling • Hash lookups • Concatenating strings
Removing Guesswork 1ns is one CPU Cycle on a 1Ghz Processor
Architectural Mistakes • Overuse of SOA, DI/IoC, Reflection etc • ~100ms per SOA call is typical • All are difficult to debug • Layer and compile-in often the best choice • Homegrown Frameworks • Since 2000s these mostly fail • Architect’s continued control prevents rescue • Buzzword/Resume Driven Architectures
Demos #1 JMeter to load test IDE to attach, pause and view all threads
Demos #2 • WinDbg – Analyzing a Production Dump • Screen Captures from Real World Tuning
Personal Quick Wins • Find/ Remove Memory Leaks • Static HashTable is classic example • Remove .Net Exceptions used in Logic • Remove unnecessary Locking • Even saw a Logging Sink with contentions! • ReaderWriterLocks are easy fixes • Short circuit SOA/ Web Service calls • SQL Tuning, even just adding Indexes! • Very chatty SQL calls -> pure Server or pure client • ‘Real OOP’ Code -> Trivial SQL Code • Stop Log.Debug writing to Database • Cache Lookup data (lazy load Singleton with IDispose) • Consider Implementing ‘Clear Cache Page’
More Difficult Fixes • Complex sprocvs 10klocs of C#/Java code • Automated Developer Tests essential with complexity • SQL Optimization • Hints, really understand data, rewrite sprocs.. • 3-Tier Library total re-write • Fought Architecture Team in a multinational • Native Memory Leak • Very hard to reproduce caching issue • Advice from others totally misleading • IISDiag confirmed the leak, then JMeterisolated • Code Simplifications • Hard coded logic -> Table driven methods • XMLDocument parsing -> xsd.exe/ XmlBeans
Locating the Problem • Existing Excuses • Only happens in live Environments • We have special hardware • Cannot reproduce traffic • Problem Domain is insanely complex • Hardware is not good enough, need 64Gb etc • Test machine • Replicate live data if possible • CPU Horsepower is not really important • IDE useful to compile/ debug • Exclusive access to database, test hardware!! • Taking Dumps (Not Recommended) • WinDbg, sos.dll, adplus, IISDiag (auto scripts) etc • Like CSI, it’s a snapshot in time • Total experts only – sole job function perhaps?
Final Slide • Feedback is much appreciated • DotNetWorkaholic.com
N-Tier/ Distributed Objects - The Mysterious Allure of distributing objects “Objects have been around for a while, and sometimes it seems that ever since they were created, folks have wanted to distribute them. However, distribution of objects, or indeed of anything else, has a lot more pitfalls than many people realize, especially when they’re under the influence of vendors’ cozy brochures.” Martin Fowler (2002) • Distributing Objects: • Increases Expense • Increases Complexity • Reduces Performance
Scalability • Look at Performance first • Scalability seems easier/ sexier • Product X, Y or Z won’t Scale! Really? • Use common sense; ask why not • Any ORM should scale: tune/cache the hot paths • DataBasewrites are an ideal Bottleneck • Most apps are mostly reads, few writes. i.e. Cache for reads • Async audit/ analytics tracking to other servers • Horizontal vs Vertical scaling • How many people have ten to fifteen web/app servers in production? • Major Enemies • Session State • Pessimization (Pessimistic Optimization) • Insane Architects :)