Scaling API-first – The story of a global engineering organization
Four Ways to Improve ASP .NET Performance and Scalability
1. Alachisoft
.NET Performance Solutions
Four Ways to Improve
ASP.NET
Performance & Scalability
with In-Memory Distributed Cache
Iqbal Khan
iqbal@alachisoft.com Ph: +1 (925) 236-2125
www.alachisoft.com 1
2. Alachisoft
ASP.NET is Popular
for
High Traffic Web Apps
It scales nicely to handle
tens of thousands of concurrent users
NCache www.alachisoft.com 2
3. Alachisoft
Typical ASP.NET Web Farm Deployment
Mainframe
Load Balancer
Web Clients
ASP.NET Web Farm
ASP.NET
Session Storage
Scale Horizontally
...
Database Servers
NCache www.alachisoft.com 3
4. Alachisoft
The Problem
Scalability Bottlenecks
Cause application slow-down
or even crash
NCache www.alachisoft.com 4
5. Alachisoft
Two Data Storage Bottlenecks
1. App Database cannot Scale
Cannot add more database servers
Database slows down with more load
2. ASP.NET Session State Storage has Problems
InProc (inside worker process):
Cannot handle web garden (multiple worker processes)
Requires “sticky session bit” in the load balance
Session data loss if a web server goes down
StateServer (stand-lone server):
Slow performance and cannot scale
Session data loss if a StateServer goes down
SqlServer
SQL Server not ideal for storing BLOBs
Performance and scalability issues
NCache www.alachisoft.com 5
7. Alachisoft
ASP.NET View State Bottleneck
1. ASP.NET View State Travels to the Browser
As a hidden string with HTTP Response
Browser returns it to web server on HTTP Post Back
2. ASP.NET View State is Usually Heavy
100’s of KB per txn multiplied by millions of txn
3. Slows Page Response Time
Page response times slow down
4. Increases Bandwidth Consumption Cost
You’re paying for bandwidth consumption
Cost increases significantly
NCache www.alachisoft.com 7
8. Alachisoft
ASP.NET View State Bottleneck
Heavy Payload
(ASP.NET View State)
Mainframe
Load Balancer
Web Clients
Heavy Payload
(ASP.NET View State)
ASP.NET Web Farm
ASP.NET
Session Storage
Scale Horizontally
...
Database Servers
NCache www.alachisoft.com 8
9. Alachisoft
Extra Page Execution Bottleneck
1. Page Output does not Change in Many Cases
Entire page output is the same
Portions of an otherwise dynamic page are static
2. ASP.NET Executes Pages Regardless
Page is executed even though output does not change
3. Slows Page Response Time
Page response times slow down
4. Increases Infrastructure Cost
Extra CPU, memory, and database resources are consumed
Capacity from same set of resources is reduced
NCache www.alachisoft.com 9
10. Alachisoft
Extra Page Execution Bottleneck
Heavy Payload
(ASP.NET View State)
Mainframe
Load Balancer
Web Clients
Heavy Payload
(ASP.NET View State)
ASP.NET Web Farm
ASP.NET
Session Storage
Scale Horizontally
...
Database Servers
Extra Page Executions
(on static output)
Extra Page Executions
(on static output)
NCache www.alachisoft.com 10
12. Alachisoft
What is In-Memory Distributed Cache?
1. Cluster of inexpensive cache servers
Pools their memory and CPU
2. Synchronizes cache updates across the cluster
Cache updates immediately visible in the cluster
3. Linearly scales transaction & memory capacity
Just add cache servers to the cluster
4. Intelligently replicates data for reliability
Without compromising performance & scalability
NCache www.alachisoft.com 12
13. Alachisoft
NCache: In-Memory Distributed Cache
ASP.NET Web Apps WCF Web Services .NET Server Apps
Distributed Cache Cluster
Memory pooled from all cache servers
Scale Horizontally
Windows 2008/2012 (64-bit)
Filesystem Database Servers Mainframe
Big Data Apps
(.NET)
NCache www.alachisoft.com 13
15. Alachisoft
ASP.NET Optimizations
with Distributed Cache
1. App Data Caching (for Database Bottlenecks)
In-memory cache faster than database
Cache linearly scalable which database is not
2. ASP.NET Session State Storage (Reliability)
Sessions are replicated for reliability
Cache is fast and scalable
3. ASP.NET View State Cache
Cache on server-side and reduce payload size
4. ASP.NET Output Cache
Cache page output
Avoid page re-execution
NCache www.alachisoft.com 15
22. Alachisoft
Cache Elasticity (100% Uptime)
Dynamic Cache Cluster
Cache Cluster
Remote Clients (Web/App Servers)
Add
Server
At
Runtime
NCache Srv
Remove
Server
At
Runtime
NCache Srv NCache Srv
TCP based Cache Cluster
Does not use Windows Clustering
Peer to peer architecture
No single point of failure
Add/remove servers at runtime
Without stopping cache or your app
Data adjusted automatically based
on caching topology
Hot Apply config changes
Change config properties while
cache is running
NCache www.alachisoft.com 22
23. Alachisoft
Cache Elasticity (100% Uptime)
Dynamic Configuration
Cluster membership info
Propagate to clients at runtime
Cache topology info
Propagate to clients at runtime
Connection strategy at runtime
Connection failover
Clients auto-connect to other servers
NCache Srv
Remote Clients (Web/App Servers)
Membership Info
NCache Srv NCache Srv
Cache
Topology Info
Dynamic Cache Cluster
Cluster
NCache www.alachisoft.com 23
24. Alachisoft
Caching Topologies
Mirrored Cache (2-node active/passive)
Mirrored Cache
Remote Clients (Web/App Servers)
Server 1 Server 2
1 2
3 Active
4
5 6
1 2
Passive
(Backup)
3 4
5 6
Async Backup
All clients connect to active node
Passive node becomes active if
active node goes down. Clients
also automatically connect to new
active node
Mirroring to passive node done
asynchronously
Recommended use:
Up to 10 app servers
2 cache server cluster
NCache www.alachisoft.com 24
25. Alachisoft
Caching Topologies
Replicated Cache
Each server has the entire cache
Cache updates done to all servers
synchronously. So, they’re slower.
Each clients connects to only one
cache server. All servers active.
Replicated Cache
Remote Clients (Web/App Servers)
Good for read-intensive scenarios Server 1 Server 2
1 2
3 Active
4
5 6
1 2
3 Active
4
5 6
Synchronous Updates
NCache www.alachisoft.com 25
26. Alachisoft
Caching Topologies
Partitioned Cache
Extremely scalable
Location transparency
Good for large cache clusters
Distribution map sent to all clients
at runtime
No replication available
Partitioned Cache
Remote Clients (Web/App Servers)
Distribution
Partition 1
1 2
Distribution
Partition 2
3 4
Server 1 Server 2
Map
Map
NCache www.alachisoft.com 26
27. Alachisoft
Caching Topologies
Partition-Replica Cache
Each partition has one replica on a
different server. All created
automatically.
Async & Sync replication options
Extremely fast & scalable
Reliability due to replicas
Partition-Replica Cache
Remote Clients (Web/App Servers)
Distribution
Partition 1
1 2
Replica 2
3 4
Distribution
Partition 2
3 4
Replica 1
1 2
Server 1 Server 2
Map
Map
NCache www.alachisoft.com 27
28. Alachisoft
Caching Topologies
Client Cache
NCache Client Nodes
Web/App Server
... Web/App Server
(Client Node) (Client Node)
Client Cache Client Cache
Synchronized Synchronized
Cache Cluster
Dynamic Clustered Cache
Server 1 Server 2
3 4
Server 3
3 4
1 2
5 6
1 2
3 4
5 6
Cached Item
1 2
5 6
Local cache on client nodes (in-process
and out-of-process)
Automatically synchronizes with
clustered cache. Optimistic &
pessimistic synch options.
No special programming needed.
Plug in thru config changes.
Good for read-intensive scenarios
NCache www.alachisoft.com 28
30. Alachisoft
Some Object Caching Features
Expirations
Absolute-time + idle-time
Auto-reload data on expiration (if read-thru enabled)
Locking (Pessimistic & Optimistic)
Lock/Unlock for pessimistic locking (writer-lock)
Object versioning for optimistic locking (reader-lock)
Bulk Operations
Bulk Get, Add, Insert, and Remove
Async Operations
Async Add, Insert, and Remove
NCache www.alachisoft.com 30
31. Alachisoft
Handling Relational Data in Cache
Cache Dependency
Key based
One-to-one, one-to-many, and many-to-many
Let cache manage relationships for you
Cache invalidates related data when a cached item is updated/removed
NCache www.alachisoft.com 31
32. Alachisoft
Synchronize Cache with Data Sources
Synchronize with Relational Databases (SQL, Oracle, etc.)
SqlDependency
OracleDependency
DbDependency
Synchronize with non-Relational Data Sources
File based Cache Dependency
Custom Cache Dependency
NCache www.alachisoft.com 32
33. Alachisoft
Data Grouping in the Cache
Group/Subgroup
Tags
Named Tags
NCache www.alachisoft.com 33
34. Alachisoft
Searching the Cache
Parallel Queries with Object Query Language (OQL)
SQL-like query language to search cache based on object attributes
Parallel LINQ Queries
Standard LINQ queries can search the cache
Indexing Object Attributes for Querying
Create indexes on object attributes to speed up queries
NCache www.alachisoft.com 34
35. Alachisoft
Read-thru, Write-thru, Write-behind
Read-through and write-through
You implement read-thru and write-thru handlers called by NCache
Write-behind
Write-through has write-behind option that queues up database updates
Database update queue replicated to multiple servers for reliability
Reload Items on Expiration or Db Sync
Use Read-thru to reload item from its data source instead of removing it
NCache www.alachisoft.com 35
36. Alachisoft
Runtime Data Sharing with Messaging
Key Based Event Notifications
Register interest in specific cached items to be notified at insert/remove
Register interest to be notified at ALL add/insert/remove (off by default)
Send custom notifications to other NCache clients (cluster wide)
General Purpose Event Notifications
Register interest to be notified at ALL add/insert/remove (off by default)
Custom Event Notifications
Apps fire custom event notifications into NCache cluster
Other apps are notified
Continuous Queries Events
SQL-Like query to specify dataset
Event notifications fired when dataset changes in the cache cluster
NCache www.alachisoft.com 36
37. Alachisoft
Some Other Features
NHibernate L2 Cache Provider
Plug into NHibernate application without any code change
Entity Framework L2 Cache
Plug into Entity Framework application without any code change
Dynamic Compact Serialization
Faster and more compact then regular .NET serialization
No code writing required
NCache www.alachisoft.com 37
38. Alachisoft
Next Steps
Download NCache 60-Day Trial (Fully Working)
http://www.alachisoft.com/download.html
Contact us for Personalized Architectural Demo
Email: sales@alachisoft.com. Phone: +1 (925) 236-3830
NCache www.alachisoft.com 38