SlideShare a Scribd company logo
Developing B2 for
Performance and Scalability
               Noriaki Tatsumi
                Kevin Weisser
Why Performance Matters?


• User experience
  – Your users don’t like slow and unresponsive apps
  – Slow applications lose users in frustrations
  – Users tend to wander off beyond captive response
    time of 7 – 10 seconds
• User adoption
  – Google saw 25% decline in searches within 6
    weeks after introducing 0.5s delay (~$2.5B loss)
  – Wikia observed up to 20% user loss as the page
    load time reached 5 seconds
Wikia – Exit rate (abandon)
http://assets.en.oreilly.com/1/event/27/Varnish%20-%20A%20State%20of%20the%20Art%20High-Performance%20Reverse%20Proxy%20Presentation.pdf
“With great power comes great
      responsibility” – Uncle Ben, Spiderman
• Reputations at stake
• System resources are shared and limited
• B2s with scalability problem impacts system
  performance
  – System-wide performance degradation
  – Server downtime
What is an anti-pattern?


• Some repeated pattern of action, process or
  structure that initially appears to be beneficial,
  but ultimately produces more bad consequences
  than beneficial results
• A refactored solution exists that is clearly
  documented, proven in actual practice and
  repeatable.

  - Definition from Wikipedia
How can anti-patterns help?


• Prevents performance as an afterthought
• Helps identify performance issues that typically
  don’t arise until deployed in production
• Prevents pre-mature optimizations
How do I use anti-patterns?


• Identify and correct the occurrences of anti-
  patterns during:
  –   Design review
  –   Implementation/code review
  –   Execution of experiments and profiling
  –   Static code analysis
Top 10 violated high-level performance
anti-patterns fixed in Blackboard Learn™
      Inefficient Filtering


  Unnecessary Processing


               The Ramp


         Data Overreach

                                                     Frequency (%)
Unlimited Resource Usage


          Functional Bug


    Excessive Granularity


             More is Less

 Usage of Outdated Tools
        and APIs

 Mishandled Concurrency


                              0   5   10   15   20                   25   30
Top 10 violated low-level performance
anti-patterns fixed in Blackboard Learn™
                  Missing or non-optimal index [db]


                Inefficient or erroneous criteria [db]


                   Unnecessary data retrieval [app}


                 Too many objects in memory [app}


               Presentation of unlimited results [ui]

                                                                           Frequency (%)
                          Inefficient access path [ui]


                              No data caching [app}


Not releasing resource (immediately) after use [app}


          Incompatiblity with HA deployment [app}


                      Excessive DB round trips [app}


                                                         0   5   10   15                   20   25
Most violated high-level anti-pattern
         #1: Inefficient Filtering
• Description
  – Querying data using inefficient logic, algorithm, or
    technique
• Problem
  – Consumes resources that can be used by other
    processes
  – Increases execution/response time
• Solution
  – Store data in both centralized and organized manner
  – Search against smaller data set first, fail fast, and don’t
    look at unnecessary data
  – Leverage indexing and other efficient
    techniques/algorithms
Most violated high-level anti-pattern
          #1: Inefficient Filtering
Missing or non-optimal index (DB)
• Most violated low-level anti-pattern
• Problem
   – Missing appropriate index on search columns leads to
     inefficient data retrieval operation by SQL query optimizer
   – Having index can inversely add unnecessary overhead if the
     column is never used for searched criteria
• Solution
   – Analyze SQL execution plan to verify usage of proper index
   – Create index on foreign keys
   – Create unique index on unique columns
   – Use an index to eliminate unnecessary full-table or index
     scans to access small percentage of data on a large table
   – Use covering index for key lookup
Creating Database Objects with B2


• Release 9.1 SP1 and above
  – B2s authored by independent developers can now
    define and install schema elements
• Not enabled by default
  – Administrators must enable this functionality from
    the B2 management section of the admin panel
• Documentation
  – http://www.edugarage.com/display/BBDN/Creating+
    Database+Objects+with+Building+Blocks
Most violated high-level anti-pattern
          #1: Inefficient Filtering
Inefficient or erroneous criteria (DB)
• The second most violated low-level anti-pattern
• Problem
   – Duplicate, unnecessary, incorrect, or missing predicate
     checks and joins exist in SQL
   – Increases response time, system resource consumption, and
     locking
• Solution
   –   Be specific on what data you need
   –   Keep it simple and avoid unnecessary checks
   –   Use JOIN criteria that aligns with index
   –   Analyze execution plan to derive efficient and balanced query
Most violated high-level anti-pattern
          #1: Inefficient Filtering
Wrapping filtering column in a function (DB)
• Problem
  – The query optimizer does not see the column
  – Available index likely does not get used
• Solution
  – Rewrite query to avoid using function if possible
  – Format bind variables in application tier
Example of bad T-SQL function usage
             - Without -
Example of bad T-SQL function usage
          - With LOWER-
Example of bad T-SQL function usage
              - Comparison -



                     Without T-SQL function   With T-SQL function
Logical I/O reads    3                        3238
Estimated CPU cost   0.396307                 15.454153
Most violated high-level anti-pattern
           #1: Inefficient Filtering
Other low-level anti-pattern examples
•   Filtering larger query first
•   Implicit data type conversion
•   Inefficient CSS selectors
•   Inefficient DOM element lookup
•   Inefficient regex
•   Unnecessary query on VIEW instead of table
•   Usage of "NOT IN" comparison rather than JOIN
•   Usage of wrong index
•   Using UNION when returned records always unique
Most violated high-level anti-pattern
      #2: Unnecessary Processing
• Description
  – Processing when not needed or not needed at the time
  – Excessive or duplicate executions
• Problem
  – Consumes resources that can be used by important
    work
  – Increases execution/response time
• Solution
  – Remove, postpone (asynchronous), prioritize, or reorder
    the processing steps
  – Leverage caching to reuse loaded or calculated data
Most violated high-level anti-pattern
      #2: Unnecessary Processing
Presentation of Unlimited Results (UI Design)
• 5th most violated low-level anti-pattern
• Problem
  – Users typically do not consume all data when presented
    with large amount so the used resources are wasted
  – Severe system performance issue can arise depending
    on the volume of prepared results
• Solution
  – Paginate results
  – Guide users to narrow down search criteria
  – Limit amount of data that can be returned
Example usage of pagination and limiting
    the number of returned results
Most violated high-level anti-pattern
      #2: Unnecessary Processing
Inefficient access path (UI Design)
• 6th most violated low-level anti-pattern
• Problem
   – Room for optimization exists in actions/clicks users
     must take to complete his/her task
   – Results to creating additional work for the system
     (also impacts user’s time to task)
• Solution
   – Refactor UI or click path to let users accomplish
     their tasks more efficiently
Example of enhancing access path
Most violated high-level anti-pattern
      #2: Unnecessary Processing
Other low-level anti-pattern examples
• Excessive executions of maintenance task
• HTTP 404 error on cacheable static content
• Missing short-circuit logic
• No data caching
• No http caching
• Unnecessary cache reload
• Unnecessary conditional check
• Unnecessary object creation
• Updating unchanged data
Most violated high-level anti-pattern
              #3: The Ramp
• Description
  – Processing time increases or the system crashes as the
    application gets used over a period of time
• Problem
  – The application cannot handle the increased volume of
    data/traffic
  – Resource consumption increases or exhausts
• Solution
  – Select algorithms or data structures based on maximum
    size expected
  – Use algorithms/designs that adapt to the increasing size
    or doesn’t get effected by it (ex. flyweight
    pattern, streaming technique)
Most violated high-level anti-pattern
              #3: The Ramp
Too many objects in memory
• #4 most violated low-level anti-pattern
• Problem
   – Loading large amount of data or objects at once for
     processing can result to out-of-memory error and other
     system-level performance impact
   – Examples include unmarshalling entire DB resultset in
     heap and generation of large XML documents using
     DOM object
• Solution
   – Flyweight and lazy loading patterns
   – Streaming and chunking techniques
Example of streaming database result set
              - Overview -
• DataList/DataListIterator
   – Interface for a list/iterator data structure materialized
     from a data source, such as a database or a file
   – Extends the List/Iterator interface to leverage
     polymorphism
• ResultSetDataList
   – Implementation of DataList that’s materialized from a
     SQL resultset
   – Unmarshalls the resultset rows one by one as the getter
     method is called
• ResultSetDataListIterator
   – Iterator that’s materialized from ResultSetDataList
Example of streaming database result set
       - Usage considerations -
Avoid out-of-memory and SQL timeout
• Use ResultSet.TYPE_FORWARD_ONLY
• Set Statement fetch size
   – Default for Oracle JDBC = 10
   – Default for i-net MERLIA = 0
      • ‘0’ uses client cursor that reads all rows into memory
      • Specify fetch size to use cursor on server side
• Use flyweight pattern in the unmarshaller if possible
Example of streaming database result set
            - Code sample -
• See Appendix A
Most violated high-level anti-pattern
              #3: The Ramp
Not releasing resource (immediately) after use
• #8 most violated low-level anti-pattern
• Problem
  – Cause of connection leaks, deadlocks, performance
    degradation and other unexpected behavior
  – Threads, sockets, database connection, file
    handler, and other resources can be a victim
• Solution
  – Use finally block to ensure release
  – Release resource as quickly as possible
Example of resource management
              - CSContext -
CSContext csCtxt=null;
try {
    csCtxt = CSContext.getContext();
    // your code
} catch (Exception e) {
    csCtxt.rollback();
    csCtxt=null;
} finally {
    if (csCtxt!=null) {
    csCtxt.commit();
}
Most violated high-level anti-pattern
                #3: The Ramp
Other low-level anti-pattern examples
•   Exceeding max number of expressions in a list
•   No data caching
•   No priority logic
•   Not releasing resource (immediately) after use
•   Presentation of unlimited results
•   Transaction isolation unnecessarily wide
•   Unlimited cache storage
Low-level performance anti-patterns
    fixed in Blackboard Learn™ by tier

Application




 Database




                                      Frequency (%)
 UI Design




   Browser




  Network



              0   10   20   30   40                   50   60
Tools to identify anti-patterns:
             First line of defense
• Peer code review
  – Atlassian Crucible
  – Review Board
• Static code analyzer
  –   FindBugs
  –   PMD
  –   Sonar
  –   Custom rules
• Performance unit testing
  – JUnitPerf
Tools to identify anti-patterns:
                Deeper analysis
• Java
  – VisualVM
  – Memory Analyzer (MAT)
  – YourKit
• Browser
  –   Firebug
  –   Google Page Speed
  –   dynaTrace AJAX Edition
  –   Fiddler
  –   WebPagetest
Tools to identify anti-patterns:
             Deeper analysis
• Database
  – MS SQL Server
    • SQL Server Management Studio
    • SQL Server Profiler
    • Performance Dashboard
  – Oracle
    • SQL*Plus
    • Automatic Workload Repository (AWR)
    • Active Session History (ASH)
Takeaways


• The importance of performance and scalability
  for your B2
• Top violated performance anti-patterns in
  Blackboard Learn™
• Forensics Tools
Please provide feedback for this session by emailing
        DevConFeedback@blackboard.com.


           The title of this session is:
  Developing B2 for Performance and Scalability
Appendix A:
Example of streaming database result set
Example of streaming database result set
            - DataList.java -

public interface DataList<E> extends List<E>
{
  /**
   Closes the list and releases all of the resources that back
    the list
   */
  void close();
}
Example of streaming database result set
       - ResultSetDataList.java -
public <X> ResultSetDataList( DataListSelectQuery<X> query )
 {
   // make sure the query object and resultset object in the query object are not null
   …
   try {
     if ( query.getRst().isClosed() ) {
       throw new IllegalArgumentException( "Result set must not be closed" );
     }
     // Use this information to restrict the usage of methods that require scrolling
     _resultSetType = query.getRst().getType();
   } catch ( SQLException e ) {
     throw new IllegalArgumentException( "Unable to validate input result set", e );
   }
   _query = query;
   _rst = query.getRst();
   _unmarshaller = query.getUnmarshaller();
…
Example of streaming database result set
       - ResultSetDataList.java -
public E get( int index ) {
  if ( _resultSetType == ResultSet.TYPE_FORWARD_ONLY ) {
    String msg = "You must use the Iterator because your ResultSet is set to
     TYPE_FORWARD_ONLY.";
    throw new IllegalArgumentException( msg );
  }
  if ( index < 0 ) {
    throw new IndexOutOfBoundsException();
  }
  try {
    if ( _rst.absolute( index + 1 ) ) {
      if ( _rst.getRow() != index + 1 ) {
        throw new IndexOutOfBoundsException();
      }
      return (E) _unmarshaller.unmarshall();
    } else {
      throw new IndexOutOfBoundsException();
    }…
Example of streaming database result set
       - ResultSetDataList.java -

/**
      The close() method closes the prepared statement and result set wrapped in this
      object. This is called by the finalize method that garbage collector executes when
      appropriate. However, it should still be called as soon as this object is no longer
      necessary by the programmer. Please do not rely on the garbage collector.
*/
 @Override
  protected void finalize() throws Throwable {
    try {
      close();
    } finally {
      super.finalize();
    }
  }
Example of streaming database result set
    - ResultSetDataListIterator.java -
@Override
public E next()
{
  if ( !hasNext() )
  {
    throw new NoSuchElementException();
  }
  try
  {
     E element = (E) _list._unmarshaller.unmarshall();
    _elementRetrieved = true;
    return element;
  }
  //handle exceptions
  …

More Related Content

Similar to Blackboard DevCon 2011 - Developing B2 for Performance and Scalability (20)

PPTX
ICSE2014 - Detecting Performance Anti-patterns for Applications Developed usi...
Concordia University
 
PPTX
Icse2014 v3
SAIL_QU
 
PDF
Darius Šilingas and Rokas Bartkevicius: Agile Modeling: from Anti-Patterns to...
Agile Lietuva
 
PPTX
Paper summary
Adam Feldscher
 
PPTX
Optimizing Application Performance - 2022.pptx
JasonTuran2
 
PDF
Programming for Performance
Cris Holdorph
 
PDF
Commonly used design patterns
Mojammel Haque
 
PPT
W-JAX Performance Workshop - Database Performance
Alois Reitbauer
 
PDF
Data Visualizations in Digital Products (ProductCamp Boston 2016)
ProductCamp Boston
 
PDF
Designing for Performance: Database Related Worst Practices
Christian Antognini
 
PPTX
Sql server infernals
Gianluca Sartori
 
PPTX
Cloud design pattern using azure
Karthikeyan VK
 
PPT
Anti-Patterns
CleanestCode
 
PDF
Designing for performance: Database Related Worst Practices
Trivadis
 
PPTX
Performance Design Patterns 3
Adam Feldscher
 
PDF
5 physical data modeling blunders 09092010
ERwin Modeling
 
PDF
Top-10-Java-Performance-Problems.pdf
KiranChinnagangannag
 
PPTX
Quick and dirty performance analysis
Chris Kernaghan
 
PDF
All Together Now: A Recipe for Successful Data Governance
Inside Analysis
 
PPTX
.NET Architecture for Enterprises
Wade Wegner
 
ICSE2014 - Detecting Performance Anti-patterns for Applications Developed usi...
Concordia University
 
Icse2014 v3
SAIL_QU
 
Darius Šilingas and Rokas Bartkevicius: Agile Modeling: from Anti-Patterns to...
Agile Lietuva
 
Paper summary
Adam Feldscher
 
Optimizing Application Performance - 2022.pptx
JasonTuran2
 
Programming for Performance
Cris Holdorph
 
Commonly used design patterns
Mojammel Haque
 
W-JAX Performance Workshop - Database Performance
Alois Reitbauer
 
Data Visualizations in Digital Products (ProductCamp Boston 2016)
ProductCamp Boston
 
Designing for Performance: Database Related Worst Practices
Christian Antognini
 
Sql server infernals
Gianluca Sartori
 
Cloud design pattern using azure
Karthikeyan VK
 
Anti-Patterns
CleanestCode
 
Designing for performance: Database Related Worst Practices
Trivadis
 
Performance Design Patterns 3
Adam Feldscher
 
5 physical data modeling blunders 09092010
ERwin Modeling
 
Top-10-Java-Performance-Problems.pdf
KiranChinnagangannag
 
Quick and dirty performance analysis
Chris Kernaghan
 
All Together Now: A Recipe for Successful Data Governance
Inside Analysis
 
.NET Architecture for Enterprises
Wade Wegner
 

More from Noriaki Tatsumi (11)

PDF
Feature drift monitoring as a service for machine learning models at scale
Noriaki Tatsumi
 
PPTX
GraphQL Summit 2019 - Configuration Driven Data as a Service Gateway with Gra...
Noriaki Tatsumi
 
PPTX
Voice Summit 2018 - Millions of Dollars in Helping Customers Through Searchin...
Noriaki Tatsumi
 
PPTX
Microservices, Continuous Delivery, and Elasticsearch at Capital One
Noriaki Tatsumi
 
PPTX
Operating a High Velocity Large Organization with Spring Cloud Microservices
Noriaki Tatsumi
 
PPTX
Application Performance Management
Noriaki Tatsumi
 
PPTX
Blackboard DevCon 2013 - Advanced Caching in Blackboard Learn Using Redis Bui...
Noriaki Tatsumi
 
PPTX
Blackboard DevCon 2013 - Hackathon
Noriaki Tatsumi
 
PPTX
Blackboard DevCon 2012 - Ensuring Code Quality
Noriaki Tatsumi
 
PPTX
Blackboard DevCon 2011 - Performance Considerations for Custom Theme Development
Noriaki Tatsumi
 
PPTX
Blackboard DevCon 2012 - How to Turn on the Lights to Your Blackboard Learn E...
Noriaki Tatsumi
 
Feature drift monitoring as a service for machine learning models at scale
Noriaki Tatsumi
 
GraphQL Summit 2019 - Configuration Driven Data as a Service Gateway with Gra...
Noriaki Tatsumi
 
Voice Summit 2018 - Millions of Dollars in Helping Customers Through Searchin...
Noriaki Tatsumi
 
Microservices, Continuous Delivery, and Elasticsearch at Capital One
Noriaki Tatsumi
 
Operating a High Velocity Large Organization with Spring Cloud Microservices
Noriaki Tatsumi
 
Application Performance Management
Noriaki Tatsumi
 
Blackboard DevCon 2013 - Advanced Caching in Blackboard Learn Using Redis Bui...
Noriaki Tatsumi
 
Blackboard DevCon 2013 - Hackathon
Noriaki Tatsumi
 
Blackboard DevCon 2012 - Ensuring Code Quality
Noriaki Tatsumi
 
Blackboard DevCon 2011 - Performance Considerations for Custom Theme Development
Noriaki Tatsumi
 
Blackboard DevCon 2012 - How to Turn on the Lights to Your Blackboard Learn E...
Noriaki Tatsumi
 
Ad

Recently uploaded (20)

PDF
99 Bottles of Trust on the Wall — Operational Principles for Trust in Cyber C...
treyka
 
PDF
Simplify Your FME Flow Setup: Fault-Tolerant Deployment Made Easy with Packer...
Safe Software
 
PPTX
Smart Factory Monitoring IIoT in Machine and Production Operations.pptx
Rejig Digital
 
PPSX
Usergroup - OutSystems Architecture.ppsx
Kurt Vandevelde
 
PPTX
2025 HackRedCon Cyber Career Paths.pptx Scott Stanton
Scott Stanton
 
PDF
Dev Dives: Accelerating agentic automation with Autopilot for Everyone
UiPathCommunity
 
PPTX
Practical Applications of AI in Local Government
OnBoard
 
PDF
Kubernetes - Architecture & Components.pdf
geethak285
 
PDF
TrustArc Webinar - Navigating APAC Data Privacy Laws: Compliance & Challenges
TrustArc
 
PDF
Java 25 and Beyond - A Roadmap of Innovations
Ana-Maria Mihalceanu
 
PDF
🚀 Let’s Build Our First Slack Workflow! 🔧.pdf
SanjeetMishra29
 
PDF
Hello I'm "AI" Your New _________________
Dr. Tathagat Varma
 
PDF
GDG Cloud Southlake #44: Eyal Bukchin: Tightening the Kubernetes Feedback Loo...
James Anderson
 
PPTX
MARTSIA: A Tool for Confidential Data Exchange via Public Blockchain - Poster...
Michele Kryston
 
PPTX
CapCut Pro PC Crack Latest Version Free Free
josanj305
 
PDF
My Journey from CAD to BIM: A True Underdog Story
Safe Software
 
PDF
Enhancing Environmental Monitoring with Real-Time Data Integration: Leveragin...
Safe Software
 
PPTX
Paycifi - Programmable Trust_Breakfast_PPTXT
FinTech Belgium
 
PDF
Understanding The True Cost of DynamoDB Webinar
ScyllaDB
 
PPTX
Mastering Authorization: Integrating Authentication and Authorization Data in...
Hitachi, Ltd. OSS Solution Center.
 
99 Bottles of Trust on the Wall — Operational Principles for Trust in Cyber C...
treyka
 
Simplify Your FME Flow Setup: Fault-Tolerant Deployment Made Easy with Packer...
Safe Software
 
Smart Factory Monitoring IIoT in Machine and Production Operations.pptx
Rejig Digital
 
Usergroup - OutSystems Architecture.ppsx
Kurt Vandevelde
 
2025 HackRedCon Cyber Career Paths.pptx Scott Stanton
Scott Stanton
 
Dev Dives: Accelerating agentic automation with Autopilot for Everyone
UiPathCommunity
 
Practical Applications of AI in Local Government
OnBoard
 
Kubernetes - Architecture & Components.pdf
geethak285
 
TrustArc Webinar - Navigating APAC Data Privacy Laws: Compliance & Challenges
TrustArc
 
Java 25 and Beyond - A Roadmap of Innovations
Ana-Maria Mihalceanu
 
🚀 Let’s Build Our First Slack Workflow! 🔧.pdf
SanjeetMishra29
 
Hello I'm "AI" Your New _________________
Dr. Tathagat Varma
 
GDG Cloud Southlake #44: Eyal Bukchin: Tightening the Kubernetes Feedback Loo...
James Anderson
 
MARTSIA: A Tool for Confidential Data Exchange via Public Blockchain - Poster...
Michele Kryston
 
CapCut Pro PC Crack Latest Version Free Free
josanj305
 
My Journey from CAD to BIM: A True Underdog Story
Safe Software
 
Enhancing Environmental Monitoring with Real-Time Data Integration: Leveragin...
Safe Software
 
Paycifi - Programmable Trust_Breakfast_PPTXT
FinTech Belgium
 
Understanding The True Cost of DynamoDB Webinar
ScyllaDB
 
Mastering Authorization: Integrating Authentication and Authorization Data in...
Hitachi, Ltd. OSS Solution Center.
 
Ad

Blackboard DevCon 2011 - Developing B2 for Performance and Scalability

  • 1. Developing B2 for Performance and Scalability Noriaki Tatsumi Kevin Weisser
  • 2. Why Performance Matters? • User experience – Your users don’t like slow and unresponsive apps – Slow applications lose users in frustrations – Users tend to wander off beyond captive response time of 7 – 10 seconds • User adoption – Google saw 25% decline in searches within 6 weeks after introducing 0.5s delay (~$2.5B loss) – Wikia observed up to 20% user loss as the page load time reached 5 seconds
  • 3. Wikia – Exit rate (abandon) http://assets.en.oreilly.com/1/event/27/Varnish%20-%20A%20State%20of%20the%20Art%20High-Performance%20Reverse%20Proxy%20Presentation.pdf
  • 4. “With great power comes great responsibility” – Uncle Ben, Spiderman • Reputations at stake • System resources are shared and limited • B2s with scalability problem impacts system performance – System-wide performance degradation – Server downtime
  • 5. What is an anti-pattern? • Some repeated pattern of action, process or structure that initially appears to be beneficial, but ultimately produces more bad consequences than beneficial results • A refactored solution exists that is clearly documented, proven in actual practice and repeatable. - Definition from Wikipedia
  • 6. How can anti-patterns help? • Prevents performance as an afterthought • Helps identify performance issues that typically don’t arise until deployed in production • Prevents pre-mature optimizations
  • 7. How do I use anti-patterns? • Identify and correct the occurrences of anti- patterns during: – Design review – Implementation/code review – Execution of experiments and profiling – Static code analysis
  • 8. Top 10 violated high-level performance anti-patterns fixed in Blackboard Learn™ Inefficient Filtering Unnecessary Processing The Ramp Data Overreach Frequency (%) Unlimited Resource Usage Functional Bug Excessive Granularity More is Less Usage of Outdated Tools and APIs Mishandled Concurrency 0 5 10 15 20 25 30
  • 9. Top 10 violated low-level performance anti-patterns fixed in Blackboard Learn™ Missing or non-optimal index [db] Inefficient or erroneous criteria [db] Unnecessary data retrieval [app} Too many objects in memory [app} Presentation of unlimited results [ui] Frequency (%) Inefficient access path [ui] No data caching [app} Not releasing resource (immediately) after use [app} Incompatiblity with HA deployment [app} Excessive DB round trips [app} 0 5 10 15 20 25
  • 10. Most violated high-level anti-pattern #1: Inefficient Filtering • Description – Querying data using inefficient logic, algorithm, or technique • Problem – Consumes resources that can be used by other processes – Increases execution/response time • Solution – Store data in both centralized and organized manner – Search against smaller data set first, fail fast, and don’t look at unnecessary data – Leverage indexing and other efficient techniques/algorithms
  • 11. Most violated high-level anti-pattern #1: Inefficient Filtering Missing or non-optimal index (DB) • Most violated low-level anti-pattern • Problem – Missing appropriate index on search columns leads to inefficient data retrieval operation by SQL query optimizer – Having index can inversely add unnecessary overhead if the column is never used for searched criteria • Solution – Analyze SQL execution plan to verify usage of proper index – Create index on foreign keys – Create unique index on unique columns – Use an index to eliminate unnecessary full-table or index scans to access small percentage of data on a large table – Use covering index for key lookup
  • 12. Creating Database Objects with B2 • Release 9.1 SP1 and above – B2s authored by independent developers can now define and install schema elements • Not enabled by default – Administrators must enable this functionality from the B2 management section of the admin panel • Documentation – http://www.edugarage.com/display/BBDN/Creating+ Database+Objects+with+Building+Blocks
  • 13. Most violated high-level anti-pattern #1: Inefficient Filtering Inefficient or erroneous criteria (DB) • The second most violated low-level anti-pattern • Problem – Duplicate, unnecessary, incorrect, or missing predicate checks and joins exist in SQL – Increases response time, system resource consumption, and locking • Solution – Be specific on what data you need – Keep it simple and avoid unnecessary checks – Use JOIN criteria that aligns with index – Analyze execution plan to derive efficient and balanced query
  • 14. Most violated high-level anti-pattern #1: Inefficient Filtering Wrapping filtering column in a function (DB) • Problem – The query optimizer does not see the column – Available index likely does not get used • Solution – Rewrite query to avoid using function if possible – Format bind variables in application tier
  • 15. Example of bad T-SQL function usage - Without -
  • 16. Example of bad T-SQL function usage - With LOWER-
  • 17. Example of bad T-SQL function usage - Comparison - Without T-SQL function With T-SQL function Logical I/O reads 3 3238 Estimated CPU cost 0.396307 15.454153
  • 18. Most violated high-level anti-pattern #1: Inefficient Filtering Other low-level anti-pattern examples • Filtering larger query first • Implicit data type conversion • Inefficient CSS selectors • Inefficient DOM element lookup • Inefficient regex • Unnecessary query on VIEW instead of table • Usage of "NOT IN" comparison rather than JOIN • Usage of wrong index • Using UNION when returned records always unique
  • 19. Most violated high-level anti-pattern #2: Unnecessary Processing • Description – Processing when not needed or not needed at the time – Excessive or duplicate executions • Problem – Consumes resources that can be used by important work – Increases execution/response time • Solution – Remove, postpone (asynchronous), prioritize, or reorder the processing steps – Leverage caching to reuse loaded or calculated data
  • 20. Most violated high-level anti-pattern #2: Unnecessary Processing Presentation of Unlimited Results (UI Design) • 5th most violated low-level anti-pattern • Problem – Users typically do not consume all data when presented with large amount so the used resources are wasted – Severe system performance issue can arise depending on the volume of prepared results • Solution – Paginate results – Guide users to narrow down search criteria – Limit amount of data that can be returned
  • 21. Example usage of pagination and limiting the number of returned results
  • 22. Most violated high-level anti-pattern #2: Unnecessary Processing Inefficient access path (UI Design) • 6th most violated low-level anti-pattern • Problem – Room for optimization exists in actions/clicks users must take to complete his/her task – Results to creating additional work for the system (also impacts user’s time to task) • Solution – Refactor UI or click path to let users accomplish their tasks more efficiently
  • 23. Example of enhancing access path
  • 24. Most violated high-level anti-pattern #2: Unnecessary Processing Other low-level anti-pattern examples • Excessive executions of maintenance task • HTTP 404 error on cacheable static content • Missing short-circuit logic • No data caching • No http caching • Unnecessary cache reload • Unnecessary conditional check • Unnecessary object creation • Updating unchanged data
  • 25. Most violated high-level anti-pattern #3: The Ramp • Description – Processing time increases or the system crashes as the application gets used over a period of time • Problem – The application cannot handle the increased volume of data/traffic – Resource consumption increases or exhausts • Solution – Select algorithms or data structures based on maximum size expected – Use algorithms/designs that adapt to the increasing size or doesn’t get effected by it (ex. flyweight pattern, streaming technique)
  • 26. Most violated high-level anti-pattern #3: The Ramp Too many objects in memory • #4 most violated low-level anti-pattern • Problem – Loading large amount of data or objects at once for processing can result to out-of-memory error and other system-level performance impact – Examples include unmarshalling entire DB resultset in heap and generation of large XML documents using DOM object • Solution – Flyweight and lazy loading patterns – Streaming and chunking techniques
  • 27. Example of streaming database result set - Overview - • DataList/DataListIterator – Interface for a list/iterator data structure materialized from a data source, such as a database or a file – Extends the List/Iterator interface to leverage polymorphism • ResultSetDataList – Implementation of DataList that’s materialized from a SQL resultset – Unmarshalls the resultset rows one by one as the getter method is called • ResultSetDataListIterator – Iterator that’s materialized from ResultSetDataList
  • 28. Example of streaming database result set - Usage considerations - Avoid out-of-memory and SQL timeout • Use ResultSet.TYPE_FORWARD_ONLY • Set Statement fetch size – Default for Oracle JDBC = 10 – Default for i-net MERLIA = 0 • ‘0’ uses client cursor that reads all rows into memory • Specify fetch size to use cursor on server side • Use flyweight pattern in the unmarshaller if possible
  • 29. Example of streaming database result set - Code sample - • See Appendix A
  • 30. Most violated high-level anti-pattern #3: The Ramp Not releasing resource (immediately) after use • #8 most violated low-level anti-pattern • Problem – Cause of connection leaks, deadlocks, performance degradation and other unexpected behavior – Threads, sockets, database connection, file handler, and other resources can be a victim • Solution – Use finally block to ensure release – Release resource as quickly as possible
  • 31. Example of resource management - CSContext - CSContext csCtxt=null; try { csCtxt = CSContext.getContext(); // your code } catch (Exception e) { csCtxt.rollback(); csCtxt=null; } finally { if (csCtxt!=null) { csCtxt.commit(); }
  • 32. Most violated high-level anti-pattern #3: The Ramp Other low-level anti-pattern examples • Exceeding max number of expressions in a list • No data caching • No priority logic • Not releasing resource (immediately) after use • Presentation of unlimited results • Transaction isolation unnecessarily wide • Unlimited cache storage
  • 33. Low-level performance anti-patterns fixed in Blackboard Learn™ by tier Application Database Frequency (%) UI Design Browser Network 0 10 20 30 40 50 60
  • 34. Tools to identify anti-patterns: First line of defense • Peer code review – Atlassian Crucible – Review Board • Static code analyzer – FindBugs – PMD – Sonar – Custom rules • Performance unit testing – JUnitPerf
  • 35. Tools to identify anti-patterns: Deeper analysis • Java – VisualVM – Memory Analyzer (MAT) – YourKit • Browser – Firebug – Google Page Speed – dynaTrace AJAX Edition – Fiddler – WebPagetest
  • 36. Tools to identify anti-patterns: Deeper analysis • Database – MS SQL Server • SQL Server Management Studio • SQL Server Profiler • Performance Dashboard – Oracle • SQL*Plus • Automatic Workload Repository (AWR) • Active Session History (ASH)
  • 37. Takeaways • The importance of performance and scalability for your B2 • Top violated performance anti-patterns in Blackboard Learn™ • Forensics Tools
  • 38. Please provide feedback for this session by emailing [email protected]. The title of this session is: Developing B2 for Performance and Scalability
  • 39. Appendix A: Example of streaming database result set
  • 40. Example of streaming database result set - DataList.java - public interface DataList<E> extends List<E> { /** Closes the list and releases all of the resources that back the list */ void close(); }
  • 41. Example of streaming database result set - ResultSetDataList.java - public <X> ResultSetDataList( DataListSelectQuery<X> query ) { // make sure the query object and resultset object in the query object are not null … try { if ( query.getRst().isClosed() ) { throw new IllegalArgumentException( "Result set must not be closed" ); } // Use this information to restrict the usage of methods that require scrolling _resultSetType = query.getRst().getType(); } catch ( SQLException e ) { throw new IllegalArgumentException( "Unable to validate input result set", e ); } _query = query; _rst = query.getRst(); _unmarshaller = query.getUnmarshaller(); …
  • 42. Example of streaming database result set - ResultSetDataList.java - public E get( int index ) { if ( _resultSetType == ResultSet.TYPE_FORWARD_ONLY ) { String msg = "You must use the Iterator because your ResultSet is set to TYPE_FORWARD_ONLY."; throw new IllegalArgumentException( msg ); } if ( index < 0 ) { throw new IndexOutOfBoundsException(); } try { if ( _rst.absolute( index + 1 ) ) { if ( _rst.getRow() != index + 1 ) { throw new IndexOutOfBoundsException(); } return (E) _unmarshaller.unmarshall(); } else { throw new IndexOutOfBoundsException(); }…
  • 43. Example of streaming database result set - ResultSetDataList.java - /** The close() method closes the prepared statement and result set wrapped in this object. This is called by the finalize method that garbage collector executes when appropriate. However, it should still be called as soon as this object is no longer necessary by the programmer. Please do not rely on the garbage collector. */ @Override protected void finalize() throws Throwable { try { close(); } finally { super.finalize(); } }
  • 44. Example of streaming database result set - ResultSetDataListIterator.java - @Override public E next() { if ( !hasNext() ) { throw new NoSuchElementException(); } try { E element = (E) _list._unmarshaller.unmarshall(); _elementRetrieved = true; return element; } //handle exceptions …

Editor's Notes

  • #3: Q: Do you like waiting for applications?Q: Have you guys seen the study done by Google?
  • #4: Illustrates the direct correlation of site exit rate to increase in page load time = this is why you should care about performance and scalability of your B2s
  • #9: Anti-patterns produced from root-cause analysis of performance bugs that were fixed since 8/2009 (~200 bugs).
  • #10: More concrete examples of anti-pattern violations.
  • #13: Q: Why should I care about table indexes? A: Because you can create database objects in 9.1 SP1 and above!
  • #20: Solution:Postpone -&gt; asynchronous
  • #29: ResultSet.TYPE_FORWARD_ONLY:Cursor may move forward only
  • #32: - The top level state manager for a series of Blackboard Content System calls- For every set of actions grouped together into one transaction, a new context is created and used- A Context instance contains transactional state for that request (i.e. commit, rollback)
  • #34: Segway to tools
  • #35: Eclipse integration available for:FindBugsPMDSonarJUnitPerf
  • #37: SQL Server Management Studio:- Use to get execution plans and run DMV queriesSQLDiag:http://msdn.microsoft.com/en-us/library/ms162833.aspxSimplifies diagnostic information gathering for SQL ServerPAL:http://pal.codeplex.com/Reads in a performance monitor counter log and analyzes it using known thresholdsAWR:http://www.oracle-base.com/articles/10g/AutomaticWorkloadRepository10g.phpUsed to collect performance statistics (ex. Wait events, resource intensive SQL statements, system and session statistics) ASHhttp://www.orafaq.com/wiki/ASHTracks session activity and simplify performance tuning
  • #42: DataListSelectQuery extends