www.alachisoft.com 1
Runtime Data Sharing
through
a Distributed Cache
Iqbal Khan [email protected] Ph: +1 (925) 236-2125
Alachisoft .NET Performance Solutions
Alachisoft
NCache 2 www.alachisoft.com
What is Runtime Data Sharing?
1. Server Apps Sharing Application Data Changes Connected to a relational database
Data changed in the database and then shared
2. Server Apps Sharing Transient Data This data is never stored in the database
Data is created at runtime, shared, and then destroyed
3. Server Apps Mix of .NET and Java Data sharing may be between .NET and Java apps as well
Alachisoft
NCache 3 www.alachisoft.com
Traditional Data Sharing Mechanisms
1. Relational Databases Polling
Database notifications (SQL Server Query Notifications or Oracle Database Change Notifications)
Performance and scalability issues
2. Message Queues Message focused (not data focused)
Not intended for large data sets
Performance and scalability issues
3. Web Services or Remote Procedure Calls Too complicated to develop and manage
Weakness: sender and receiver not decoupled
Alachisoft
NCache 4 www.alachisoft.com
Use
Fast & Scalable
Distributed Cache
The Solution
NCache
Alachisoft
NCache 5 www.alachisoft.com
What is a Distributed Cache?
1. Cluster of cache servers Pools their memory and CPU
2. Synchronizes cache across all servers Updates immediately visible
3. Linearly scales transaction & memory capacity Add servers to grow capacity
4. Replicates data for reliability Without compromising performance & scalability
Alachisoft
NCache 6 www.alachisoft.com
Distributed Cache Deployment Architecture
Filesystem Database Servers Mainframe
Distributed Cache Cluster
Windows 2008/2012 (64-bit)
Scale Horizontally
Memory pooled from all cache servers
Grid Computing Apps
(.NET/Java)Web Services (.NET/Java) Server Apps (.NET/Java)Web Apps (.NET/Java)
Alachisoft
NCache 7 www.alachisoft.com
Following Apps use Distributed Cache
1. Web Apps (.NET & Java) To handle millions of users
2. Web Services (.NET & Java) To handle millions of requests
3. Big Data Apps (.NET & Java) To quickly process very large amounts of data thru distribution
4. Grid Computing Apps (.NET & Java) To process very large computations thru distribution
5. Other Server Apps (.NET & Java) To handle millions of requests
Alachisoft
NCache 8 www.alachisoft.com
Three Common Uses of Distributed Cache
1. App Data Caching (for Database Bottlenecks) In-memory cache faster than database
Cache linearly scalable which database is not
2. Reliable & Scalable Cache for ASP.NET Specific Data ASP.NET Session State storage (most common)
ASP.NET View State cache
ASP.NET Output Cache provider
3. Scalable Runtime Data Sharing Faster & more scalable than traditional message queues
Async data sharing in producer/consumer model
Powerful event notifications & continuous queries for app coordination
Alachisoft
NCache 9 www.alachisoft.com
Scalable Event Notifications for Data Sharing
Alachisoft
NCache 10 www.alachisoft.com
Event Notification Types for Data Sharing
1. Event Notifications between .NET and Java Apps .NET and Java apps can send event notifications to each other
2. Data Focused Event Notifications Whenever some data in the cache changes
3. Message Based Event Notifications Publish/subscribe model
Message sent to one or more subscribers
Alachisoft
NCache 11 www.alachisoft.com
.NET and Java App Event Notifications
1. Binary Portable Format Data and messages in the cache can use Binary Portable Format
.NET objects can be read back as Java objects and vice versa
No XML based costly transformations needed
2. Events Notifications between .NET & Java Apps .NET and Java apps can send event notifications to each other
Alachisoft
NCache 12 www.alachisoft.com
Data Focused Event Notifications
1. Item Level Event Notifications When specific cached items change (update/remove)
2. Group Level Event Notifications When any data in a group changes (add/update/remove)
NCache 4.6 will have this feature
3. Cache Level Event Notifications When any data in the cache changes (add/update/remove)
4. Continuous Query Event Notifications When any data in a dataset in the cache changes (add/update/remove)
Dataset defined through SQL-like criteria
Alachisoft
NCache 13 www.alachisoft.com
Item Level Event Notifications
// Define and item level event handler function static void OnCacheDataModification (string key, CacheEventArg args) { switch(args.EventType) { case EventType.ItemRemoved:
break; case EventType.ItemUpdated:
break; } }
// Register item level event handler function with a “key” CacheDataNotificationCallback dataNotificationCallback
= new CacheDataNotificationCallback( OnCacheDataModification ); CacheEventDescriptor EventDescriptor
= cache.RegisterCacheNotification (key, dataNotificationCallback, EventType.ItemRemoved | EventType.ItemUpdated, EventDataFilter.DataWithMetadata);
Alachisoft
NCache 14 www.alachisoft.com
Cache Level Event Notifications
// Define the event handler function static void OnCacheDataModification (string key, CacheEventArg args) { switch(args.EventType) { case EventType.ItemAdded:
break; case EventType.ItemRemoved:
break; case EventType.ItemUpdated:
break; } } // Register event handler function CacheDataNotificationCallback dataNotificationCallback
= new CacheDataNotificationCallback ( OnCacheDataModification ); CacheEventDescriptor EventDescriptor = cache.RegisterCacheNotification (
dataNotificationCallback, EventType.ItemAdded | EventType.ItemRemoved | EventType.ItemUpdated, EventDataFilter.DataWithMetadata );
Alachisoft
NCache 15 www.alachisoft.com
Continuous Query Event Notifications
string queryStr = "Select ClassLibrary.Product WHERE this.supplier = ?"; Hashtable values = new Hashtable(); values.Add("supplier", "Carlos Diaz"); ContinuousQuery cq = new ContinuousQuery(queryStr, values); cq.RegisterNotification (
new QueryDataNotificationCallback (ItemAddedCallBack), EventType.ItemAdded, EventDataFilter.None );
cq.RegisterNotification (
new QueryDataNotificationCallback(QueryItemCallBack), EventType.ItemUpdated | EventType.ItemRemoved , EventDataFilter.None);
cq.RegisterClearNotification (
new ContinuousQueryClearCallback(CacheClear));
cache.RegisterCQ ( cq );
Alachisoft
NCache 16 www.alachisoft.com
Message Based Event Notifications
1. App Generated Custom Event Notifications Publish/subscribe model
App fires a notification into cache cluster, other apps receive it
2. Topic Based Event Notifications Publish/subscribe model
Publisher sends a message against a topic to multiple subscribers
NCache 4.6 will have this feature
3. Queue Based Event Notifications Publish/subscribe model
Publisher sends a message to any one subscriber through cache cluster
NCache 4.6 will have this feature
Alachisoft
NCache 17 www.alachisoft.com
App Generated Event Notifications
// Define a callback function void CacheCustomEvent(object eventId, object data) { } Product product = new Product(); // Registering custom event callback function cache.CustomEvent += new CustomEventCallback(CacheCustomEvent); //Raise custom event when needed cache.RaiseCustomEvent("custom event id", product);
Alachisoft
NCache 18 www.alachisoft.com
Hands on Demo
Alachisoft
NCache 19 www.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 20 www.alachisoft.com
High Availability (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 21 www.alachisoft.com
High Availability (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 22 www.alachisoft.com
Caching Topologies Mirrored 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 23 www.alachisoft.com
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.
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 24 www.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 25 www.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 26 www.alachisoft.com
Conclusion
1. Distributed Cache is Better for Runtime Data Sharing Faster and more scalable
Likely to be already available for your app
2. NCache is the leading distributed cache for .NET More feature rich product in the market
Alachisoft
NCache 27 www.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
Top Related