38
www.alachisoft.com 1 Four Ways to Improve ASP.NET Performance & Scalability with In - Memory Distributed Cache Iqbal Khan [email protected] Ph: +1 (925) 236 - 2125 Alachisoft .NET Performance Solutions

Four Ways to Improve ASP .NET Performance and Scalability

Embed Size (px)

Citation preview

www.alachisoft.com 1

Four Ways to Improve

ASP.NET

Performance & Scalability

with In-Memory Distributed Cache

Iqbal [email protected] Ph: +1 (925) 236-2125

Alachisoft

.NET Performance Solutions

Alachisoft

NCache 2www.alachisoft.com

It scales nicely to handle

tens of thousands of concurrent users

ASP.NET is Popular

for

High Traffic Web Apps

Alachisoft

NCache 3www.alachisoft.com

Typical ASP.NET Web Farm Deployment

Mainframe

Load Balancer

ASP.NET

Session Storage

ASP.NET Web Farm

Scale Horizontally

Web Clients

...

Database Servers

Alachisoft

NCache 4www.alachisoft.com

The Problem

Cause application slow-down

or even crash

Scalability Bottlenecks

Alachisoft

NCache 5www.alachisoft.com

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

Alachisoft

NCache 6www.alachisoft.com

Two Data Storage Bottlenecks

Alachisoft

NCache 7www.alachisoft.com

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

Alachisoft

NCache 8www.alachisoft.com

ASP.NET View State Bottleneck

Mainframe

Load Balancer

ASP.NET

Session Storage

ASP.NET Web Farm

Scale Horizontally

Web Clients

...

Database Servers

Heavy Payload

(ASP.NET View State)

Heavy Payload

(ASP.NET View State)

Alachisoft

NCache 9www.alachisoft.com

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

Alachisoft

NCache 10www.alachisoft.com

Extra Page Execution Bottleneck

Mainframe

Load Balancer

ASP.NET

Session Storage

ASP.NET Web Farm

Scale Horizontally

Web Clients

...

Database Servers

Heavy Payload

(ASP.NET View State)

Heavy Payload

(ASP.NET View State)

Extra Page Executions

(on static output)Extra Page Executions

(on static output)

Alachisoft

NCache 11www.alachisoft.com

In-Memory Distributed Cache

The Solution

NCache

Alachisoft

NCache 12www.alachisoft.com

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

Alachisoft

NCache 13www.alachisoft.com

NCache: In-Memory Distributed Cache

Filesystem Database Servers Mainframe

Distributed Cache Cluster

Windows 2008/2012 (64-bit)

Scale Horizontally

Memory pooled from all cache servers

Big Data Apps

(.NET)WCF Web Services .NET Server AppsASP.NET Web Apps

Alachisoft

NCache 14www.alachisoft.com

NCache Performance Benchmarks

Alachisoft

NCache 15www.alachisoft.com

ASP.NET Optimizationswith 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

Alachisoft

NCache 16www.alachisoft.com

ASP.NET Session State Storage

Alachisoft

NCache 17www.alachisoft.com

ASP.NET View State Cache

Alachisoft

NCache 18www.alachisoft.com

ASP.NET Output Cache

Alachisoft

NCache 19www.alachisoft.com

App Data Caching

Alachisoft

NCache 20www.alachisoft.com

Overview of Caching API

Connect & Disconnect from the Cache Cache cache = NCache.InitializeCache(“myReplicatedCache”);

cache.Dispose();

Read from the Cache object obj = cache.Get(“myKey”);

object obj = cache[“myKey”];

bool isPresent = cache.Contains(“myKey”);

Add to the Cache cache.Add(“myKey”, obj);

cache.Insert(“myKey”, obj);

cache[“myKey”] = obj;

Remove from the Cache object obj = cache.Remove(“myKey”);

Empty the Cache cache.Clear();

Alachisoft

NCache 21www.alachisoft.com

NCache Architecture

1. High Availability (100% Uptime) Peer to peer cluster

Dynamic configuration

2. Scalability: Caching Topologies Mirrored, Replicated, Partitioned, and Partition-Replica Cache

Alachisoft

NCache 22www.alachisoft.com

Cache Elasticity (100% Uptime)Dynamic Cache Cluster

Cache Cluster

NCache Srv

Add

Server

At

Runtime

Remove

Server

At

Runtime

NCache Srv NCache Srv

Remote Clients (Web/App Servers) 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

Alachisoft

NCache 23www.alachisoft.com

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

Dynamic Cache Cluster

NCache Srv

Remote Clients (Web/App Servers)

NCache SrvNCache Srv

Cluster

Membership Info

Cache

Topology Info

Alachisoft

NCache 24www.alachisoft.com

Caching TopologiesMirrored Cache (2-node active/passive)

Server 1 Server 2

Mirrored Cache

1 2

3 4

5 6

Active

1 2

3 4

5 6

Passive

(Backup)

Async Backup

Remote Clients (Web/App Servers)

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

Alachisoft

NCache 25www.alachisoft.com

Caching TopologiesReplicated 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.

Good for read-intensive scenarios Server 1 Server 2

Replicated Cache

1 2

3 4

5 6

Active

Synchronous Updates

Remote Clients (Web/App Servers)

1 2

3 4

5 6

Active

Alachisoft

NCache 26www.alachisoft.com

Caching Topologies Partitioned Cache

Extremely scalable

Location transparency

Good for large cache clusters

Distribution map sent to all clients at runtime

No replication available

Server 1 Server 2

Partitioned CacheRemote Clients (Web/App Servers)

21

Partition 1

43

Partition 2

Distribution

Map

Distribution

Map

Alachisoft

NCache 27www.alachisoft.com

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

Server 1 Server 2

Partition-Replica CacheRemote Clients (Web/App Servers)

21

Partition 1

43

Replica 2

43

Partition 2

21

Replica 1

Distribution

Map

Distribution

Map

Alachisoft

NCache 28www.alachisoft.com

Caching TopologiesClient Cache

Web/App Server

(Client Node) ... Web/App Server

(Client Node)

Cache Cluster

NCache Client Nodes

Server 1 Server 2

Server 3

Dynamic Clustered Cache

Cached Item

1 2

3 4

5 6

1 2

3 4

5 6

1 2

3 4

5 6

Client Cache Client Cache

SynchronizedSynchronized

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

Alachisoft

NCache 29www.alachisoft.com

Hands on Demo

Alachisoft

NCache 30www.alachisoft.com

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

Alachisoft

NCache 31www.alachisoft.com

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

Alachisoft

NCache 32www.alachisoft.com

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

Alachisoft

NCache 33www.alachisoft.com

Data Grouping in the Cache

Group/Subgroup

Tags

Named Tags

Alachisoft

NCache 34www.alachisoft.com

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

Alachisoft

NCache 35www.alachisoft.com

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

Alachisoft

NCache 36www.alachisoft.com

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

Alachisoft

NCache 37www.alachisoft.com

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

Alachisoft

NCache 38www.alachisoft.com

Next Steps

Download NCache 60-Day Trial (Fully Working) http://www.alachisoft.com/download.html

Contact us for Personalized Architectural Demo Email: [email protected]. Phone: +1 (925) 236-3830