SaaS - Performance Management - PowerPoint PPT Presentation


Title: SaaS - Performance Management


1
SaaS - Performance Management
20th Nov 2013
2
ITaaS Platform
We studied the business challenges of SMBs to
redefine the Technology Consumption Model On the
software side the solution was to build a set of
multi-tenant applications to leverage the SaaS
model
3
SaaS Performance Management
Introduction
  1. The SaaS platform Solution stack
  2. Performance challenges
  3. Three tier Architecture
  4. Performance optimizations for each tier
  5. SaaS Three Tier Architecture

4
ITaaS Solution Stack
Business Analytics
Niche Vertical Application Layer
Software Solution
Network Solution
Hardware Solution
Biz Services
Reward-Recognition
Virtual Community
Assessment
Customer Supplier Integration Layer
Vertical Core Applications Layer
Manufacturing
Retail
Wellness
Prof. Services
Education
CRM
FA
HRMS
Payroll
Projects
PI
Common Business Applications Layer
Document Mgmt
Online Presence Mgmt
Enterprise Intranet Mgmt
Messaging Solution
Office Mgmt Solution
Common Office Applications Layer
Networks Layer
Network Connectivity
Data Center Hosting
Network Devices
Desktop/Laptops
Hardware Layer
Printers
On Premise Servers
All System Software
5
SaaS Performance Management
Introduction
  1. The SaaS platform Solution stack
  2. Performance challenges
  3. Three tier Architecture
  4. Performance optimizations for each tier
  5. Deployment Architecture Monitoring

6
Performance Challenges
  • Can users get a fast response over the low
    bandwidth network?
  • Whether to host different solutions on different
    servers or on the same server?
  • How do we find if anything is slow in production?
  • Can the applications on the cloud scale as
    transactions and users increase?
  • Will business operations continue in face of a
    disaster?
  • Will use of Open source tools and servers serve
    the requirement?
  • How would we avoid bad code entering production?
  • How would we identify if any bad code has entered
    production?

7
SaaS Performance Management
Introduction
  1. The SaaS platform Solution stack
  2. Performance challenges
  3. Basic three tier Architecture
  4. Performance optimizations for each tier
  5. SaaS Three Tier Architecture

8
Three tier Architecture
Perimeter Security
Web Tier
Application Tier
Reports
Applications

Slave
Master
Database Tier
C1
C1
C2
C2
9
SaaS Performance Management
Introduction
  • The SaaS platform Solution stack
  • Performance challenges
  • Basic three tier Architecture
  • Performance optimizations for each tier
  • Web
  • Application
  • Database
  • SaaS Three Tier Architecture

10
Summary of achieving speed
Introduction
  • Lookup DNS
  • Make TCP Connection
  • Reduce number of TCP reconnections
  • Negotiate SSL
  • Make the negotiation quick
  • Reduce number of renegotiations
  • Send Request
  • Reduce content to be sent
  • Server Sends Response
  • Send response quickly
  • Minimize response
  • Parse Response and Download additional Resources
  • Minimize number of resources to be downloaded
  • Render Content
  • Keep content lean, clean and simple
  • Ensure all required styles for rendering are
    available at the earliest
  • Compile and execute JavaScript (Single Threaded
    Blocking)
  • Keep minimal JavaScript
  • Defer JavaScript Execution

11
Web tier Minimize round-trip times
  • What is a Round-trip time (RTT) Request time
    Response time
  • Ways to minimize RTT -
  • Minimize the number of requests
  • Avoid bad requests (e.g. 404)
  • Combine external JavaScript
  • Combine external CSS
  • Optimize the order of styles and scripts
  • Use CSS Sprites for images
  • Parallelize them
  • Parallelize downloads across hostnames (CDN)

12
Web tier Set HTTP Keep Alive
  • What is it?
  • In HTTP/1.1 the keep-alive extension allows
    persistent
  • connections . Basically the HTTP sessions allow
    multiple
  • requests to reuse the same underlying TCP
    connection.
  • Advantage?
  • Speed up latency for html documents with lots of
    static content
  • Example of Web tier setting -
  • Apache has 2 directives - KeepAlive and
    KeepAliveTimeout
  • These directives keep the connection to the Web
    server alive for a pre-defined number of requests
    or for pre-defined time period (Default 100, 15
    seconds)

Make the negotiation quick
Browsers limit the number of parallel downloads
to six - eight(per hostname over HTTP/1.1). It is
beneficial to increase the no. of concurrent
connections to reduce page load time.
13
Web tier Optimize SSL Negotiation
  1. Offload SSL Negotiation to a Hardware Device
  2. Enable SSL Session Cache
  3. Set a proper Timeout for SSL Session Cache

Make the negotiation quick
Session Timeout should be a based on the security
concerns and normal Session Time of the user
14
Web tier Minimize HTML content
Criteria Object type to use Example
Records less than 5 Radio button/Check box Male/ Female
Records rarely increase is easy to scroll choose Drop down City, State, Country
Records increase in a narrow range Limited filters to search AJAX look up (AJAX call can be triggered after certain no. of characters are typed, esp. in case of Codification) Clinic names, Site names.
Records are in thousands and can increase Many filters to search Use Lookups (popup screen) Search an item by item id, item name, store name, item type, etc
15
Web tier Pagination
  • Paginate depending on the context - need not be
    same for all screens
  • To reduce navigation show the latest/relevant
    records first
  • Leverage various Pagination design patterns

16
Web tier Filters
  • Mandate filters for reports - To narrow the
    number of records fetched.
  • Put appropriate Constraints Date field should
    always be constrained.
  • A constraint would typically require Functional
    knowledge
  • Set default for certain filters e.g. Status
    filter defaulted to Open
  • Note A file of 3 MB was downloaded with various
    bandwidths and latencies using WANEM. (WAN
    emulator). Please find its outcome and its impact
    on the end user experience

Test case Bandwidth Latency Time taken 1 114
mbps NIL 3 secs 2 128 kbps NIL 3 mins
40 secs 3 256 kbps NIL 1 min 57 secs 4 128
kbps 50 ms 4 mins 45 secs 5 256 kbps 50 ms
2 mins
(without WANEM)
Tools Tip Create an excel sheet listing all
reports names v/s its filters. This would give a
holistic view of all the filters in the solution.
It would not be relatively easy to implement
policies related to mandating and constraining
filters with some functional knowledge obviously.
17
Web tier Serve static content
  • A typical web request Static Dynamic
  • Static content - images, style sheets,
    JavaScript, html, pdf, video files, etc should be
    served by Web tier
  • Advantage
  • To avoid use of expensive Application server
    threads
  • Avoid delay to serve static content during
    Garbage collections
  • Web servers serve static content faster than
    Application servers
  • Sets stage for further static content
    consolidation and scale with use of CDN

18
Web tier Minimize round-trip times Avoid bad
requests
  • HTTP requests are expensive, making an HTTP
    request and getting a useless response (i.e. 404
    Not Found) is unnecessary. Will slow down the
    user experience.

Firefox Use add-ons like Firebug, Page Speed,
YSlow, Fiddler, For IE Fiddler
19
Web tier Minimize round-trip times Optimize
order of styles scripts
  • Correct order of external style sheets and
    external/inline scripts enables better
    parallelization of downloads and speeds up
    browser rendering time.

Scenario 1 ltheadgtltlink rel"stylesheet"
type"text/css" href"stylesheet1.css" /gtltscript
type"text/javascript" src"scriptfile1.js"
/gtltscript type"text/javascript"
src"scriptfile2.js" /gtltlink rel"stylesheet"
type"text/css" href"stylesheet2.css" /gtltlink
rel"stylesheet" type"text/css"
href"stylesheet3.css" /gtlt/headgt
Scenario 2 ltheadgtltlink rel"stylesheet"
type"text/css" href"stylesheet1.css" /gtltlink
rel"stylesheet" type"text/css"
href"stylesheet2.css" /gtltlink rel"stylesheet"
type"text/css" href"stylesheet3.css" /gtltscript
type"text/javascript" src"scriptfile1.js"
/gtltscript type"text/javascript"
src"scriptfile2.js" /gtlt/headgt
Scenario 1 the second two style sheets must wait
until the JS files are finished downloading.
Scenario 2 merely by changing the order of the
resources - 100 ms is shaved off the total
download time.
20
Web tier Minimize round-trip times Combine
external Javascripts
  • Example of the download profile of an HTML file
    containing requests for 13 different .js files
    from the same domain

All files are downloaded serially, and take a
total of 4.46 seconds to complete. Now here is
the profile for the same document, with the same
13 files collapsed into 2 files. The same 729
kilobytes now take only 1.87 seconds to
download.
Tip 0 Externalize JavaScript Tip 1 Deduplicate
JavaScript Tip 1 JavaScript files should be
combined into fewer output files (except third
party JS libraries) Tip 2 Serve the file only
when that component is requested by a user.
21
Web tier Minimize round-trip times Sprite
Images
  • CSS Sprite - A single image file that contains
    number of different images.

Without Sprite
With Sprite
Reduced 14 HTTP hits as 15 images are combined in
one single sprite improving page load time. Try
SpriteMe bookmarklet
22
Web tier Minify static content
  • Minification - Removes whitespace, Line Breaks,
    comments, Shrinks Variables Optimizes code in
    js and css files. Decreases file size improves
    page load time.

File size
File size reduction 62
Tools available - Google Closure Compiler, YUI
Compressor, JSMIN, Dean Edwards Packer, DOJO
Compressor.
23
Web tier Compress static content
  1. GZIP generally reduces the response size by about
    70.
  2. Compression may sometimes not be supported by the
    proxy setting at customer end
  3. Zipping of images, pdf or any binary file not
    done as most are already compressed

24
290304000
Web tier Cache locally to take heat off
back-end servers
  • Set suitable static content expiry in the web
    tier
  • Example
  • ExpiresActive ON
  • ExpiresByType text/javascript "access plus 1
    month
  • Cache-Control public max-age290304000
  • Use a unique identifier to append every static
    request, to refresh browser cache when the
    content changes.

Note Incase of server farms do not use Etags.
25
Web tier Ajax lookups Optimization tip
AJAX auto lookups needs to have a limit to the
characters entered before which the lookup is
shown. A lookup done for every character entered
would lead to executing a select query. Infact it
is directly proportional to the characters typed.
Assuming there is no delay. For SMB we recommend
to set it to at least 4 characters.
4 Characters entered
1 Character entered
x
?
Note Enable Caching of AJAX Requests.
- 25 -
26
Web tier Bandwidth/Latency User Experience
Impact on a transaction response time due to
Bandwidth, Latency, Browser Cache Static file
compression in Web tier.
  Response times vs. varying bandwidth/latency Response times vs. varying bandwidth/latency Response times vs. varying bandwidth/latency Response times vs. varying bandwidth/latency Response times vs. varying bandwidth/latency Response times vs. varying bandwidth/latency Response times vs. varying bandwidth/latency Response times vs. varying bandwidth/latency Response times vs. varying bandwidth/latency Response times vs. varying bandwidth/latency
  Without browser cache Without browser cache Without browser cache Without browser cache Without browser cache Without browser cache Without browser cache With cache With cache With cache
Compression On Off On On Off On On On On On
Bandwidth 57 Mbps (Without WANem) 57 Mbps (Without WANem) 64 Kbps 128 Kbps 128 Kbps 128Kbps, Latency 200msec 128Kbps, Latency 400msec 128 Kbps 57 Mbps (Without WANem) 64 kbps
Resp. time (secs) 0.61 0.98 48.38 22.89 56.88 44.82 76.09 4.18 0.38 9.81
Note Time does not include Browser rendering
or processing Web Page size With compression
260 KB, Without compression 730 KB Used TCS'
WANem (WAN Emulator)
27
Web tier Avoid Repetitive Requests
  • Communicate the system status to the user once a
    transaction is initiated.
  • Example
  • Use the loader feature which creates a grey
    transparent layer over the existing User
  • interface and does not allow the access to the
    submit button.

28
Web tier Time to test
Analysis of web service http//www.webtest.org
for http//www.tcs.com
29
SaaS Performance Management
Introduction
  • The SaaS platform Solution stack
  • Performance challenges
  • Basic three tier Architecture
  • Performance optimizations for each tier
  • Web
  • Application
  • Database
  • SaaS Three Tier Architecture

30
Typical Activity in the Application Layer
Introduction
  • Read and interpret the request parameters
  • Validate the Request Parameters
  • Read from Data Store
  • Perform Business Operations
  • Read from Data Store
  • Persist Data to Data Store
  • Form and Send the HTML Response

Optimize Processing Minimize fetches from Data
Store Fetch only Required Data
31
App tier Review default server settings
  • Server Log Level (In thread dumps, several
    threads in blocked state are observed in several
    instances where too many logs at debug, info
    logs in the code in combination with low log
    level )
  • Clients/Threads in Web, Application and Database
    tiers
  • JVM settings
  • Max File Descriptors

Notes Apache maxClients, JBoss maxThreads,
MySQL - max_connections Generally - maxClients gt
Maxthreads lt Max_connections Every layer works
with a limited number of connections and
resources (read Threads)
32
Application tier Memory allocation for JEE
Application Server
64bit JVM allows us to set higher values of heap
size
But bigger the heap, longer the major GC and
hence pause times.
OS Room for me?
33
Application tier Out of memory?
Exception in thread main java.lang.OutOfMemoryEr
ror PermGen space ? Exception in thread "main"
java.lang.OutOfMemoryError Java heap space ?
  • Jvisualvm
  • Jmap
  • GC Viewer

Heap default java -Xms32m -Xmx128m
Minor GC
Major GC
Metadata of loaded classes
Note Specific to SUN JVM. Internals may vary
depending on choice of JVM
34
Application tier Exploring jmap (Memory Map)
command
  • Heap Space -
  • 1. jmap -heap ltPIDgt
  • - To get Heap details. Here look at the section
    named - "PS Old generation" -  if its above
    80-90 we may then execute the next two commands
    in that order to get more details 
  • 2. jmap -histo ltPIDgt
  • For each Java class, number of objects, memory
    size in bytes, and fully qualified class names
    are printed. VM internal class names are printed
    with '' prefix. This helps to find who is
    occupying the heap.
  • If the live suboption is specified, only live
    objects are counted
  • Note - jmap histolive triggers a FULL GC as
    compared to jmap -histo 
  • 3. jmap -dumplive,formatb,fileltjmap_date_server
    _dump.bin gt ltPIDgt
  • jmap -dumpformatb,fileltjmap_date_server_dump.b
    in gt ltPIDgt
  • Note Depending on JVM size, the heap dump can
    be sizeable. To open the heap dump in IBM Heap
    analyzer to check leak suspects the overall VM
    memory required is generally greater than twice
    the heap dump size
  • Permanent Generation Space - jmap permstat
    ltPIDgt
  • Prints class loader wise statistics of permanent
    generation of Java heap. For each class loader,
    its name, liveness, address, parent class loader,
    and the number and size of classes it has loaded
    are printed. In addition, the number and size of
    interned Strings are printed.

35
Application tier Scale Out vs Scale up
Methods to add more resources for a particular
application fall in two broad categories.
Scale-out and Scale-up.
Simple
Complex
Applications designed to scale out will almost
always scale up, yet applications designed to
scale up will almost never scale out. Example -
Before development, we would need to think - How
do we make the Singletons and Synchronized code
blocks work across processes ?
36
Application tier Synchronous v/s Asynchronous
Communication
Phone call (Synchronous) or vs email
(Asynchronous). Lets look at options to send
emails related for alerts, notification,
reminder, etc - 1) Send email in the same
transaction Synchronous - Each request blocks
the calling thread 2) Send email by spawning a
new thread - Asynchronous - Current thread is
not blocked whilst the separate thread awaits a
response from SMTP 3) Set a flag to send email
and let the batch job do the needful -
Asynchronous - A batch process wakes up after
set time gt Checks a status flag sends emails
in configurable batch mode (i.e. throttle the
traffic (count of emails) to be sent (with or
without priority) ) Note Configuration would
depend on capacity of SMTP server and/or traffic
at that instance. Also, here optimization
techniques like query tuning would be important.
37
Application tier Server side caching mechanisms
  • In JVM
  • Occupies precious JVM heap space
  • May trigger early frequent Garbage Collection
  • Can slow down and crash system
  • Not easy to replicate changes across JVMs in a
    cluster
  • Out of JVM
  • Relatively slower
  • Will overcome all the above mentioned problems

38
Application tier Server side caching mechanisms
  1. Memcached
  2. CouchBase/ Membase (A fork of memcached)
  3. Redis from Google
  4. Infinispan from JBoss
  5. Terracotta (now from Software AG)
  6. Coherence from Oracle
  7. Gemfire from Gemstone

39
Application tier Use latest stable libraries
  • Dos donts
  • Avoid duplicates jar files
  • Avoid multiple version of same jar files
  • Remove unwanted jars
  • Use latest stable versions of library files
  • Use Server default Library NOT Application library

40
Application tier Sticky Sessions
  • Session Identifies a User
  • Needs replication in clustered environment
  • Should NOT be used for storing large data
  • Session has a time out parameter
  • Sticky sessions should be enabled

41
Application tier String concatenation
Method Purpose
Built-in concatenation () operator To concatenate static strings String s1 "aa" "bb"
String.concat() To concatenate two strings
StringBuffer Is a synchronized class To be used in a multithreaded environment (when more than one thread access the same StringBuffer instance).
StringBuilder (Added in Java 5) Identical in all respects to StringBuffer except that is NOT synchronized, which means that if multiple threads are accessing it at the same time, there could be trouble (Not thread safe). To be used in places where string concatenation is to be done by a single thread
42
Application tier XML Parsing ? Memory is limited
High level differences between DOM parser and SAX
Parser in Java 1) DOM parser loads whole xml
document in memory while SAX only loads small
part of XML file in memory. 2) DOM parser is
faster than SAX because it access whole XML
document in memory. 3) SAX parser in Java is
better suitable for large XML file than DOM
Parser because it doesn't require much
memory. 4) DOM parser works on Document Object
Model while SAX is an event based xml
parser. Thumb rule Use DOM parser over SAX
parser if XML file is small enough and go with
SAX parser if you dont know size of xml files to
be processed or they are large.
43
Application tier File Handling (Leverage
stream-chaining techniques)
FileReader (DataInputStream - deprecated)-
Common and simple method to read a file but is
extremely slow. The reason for the poor
performance is that the DataInputStream class
does no buffering. The resulting reads are done
one byte at a time.For e.g. One of the
benchmark says that to read a 250 KB file it took
28,198 milliseconds BufferedReader
(BufferedInputStream-deprecated) A simple
improvement involves buffering the
FileInputStream by interposing a
BufferedInputStream in the stream chain. This
buffers the data, with the default buffer size of
2048 bytes Result - The resulting performance
increase for the medium sized file (250
kilobytes) was 91, from 28,198 milliseconds to
2,510 -- over an order of  magnitude with just a
simple change i.e. Example - try
BufferedReader in new BufferedReader(new
FileReader(argsi), 8192) while
((line in.readLine()) ! null)
nlines catch (Exception e)
System.out.println(" BR8192Test
exception" e ) finally in.close()
Note - The buffer size used in buffering
schemes is important for performance. As a rule
of thumb, bigger is better to a point. Refer -
http//www.kegel.com/java/wp-javaio.html. Match
the buffer size to the underlying storage sector
size. Adopt similar strategy for writing to files.
44
Application tier Blocking API - Synchronized
Blocking/Slow API
JVM
  • Note In case of Multiple JVM scenario there is
    no default JVM synchronization between the
    Application server instances. Hence, usage of
    Sync blocks should be done wisely and at granular
    level

45
Application tier Static Code Review
Commit Code
Commit Code
Project Code
Publish reports
Central Build Machine
  1. Compile
  2. Static Code Review
  3. Copy Paste instances
  4. Design analysis
  5. JUnit/Code coverage

John runs Static Code review locally
46
Application tier An approach to find time taken
by request on each tier
  • Use Non-intrusive code weaving (Aspect Oriented
    Programming
  • Available for
  • Java
  • .Net
  • Weave at run time
  • Weave at compile time
  • Can build all-inclusive monitoring
  • Not dependent on any framework
  • But can leverage standards like Servlet API, JDBC
    API etc

47
Application tier An approach to find time taken
by request on each tier
Web Layer
Business Layer
Data Access Layer
Capture start Time, IP Address, Port, Request URL
SQL, SQL Start Time, SQL End Time Request End
Time

DB
Capture query end time
Capture end time
JBoss
  1. For each request a unique thread is assigned by
    the Application server
  2. For each thread a Statistic Entity Object is
    created and its relationship maintained
  3. Using Unique thread id retrieve the Statistics
    Entity object at each layer and fill the
    respective attributes
  4. Once request is finished calculate time taken to
    process request, time taken to execute sql
    statement for respective URL
  5. Convert summary information in to string and
    stored it in the Collection object.
  6. Flush the thread and object relationship
  7. At periodic interval a service saves the
    collection object to a log file

48
Application tier Fault Isolation Architectural
Structure Swim Lanes
There are four general principles for designing
and implementing swim lanes in a systems
architecture 1) There must not be any
shared hardware or software between lanes other
than possibly highly available network gear
such as paired loadbalancers or border routers.
(Nothing is shared) 2) No synchronous calls
can take place between swim lanes. If cross swim
lane communication is required, i.e. grabbing
search results to display on the same page as
login, it must be done asynchronously. (Nothing
crosses a swim lane boundary, Transactions occur
along swim lanes) 3) Limit asynchronous
communication. While permitted, more calls lead
to a greater chance of failure propagation. 4)
Use timeouts with asynchronous calls. There is
no need to tie up the users browser or your
server waiting for the eventual TCP timeout.
Note - Swim lane the money maker, Swim lane the
problem areas, Swim lane natural barriers
49
SaaS Performance Management
Introduction
  • The SaaS platform Solution stack
  • Performance challenges
  • Basic three tier Architecture
  • Performance optimizations for each tier
  • Web
  • Application
  • Database
  • SaaS Three Tier Architecture

50
Database tier Check for Open database
connections
  • Database memory requirement primarily depends on
  • Memory allocated per connection (Limited
    resource)
  • Global memory
  • Memory required for background processes.
  • To identify connection leaks at various levels
  • Static code review
  • Verify pattern Connect Query Quit in dB
    general logs
  • Consolidate database connection closure code in
    framework itself
  • Use AOP to find Line of Code that invoked an open
    database connection or auto close it
  • Kill any idle connections for more than specified
    time -Server policy

51
Database tier Reduce table joins
  • Requirement To fetch list of all products sold,
    along with their rate, quantity, sell date and
    customer to whom products were sold
  • Typical Join
  • Customer Master (100000)
  • Product Master (100000)
  • Bill Header (100000)
  • Bill Details (500000) (Five items per bill)

52
Database tier Reduce table joins
  • Instead
  • Join only Bill Header and Bill Details
  • Fetch the Customer Name, and the Product Name
    from a cache of Hashmaps
  • Customer Id Customer Name
  • Product Id Product Name

53
Database tier Track slow queries
Select from emp

C1
C2
gt1 second
  • Optimize queries that
  • repeatedly run slow
  • examine lot of records
  • fetch lot of records
  • take more time to execute
  • take up locks for long time

Slow Query Log
54
Database tier Avoid full table scans
  • Full table scans are where the database will read
    the entire table without an index.
  • Reasons why full table scans are performed
  • no WHERE clause
  • no index on any field in WHERE clause
  • poor selectivity on an indexed field
  • too many records meet WHERE conditions
  • using SELECT FROM
  • function used on the indexed column in the query

Generate Explain plans to understand how database
query optimizer chooses to execute a query
55
Database tier Consider chunk at a time v/s row
at a time
ConnectionID_1 INSERT INTO table(A,B)
values(1,2) ConnectionID_1 Quit ConnectionID_2
INSERT INTO table(A,B) values(3,4) ConnectionID_2
Quit
  • One insert - one connection
  • All inserts one connection
  • Batch Insert one connection
  • Prepared Inserts one connection
  • Good for repeated inserts
  • Extended Inserts one connection
  • Good for bulk Insertion

ConnectionID_1 INSERT INTO table(A,B)
values(1,2) ConnectionID_1 INSERT INTO
table(A,B) values(3,4) ConnectionID_1 Quit
better
Batch start ConnectionID_1 INSERT INTO
table(A,B) values(1,2) ConnectionID_1 INSERT
INTO table(A,B) values(3,4) Batch
end ConnectionID_1 Quit
Begin Transaction ConnectionID_1 INSERT INTO
table(A,B) values(?,?) Set Value (1, 2)
Execute SetValue(3,4) Commit Transaction Connect
ionID_1 Quit
ConnectionID_1 INSERT INTO table(A,B)
values(1,2),(3,4) ConnectionID_1 Quit
In case of MySQL extended insert one connection
technique is seen the fastest. Note Need to
watch out on the limit on size of the query and
regular commits should be done after set
frequency to avoid large rollbacks. Use Prepared
Statement and Bulk Commit
56
Database tier Generate Explain plans
Developer Query works fast in my environment
but is slow in Production, is something different
there?
  • DBA -
  • Records in development environment less than
    production
  • Optimizers perspective matters than yours
  • Recommendation -
  • Generate a Query execution plan to understand the
    execution plan chosen by the database optimizer.
  • An execution plan (Explain plan) helps to
    understand
  • Number of rows examined
  • Use of indexes
  • Missing indexes
  • Type of join
  • Information on sorting, etc

57
Database tier Stored Procedures
  • Set of SQL statements stored on the server and
    are pre-compiled. It takes in
  • certain arguments and processes that code with
    those arguments at
  • execution time
  • Points to ponder before we use Stored Procedures
  • Ease to scale database compared to application
    tier?
  • Ease to write and maintain?
  • Ease to debug
  • Need for specialized skill set
  • Performance gain
  • Reduction in traffic between application and
    database tier
  • Reusability transparency
  • Security

58
Database tier Use prepared statements
  • Prepared statements are the ability to set up a
    statement once, and then execute it
  • many times with different parameters.
  • Advantages
  • Save on query parsing (especially if we execute
    the query several times)
  • Prepared statement caching inside the J2EE server
    connection pool avoids re-preparing of the
    statement
  • Cache is database-wide Improves efficiency
    across applications if they all use similar
    parameterized SQL

59
Database tier Application tier switch for
Database servers
  • Good Practice For Multi-Tenanted Applications
  • Provide an Application level switch that can
    dynamically select the database to connect which
    itself may reside on one more database instances

60
System File descriptors
  • Linux limits the number of file descriptors that
    any one process may open the default limits are
    1024 per process which generally is not
    sufficient for production use
  • Plan to set this to a value which is more than
    the maximum number of TCP connections expected on
    the server.

61
Introduction
SaaS Three Tier Architecture Consolidate Scale
F5 BIG-IP Local Traffic Manager
Web Tier
Application Tier
Reports
Applications


Database Tier
C1
C1
C2
C2
62
SaaS Three Tier Architecture Consolidate Scale
Perimeter Security
Web Tier
Application Tier
Reports
Applications
Cloud Capacity increases to serve more users and
is resilient to failures
Database Tier
63
Static Request
Dynamic Request
Report Request
SaaS Three Tier Architecture Caching
Use browser cache
Static Request
Dynamic Request
Perimeter Security
Cached Data
Web Tier
Compress Static Content
Application Tier
Reports
Cache-enabled Browser
Server Cache
Cached Data
Applications
Minified compressed Static content served by
Web tier and cached by browser with appropriate
version


Database Tier
C1
C1
C2
C2
Reports
Transactions
64
SaaS Architecture Monitoring Production Servers
Performance counters on Production Servers
monitored using TCSMonIT
65
SaaS Architecture Monitoring Remote Machines
(On-premise)
Administer from any location
Audit
Monitor
Install Software
Experts connect remotely for immediate support
Remote backup
66
SaaS Architecture Business Continuity
SaaS users continue to operate in face of disaster
View by Category
About This Presentation
Title:

SaaS - Performance Management

Description:

Title: Slide 1 Author: 332418 Last modified by: Sundarraj Kaushik Created Date: 2/11/2011 1:07:23 PM Document presentation format: On-screen Show (4:3) – PowerPoint PPT presentation

Number of Views:79
Avg rating:3.0/5.0
Slides: 67
Provided by: 3322
Learn more at: http://www.cmgindia.org
Category:

less

Write a Comment
User Comments (0)
Transcript and Presenter's Notes

Title: SaaS - Performance Management


1
SaaS - Performance Management
20th Nov 2013
2
ITaaS Platform
We studied the business challenges of SMBs to
redefine the Technology Consumption Model On the
software side the solution was to build a set of
multi-tenant applications to leverage the SaaS
model
3
SaaS Performance Management
Introduction
  1. The SaaS platform Solution stack
  2. Performance challenges
  3. Three tier Architecture
  4. Performance optimizations for each tier
  5. SaaS Three Tier Architecture

4
ITaaS Solution Stack
Business Analytics
Niche Vertical Application Layer
Software Solution
Network Solution
Hardware Solution
Biz Services
Reward-Recognition
Virtual Community
Assessment
Customer Supplier Integration Layer
Vertical Core Applications Layer
Manufacturing
Retail
Wellness
Prof. Services
Education
CRM
FA
HRMS
Payroll
Projects
PI
Common Business Applications Layer
Document Mgmt
Online Presence Mgmt
Enterprise Intranet Mgmt
Messaging Solution
Office Mgmt Solution
Common Office Applications Layer
Networks Layer
Network Connectivity
Data Center Hosting
Network Devices
Desktop/Laptops
Hardware Layer
Printers
On Premise Servers
All System Software
5
SaaS Performance Management
Introduction
  1. The SaaS platform Solution stack
  2. Performance challenges
  3. Three tier Architecture
  4. Performance optimizations for each tier
  5. Deployment Architecture Monitoring

6
Performance Challenges
  • Can users get a fast response over the low
    bandwidth network?
  • Whether to host different solutions on different
    servers or on the same server?
  • How do we find if anything is slow in production?
  • Can the applications on the cloud scale as
    transactions and users increase?
  • Will business operations continue in face of a
    disaster?
  • Will use of Open source tools and servers serve
    the requirement?
  • How would we avoid bad code entering production?
  • How would we identify if any bad code has entered
    production?

7
SaaS Performance Management
Introduction
  1. The SaaS platform Solution stack
  2. Performance challenges
  3. Basic three tier Architecture
  4. Performance optimizations for each tier
  5. SaaS Three Tier Architecture

8
Three tier Architecture
Perimeter Security
Web Tier
Application Tier
Reports
Applications

Slave
Master
Database Tier
C1
C1
C2
C2
9
SaaS Performance Management
Introduction
  • The SaaS platform Solution stack
  • Performance challenges
  • Basic three tier Architecture
  • Performance optimizations for each tier
  • Web
  • Application
  • Database
  • SaaS Three Tier Architecture

10
Summary of achieving speed
Introduction
  • Lookup DNS
  • Make TCP Connection
  • Reduce number of TCP reconnections
  • Negotiate SSL
  • Make the negotiation quick
  • Reduce number of renegotiations
  • Send Request
  • Reduce content to be sent
  • Server Sends Response
  • Send response quickly
  • Minimize response
  • Parse Response and Download additional Resources
  • Minimize number of resources to be downloaded
  • Render Content
  • Keep content lean, clean and simple
  • Ensure all required styles for rendering are
    available at the earliest
  • Compile and execute JavaScript (Single Threaded
    Blocking)
  • Keep minimal JavaScript
  • Defer JavaScript Execution

11
Web tier Minimize round-trip times
  • What is a Round-trip time (RTT) Request time
    Response time
  • Ways to minimize RTT -
  • Minimize the number of requests
  • Avoid bad requests (e.g. 404)
  • Combine external JavaScript
  • Combine external CSS
  • Optimize the order of styles and scripts
  • Use CSS Sprites for images
  • Parallelize them
  • Parallelize downloads across hostnames (CDN)

12
Web tier Set HTTP Keep Alive
  • What is it?
  • In HTTP/1.1 the keep-alive extension allows
    persistent
  • connections . Basically the HTTP sessions allow
    multiple
  • requests to reuse the same underlying TCP
    connection.
  • Advantage?
  • Speed up latency for html documents with lots of
    static content
  • Example of Web tier setting -
  • Apache has 2 directives - KeepAlive and
    KeepAliveTimeout
  • These directives keep the connection to the Web
    server alive for a pre-defined number of requests
    or for pre-defined time period (Default 100, 15
    seconds)

Make the negotiation quick
Browsers limit the number of parallel downloads
to six - eight(per hostname over HTTP/1.1). It is
beneficial to increase the no. of concurrent
connections to reduce page load time.
13
Web tier Optimize SSL Negotiation
  1. Offload SSL Negotiation to a Hardware Device
  2. Enable SSL Session Cache
  3. Set a proper Timeout for SSL Session Cache

Make the negotiation quick
Session Timeout should be a based on the security
concerns and normal Session Time of the user
14
Web tier Minimize HTML content
Criteria Object type to use Example
Records less than 5 Radio button/Check box Male/ Female
Records rarely increase is easy to scroll choose Drop down City, State, Country
Records increase in a narrow range Limited filters to search AJAX look up (AJAX call can be triggered after certain no. of characters are typed, esp. in case of Codification) Clinic names, Site names.
Records are in thousands and can increase Many filters to search Use Lookups (popup screen) Search an item by item id, item name, store name, item type, etc
15
Web tier Pagination
  • Paginate depending on the context - need not be
    same for all screens
  • To reduce navigation show the latest/relevant
    records first
  • Leverage various Pagination design patterns

16
Web tier Filters
  • Mandate filters for reports - To narrow the
    number of records fetched.
  • Put appropriate Constraints Date field should
    always be constrained.
  • A constraint would typically require Functional
    knowledge
  • Set default for certain filters e.g. Status
    filter defaulted to Open
  • Note A file of 3 MB was downloaded with various
    bandwidths and latencies using WANEM. (WAN
    emulator). Please find its outcome and its impact
    on the end user experience

Test case Bandwidth Latency Time taken 1 114
mbps NIL 3 secs 2 128 kbps NIL 3 mins
40 secs 3 256 kbps NIL 1 min 57 secs 4 128
kbps 50 ms 4 mins 45 secs 5 256 kbps 50 ms
2 mins
(without WANEM)
Tools Tip Create an excel sheet listing all
reports names v/s its filters. This would give a
holistic view of all the filters in the solution.
It would not be relatively easy to implement
policies related to mandating and constraining
filters with some functional knowledge obviously.
17
Web tier Serve static content
  • A typical web request Static Dynamic
  • Static content - images, style sheets,
    JavaScript, html, pdf, video files, etc should be
    served by Web tier
  • Advantage
  • To avoid use of expensive Application server
    threads
  • Avoid delay to serve static content during
    Garbage collections
  • Web servers serve static content faster than
    Application servers
  • Sets stage for further static content
    consolidation and scale with use of CDN

18
Web tier Minimize round-trip times Avoid bad
requests
  • HTTP requests are expensive, making an HTTP
    request and getting a useless response (i.e. 404
    Not Found) is unnecessary. Will slow down the
    user experience.

Firefox Use add-ons like Firebug, Page Speed,
YSlow, Fiddler, For IE Fiddler
19
Web tier Minimize round-trip times Optimize
order of styles scripts
  • Correct order of external style sheets and
    external/inline scripts enables better
    parallelization of downloads and speeds up
    browser rendering time.

Scenario 1 ltheadgtltlink rel"stylesheet"
type"text/css" href"stylesheet1.css" /gtltscript
type"text/javascript" src"scriptfile1.js"
/gtltscript type"text/javascript"
src"scriptfile2.js" /gtltlink rel"stylesheet"
type"text/css" href"stylesheet2.css" /gtltlink
rel"stylesheet" type"text/css"
href"stylesheet3.css" /gtlt/headgt
Scenario 2 ltheadgtltlink rel"stylesheet"
type"text/css" href"stylesheet1.css" /gtltlink
rel"stylesheet" type"text/css"
href"stylesheet2.css" /gtltlink rel"stylesheet"
type"text/css" href"stylesheet3.css" /gtltscript
type"text/javascript" src"scriptfile1.js"
/gtltscript type"text/javascript"
src"scriptfile2.js" /gtlt/headgt
Scenario 1 the second two style sheets must wait
until the JS files are finished downloading.
Scenario 2 merely by changing the order of the
resources - 100 ms is shaved off the total
download time.
20
Web tier Minimize round-trip times Combine
external Javascripts
  • Example of the download profile of an HTML file
    containing requests for 13 different .js files
    from the same domain

All files are downloaded serially, and take a
total of 4.46 seconds to complete. Now here is
the profile for the same document, with the same
13 files collapsed into 2 files. The same 729
kilobytes now take only 1.87 seconds to
download.
Tip 0 Externalize JavaScript Tip 1 Deduplicate
JavaScript Tip 1 JavaScript files should be
combined into fewer output files (except third
party JS libraries) Tip 2 Serve the file only
when that component is requested by a user.
21
Web tier Minimize round-trip times Sprite
Images
  • CSS Sprite - A single image file that contains
    number of different images.

Without Sprite
With Sprite
Reduced 14 HTTP hits as 15 images are combined in
one single sprite improving page load time. Try
SpriteMe bookmarklet
22
Web tier Minify static content
  • Minification - Removes whitespace, Line Breaks,
    comments, Shrinks Variables Optimizes code in
    js and css files. Decreases file size improves
    page load time.

File size
File size reduction 62
Tools available - Google Closure Compiler, YUI
Compressor, JSMIN, Dean Edwards Packer, DOJO
Compressor.
23
Web tier Compress static content
  1. GZIP generally reduces the response size by about
    70.
  2. Compression may sometimes not be supported by the
    proxy setting at customer end
  3. Zipping of images, pdf or any binary file not
    done as most are already compressed

24
290304000
Web tier Cache locally to take heat off
back-end servers
  • Set suitable static content expiry in the web
    tier
  • Example
  • ExpiresActive ON
  • ExpiresByType text/javascript "access plus 1
    month
  • Cache-Control public max-age290304000
  • Use a unique identifier to append every static
    request, to refresh browser cache when the
    content changes.

Note Incase of server farms do not use Etags.
25
Web tier Ajax lookups Optimization tip
AJAX auto lookups needs to have a limit to the
characters entered before which the lookup is
shown. A lookup done for every character entered
would lead to executing a select query. Infact it
is directly proportional to the characters typed.
Assuming there is no delay. For SMB we recommend
to set it to at least 4 characters.
4 Characters entered
1 Character entered
x
?
Note Enable Caching of AJAX Requests.
- 25 -
26
Web tier Bandwidth/Latency User Experience
Impact on a transaction response time due to
Bandwidth, Latency, Browser Cache Static file
compression in Web tier.
  Response times vs. varying bandwidth/latency Response times vs. varying bandwidth/latency Response times vs. varying bandwidth/latency Response times vs. varying bandwidth/latency Response times vs. varying bandwidth/latency Response times vs. varying bandwidth/latency Response times vs. varying bandwidth/latency Response times vs. varying bandwidth/latency Response times vs. varying bandwidth/latency Response times vs. varying bandwidth/latency
  Without browser cache Without browser cache Without browser cache Without browser cache Without browser cache Without browser cache Without browser cache With cache With cache With cache
Compression On Off On On Off On On On On On
Bandwidth 57 Mbps (Without WANem) 57 Mbps (Without WANem) 64 Kbps 128 Kbps 128 Kbps 128Kbps, Latency 200msec 128Kbps, Latency 400msec 128 Kbps 57 Mbps (Without WANem) 64 kbps
Resp. time (secs) 0.61 0.98 48.38 22.89 56.88 44.82 76.09 4.18 0.38 9.81
Note Time does not include Browser rendering
or processing Web Page size With compression
260 KB, Without compression 730 KB Used TCS'
WANem (WAN Emulator)
27
Web tier Avoid Repetitive Requests
  • Communicate the system status to the user once a
    transaction is initiated.
  • Example
  • Use the loader feature which creates a grey
    transparent layer over the existing User
  • interface and does not allow the access to the
    submit button.

28
Web tier Time to test
Analysis of web service http//www.webtest.org
for http//www.tcs.com
29
SaaS Performance Management
Introduction
  • The SaaS platform Solution stack
  • Performance challenges
  • Basic three tier Architecture
  • Performance optimizations for each tier
  • Web
  • Application
  • Database
  • SaaS Three Tier Architecture

30
Typical Activity in the Application Layer
Introduction
  • Read and interpret the request parameters
  • Validate the Request Parameters
  • Read from Data Store
  • Perform Business Operations
  • Read from Data Store
  • Persist Data to Data Store
  • Form and Send the HTML Response

Optimize Processing Minimize fetches from Data
Store Fetch only Required Data
31
App tier Review default server settings
  • Server Log Level (In thread dumps, several
    threads in blocked state are observed in several
    instances where too many logs at debug, info
    logs in the code in combination with low log
    level )
  • Clients/Threads in Web, Application and Database
    tiers
  • JVM settings
  • Max File Descriptors

Notes Apache maxClients, JBoss maxThreads,
MySQL - max_connections Generally - maxClients gt
Maxthreads lt Max_connections Every layer works
with a limited number of connections and
resources (read Threads)
32
Application tier Memory allocation for JEE
Application Server
64bit JVM allows us to set higher values of heap
size
But bigger the heap, longer the major GC and
hence pause times.
OS Room for me?
33
Application tier Out of memory?
Exception in thread main java.lang.OutOfMemoryEr
ror PermGen space ? Exception in thread "main"
java.lang.OutOfMemoryError Java heap space ?
  • Jvisualvm
  • Jmap
  • GC Viewer

Heap default java -Xms32m -Xmx128m
Minor GC
Major GC
Metadata of loaded classes
Note Specific to SUN JVM. Internals may vary
depending on choice of JVM
34
Application tier Exploring jmap (Memory Map)
command
  • Heap Space -
  • 1. jmap -heap ltPIDgt
  • - To get Heap details. Here look at the section
    named - "PS Old generation" -  if its above
    80-90 we may then execute the next two commands
    in that order to get more details 
  • 2. jmap -histo ltPIDgt
  • For each Java class, number of objects, memory
    size in bytes, and fully qualified class names
    are printed. VM internal class names are printed
    with '' prefix. This helps to find who is
    occupying the heap.
  • If the live suboption is specified, only live
    objects are counted
  • Note - jmap histolive triggers a FULL GC as
    compared to jmap -histo 
  • 3. jmap -dumplive,formatb,fileltjmap_date_server
    _dump.bin gt ltPIDgt
  • jmap -dumpformatb,fileltjmap_date_server_dump.b
    in gt ltPIDgt
  • Note Depending on JVM size, the heap dump can
    be sizeable. To open the heap dump in IBM Heap
    analyzer to check leak suspects the overall VM
    memory required is generally greater than twice
    the heap dump size
  • Permanent Generation Space - jmap permstat
    ltPIDgt
  • Prints class loader wise statistics of permanent
    generation of Java heap. For each class loader,
    its name, liveness, address, parent class loader,
    and the number and size of classes it has loaded
    are printed. In addition, the number and size of
    interned Strings are printed.

35
Application tier Scale Out vs Scale up
Methods to add more resources for a particular
application fall in two broad categories.
Scale-out and Scale-up.
Simple
Complex
Applications designed to scale out will almost
always scale up, yet applications designed to
scale up will almost never scale out. Example -
Before development, we would need to think - How
do we make the Singletons and Synchronized code
blocks work across processes ?
36
Application tier Synchronous v/s Asynchronous
Communication
Phone call (Synchronous) or vs email
(Asynchronous). Lets look at options to send
emails related for alerts, notification,
reminder, etc - 1) Send email in the same
transaction Synchronous - Each request blocks
the calling thread 2) Send email by spawning a
new thread - Asynchronous - Current thread is
not blocked whilst the separate thread awaits a
response from SMTP 3) Set a flag to send email
and let the batch job do the needful -
Asynchronous - A batch process wakes up after
set time gt Checks a status flag sends emails
in configurable batch mode (i.e. throttle the
traffic (count of emails) to be sent (with or
without priority) ) Note Configuration would
depend on capacity of SMTP server and/or traffic
at that instance. Also, here optimization
techniques like query tuning would be important.
37
Application tier Server side caching mechanisms
  • In JVM
  • Occupies precious JVM heap space
  • May trigger early frequent Garbage Collection
  • Can slow down and crash system
  • Not easy to replicate changes across JVMs in a
    cluster
  • Out of JVM
  • Relatively slower
  • Will overcome all the above mentioned problems

38
Application tier Server side caching mechanisms
  1. Memcached
  2. CouchBase/ Membase (A fork of memcached)
  3. Redis from Google
  4. Infinispan from JBoss
  5. Terracotta (now from Software AG)
  6. Coherence from Oracle
  7. Gemfire from Gemstone

39
Application tier Use latest stable libraries
  • Dos donts
  • Avoid duplicates jar files
  • Avoid multiple version of same jar files
  • Remove unwanted jars
  • Use latest stable versions of library files
  • Use Server default Library NOT Application library

40
Application tier Sticky Sessions
  • Session Identifies a User
  • Needs replication in clustered environment
  • Should NOT be used for storing large data
  • Session has a time out parameter
  • Sticky sessions should be enabled

41
Application tier String concatenation
Method Purpose
Built-in concatenation () operator To concatenate static strings String s1 "aa" "bb"
String.concat() To concatenate two strings
StringBuffer Is a synchronized class To be used in a multithreaded environment (when more than one thread access the same StringBuffer instance).
StringBuilder (Added in Java 5) Identical in all respects to StringBuffer except that is NOT synchronized, which means that if multiple threads are accessing it at the same time, there could be trouble (Not thread safe). To be used in places where string concatenation is to be done by a single thread
42
Application tier XML Parsing ? Memory is limited
High level differences between DOM parser and SAX
Parser in Java 1) DOM parser loads whole xml
document in memory while SAX only loads small
part of XML file in memory. 2) DOM parser is
faster than SAX because it access whole XML
document in memory. 3) SAX parser in Java is
better suitable for large XML file than DOM
Parser because it doesn't require much
memory. 4) DOM parser works on Document Object
Model while SAX is an event based xml
parser. Thumb rule Use DOM parser over SAX
parser if XML file is small enough and go with
SAX parser if you dont know size of xml files to
be processed or they are large.
43
Application tier File Handling (Leverage
stream-chaining techniques)
FileReader (DataInputStream - deprecated)-
Common and simple method to read a file but is
extremely slow. The reason for the poor
performance is that the DataInputStream class
does no buffering. The resulting reads are done
one byte at a time.For e.g. One of the
benchmark says that to read a 250 KB file it took
28,198 milliseconds BufferedReader
(BufferedInputStream-deprecated) A simple
improvement involves buffering the
FileInputStream by interposing a
BufferedInputStream in the stream chain. This
buffers the data, with the default buffer size of
2048 bytes Result - The resulting performance
increase for the medium sized file (250
kilobytes) was 91, from 28,198 milliseconds to
2,510 -- over an order of  magnitude with just a
simple change i.e. Example - try
BufferedReader in new BufferedReader(new
FileReader(argsi), 8192) while
((line in.readLine()) ! null)
nlines catch (Exception e)
System.out.println(" BR8192Test
exception" e ) finally in.close()
Note - The buffer size used in buffering
schemes is important for performance. As a rule
of thumb, bigger is better to a point. Refer -
http//www.kegel.com/java/wp-javaio.html. Match
the buffer size to the underlying storage sector
size. Adopt similar strategy for writing to files.
44
Application tier Blocking API - Synchronized
Blocking/Slow API
JVM
  • Note In case of Multiple JVM scenario there is
    no default JVM synchronization between the
    Application server instances. Hence, usage of
    Sync blocks should be done wisely and at granular
    level

45
Application tier Static Code Review
Commit Code
Commit Code
Project Code
Publish reports
Central Build Machine
  1. Compile
  2. Static Code Review
  3. Copy Paste instances
  4. Design analysis
  5. JUnit/Code coverage

John runs Static Code review locally
46
Application tier An approach to find time taken
by request on each tier
  • Use Non-intrusive code weaving (Aspect Oriented
    Programming
  • Available for
  • Java
  • .Net
  • Weave at run time
  • Weave at compile time
  • Can build all-inclusive monitoring
  • Not dependent on any framework
  • But can leverage standards like Servlet API, JDBC
    API etc

47
Application tier An approach to find time taken
by request on each tier
Web Layer
Business Layer
Data Access Layer
Capture start Time, IP Address, Port, Request URL
SQL, SQL Start Time, SQL End Time Request End
Time

DB
Capture query end time
Capture end time
JBoss
  1. For each request a unique thread is assigned by
    the Application server
  2. For each thread a Statistic Entity Object is
    created and its relationship maintained
  3. Using Unique thread id retrieve the Statistics
    Entity object at each layer and fill the
    respective attributes
  4. Once request is finished calculate time taken to
    process request, time taken to execute sql
    statement for respective URL
  5. Convert summary information in to string and
    stored it in the Collection object.
  6. Flush the thread and object relationship
  7. At periodic interval a service saves the
    collection object to a log file

48
Application tier Fault Isolation Architectural
Structure Swim Lanes
There are four general principles for designing
and implementing swim lanes in a systems
architecture 1) There must not be any
shared hardware or software between lanes other
than possibly highly available network gear
such as paired loadbalancers or border routers.
(Nothing is shared) 2) No synchronous calls
can take place between swim lanes. If cross swim
lane communication is required, i.e. grabbing
search results to display on the same page as
login, it must be done asynchronously. (Nothing
crosses a swim lane boundary, Transactions occur
along swim lanes) 3) Limit asynchronous
communication. While permitted, more calls lead
to a greater chance of failure propagation. 4)
Use timeouts with asynchronous calls. There is
no need to tie up the users browser or your
server waiting for the eventual TCP timeout.
Note - Swim lane the money maker, Swim lane the
problem areas, Swim lane natural barriers
49
SaaS Performance Management
Introduction
  • The SaaS platform Solution stack
  • Performance challenges
  • Basic three tier Architecture
  • Performance optimizations for each tier
  • Web
  • Application
  • Database
  • SaaS Three Tier Architecture

50
Database tier Check for Open database
connections
  • Database memory requirement primarily depends on
  • Memory allocated per connection (Limited
    resource)
  • Global memory
  • Memory required for background processes.
  • To identify connection leaks at various levels
  • Static code review
  • Verify pattern Connect Query Quit in dB
    general logs
  • Consolidate database connection closure code in
    framework itself
  • Use AOP to find Line of Code that invoked an open
    database connection or auto close it
  • Kill any idle connections for more than specified
    time -Server policy

51
Database tier Reduce table joins
  • Requirement To fetch list of all products sold,
    along with their rate, quantity, sell date and
    customer to whom products were sold
  • Typical Join
  • Customer Master (100000)
  • Product Master (100000)
  • Bill Header (100000)
  • Bill Details (500000) (Five items per bill)

52
Database tier Reduce table joins
  • Instead
  • Join only Bill Header and Bill Details
  • Fetch the Customer Name, and the Product Name
    from a cache of Hashmaps
  • Customer Id Customer Name
  • Product Id Product Name

53
Database tier Track slow queries
Select from emp

C1
C2
gt1 second
  • Optimize queries that
  • repeatedly run slow
  • examine lot of records
  • fetch lot of records
  • take more time to execute
  • take up locks for long time

Slow Query Log
54
Database tier Avoid full table scans
  • Full table scans are where the database will read
    the entire table without an index.
  • Reasons why full table scans are performed
  • no WHERE clause
  • no index on any field in WHERE clause
  • poor selectivity on an indexed field
  • too many records meet WHERE conditions
  • using SELECT FROM
  • function used on the indexed column in the query

Generate Explain plans to understand how database
query optimizer chooses to execute a query
55
Database tier Consider chunk at a time v/s row
at a time
ConnectionID_1 INSERT INTO table(A,B)
values(1,2) ConnectionID_1 Quit ConnectionID_2
INSERT INTO table(A,B) values(3,4) ConnectionID_2
Quit
  • One insert - one connection
  • All inserts one connection
  • Batch Insert one connection
  • Prepared Inserts one connection
  • Good for repeated inserts
  • Extended Inserts one connection
  • Good for bulk Insertion

ConnectionID_1 INSERT INTO table(A,B)
values(1,2) ConnectionID_1 INSERT INTO
table(A,B) values(3,4) ConnectionID_1 Quit
better
Batch start ConnectionID_1 INSERT INTO
table(A,B) values(1,2) ConnectionID_1 INSERT
INTO table(A,B) values(3,4) Batch
end ConnectionID_1 Quit
Begin Transaction ConnectionID_1 INSERT INTO
table(A,B) values(?,?) Set Value (1, 2)
Execute SetValue(3,4) Commit Transaction Connect
ionID_1 Quit
ConnectionID_1 INSERT INTO table(A,B)
values(1,2),(3,4) ConnectionID_1 Quit
In case of MySQL extended insert one connection
technique is seen the fastest. Note Need to
watch out on the limit on size of the query and
regular commits should be done after set
frequency to avoid large rollbacks. Use Prepared
Statement and Bulk Commit
56
Database tier Generate Explain plans
Developer Query works fast in my environment
but is slow in Production, is something different
there?
  • DBA -
  • Records in development environment less than
    production
  • Optimizers perspective matters than yours
  • Recommendation -
  • Generate a Query execution plan to understand the
    execution plan chosen by the database optimizer.
  • An execution plan (Explain plan) helps to
    understand
  • Number of rows examined
  • Use of indexes
  • Missing indexes
  • Type of join
  • Information on sorting, etc

57
Database tier Stored Procedures
  • Set of SQL statements stored on the server and
    are pre-compiled. It takes in
  • certain arguments and processes that code with
    those arguments at
  • execution time
  • Points to ponder before we use Stored Procedures
  • Ease to scale database compared to application
    tier?
  • Ease to write and maintain?
  • Ease to debug
  • Need for specialized skill set
  • Performance gain
  • Reduction in traffic between application and
    database tier
  • Reusability transparency
  • Security

58
Database tier Use prepared statements
  • Prepared statements are the ability to set up a
    statement once, and then execute it
  • many times with different parameters.
  • Advantages
  • Save on query parsing (especially if we execute
    the query several times)
  • Prepared statement caching inside the J2EE server
    connection pool avoids re-preparing of the
    statement
  • Cache is database-wide Improves efficiency
    across applications if they all use similar
    parameterized SQL

59
Database tier Application tier switch for
Database servers
  • Good Practice For Multi-Tenanted Applications
  • Provide an Application level switch that can
    dynamically select the database to connect which
    itself may reside on one more database instances

60
System File descriptors
  • Linux limits the number of file descriptors that
    any one process may open the default limits are
    1024 per process which generally is not
    sufficient for production use
  • Plan to set this to a value which is more than
    the maximum number of TCP connections expected on
    the server.

61
Introduction
SaaS Three Tier Architecture Consolidate Scale
F5 BIG-IP Local Traffic Manager
Web Tier
Application Tier
Reports
Applications


Database Tier
C1
C1
C2
C2
62
SaaS Three Tier Architecture Consolidate Scale
Perimeter Security
Web Tier
Application Tier
Reports
Applications
Cloud Capacity increases to serve more users and
is resilient to failures
Database Tier
63
Static Request
Dynamic Request
Report Request
SaaS Three Tier Architecture Caching
Use browser cache
Static Request
Dynamic Request
Perimeter Security
Cached Data
Web Tier
Compress Static Content
Application Tier
Reports
Cache-enabled Browser
Server Cache
Cached Data
Applications
Minified compressed Static content served by
Web tier and cached by browser with appropriate
version


Database Tier
C1
C1
C2
C2
Reports
Transactions
64
SaaS Architecture Monitoring Production Servers
Performance counters on Production Servers
monitored using TCSMonIT
65
SaaS Architecture Monitoring Remote Machines
(On-premise)
Administer from any location
Audit
Monitor
Install Software
Experts connect remotely for immediate support
Remote backup
66
SaaS Architecture Business Continuity
SaaS users continue to operate in face of disaster
About PowerShow.com