Windows Server appfabric caching

Source: Internet
Author: User

This appfabric caching is much more complicated than the memcached I have used. msdn has an article about introduction to caching with Windows Server appfabric (Beta 1). There are many headers here, till now it is still vague. This article is mainly about some concepts and may be incorrect. You are welcome to point it out.

Windows Server appfabric cachingArchitecture

It can be seen from the general architecture of appfabric caching, which provides clients with a unified cache view. The client does not need to care about the actual cache layer) how complicated it is. You can use appfabric caching to develop a 3 h (high scalability, high availability, and high performance) application system through a unified API.

   1: //Define Array for 1 Cache Host

   2: List<DataCacheServerEndpoint> servers = new List<DataCacheServerEndpoint>(1);

   3:  

   4: //Specify Cache Host Details 

   5: //  Parameter 1 = host name

   6: //  Parameter 2 = cache port number

   7: servers.Add(new DataCacheServerEndpoint("localhost", 22233));

   8:  

   9: //Create cache configuration

  10: DataCacheFactoryConfiguration configuration = new DataCacheFactoryConfiguration();

  11:  

  12: //Set the cache host(s)

  13: configuration.Servers = servers;

  14:  

  15: //Set default properties for local cache (local cache disabled)

  16: configuration.LocalCacheProperties = new DataCacheLocalCacheProperties();

  17:  

  18: //Disable exception messages since this sample works on a cache aside

  19: DataCacheClientLogManager.ChangeLogLevel(System.Diagnostics.TraceLevel.Off);

  20:  

  21: //Pass configuration settings to cacheFactory constructor

  22: myCacheFactory = new DataCacheFactory(configuration);

  23:  

  24: //Get reference to named cache called "default"

  25: myDefaultCache = myCacheFactory.GetCache("default");

 

Windows Server appfabric caching has the following features:

  • Any serialized CLR object can cache data through a simple cache API.
  • Supported enterprise scale: supports Server architecture of hundreds of hosts
  • Elastically adjusts configurations and uses the network cache service
  • Supports Dynamic Scaling and allows you to add nodes at any time.
  • High Availability Architecture
  • Automatic Load Balancing
  • Integrated management and monitoring with event tracing for Windows (ETW) and System Center
  • Seamless integration with ASP. NET, storing session data to the cache, and caching application data in the Web farm architecture to reduce the burden of reading a large number of databases
  • The first version follows the cache-aside architecture (clear cache, explicit it caching), meaning that you must explicitly specify in your application that you want to add (Put) or remove (remove) all cached data is not automatically synchronized with any source database.

Data Classification

To make full use of the appfabric caching function in your application, it is necessary to understand the data types that are normally cached. These data types can be categorized into reference data, activity data, and resource data, because different cache data types are applicable in different scenarios.

  1. Reference data)

    This type of data is responsible for storing "important data". This type of data does not change frequently, and a new version is created for each change, therefore, this type of data is suitable for sharing to multiple users and applications, accelerating the access speed of all applications, and reducing the load of each application on the database system. This type of data can be used for data caching, for example, product category.

    For large applications or large-traffic websites,Reference data typeYou can also set it to automatically copy to multiple servers in the cache cluster to increase the scalability of the application system.

  2. Activity data)

    The so-calledActivity data typeIt refers to program data with short lifecycles. Such data is usually not shared by applications or users, such as shopping cart information.Activity data. This type of data can be stored across servers in large applications and can easily meet high scalability requirements.

  3. Resource Data)

    Whether it is reference data (shared read) or activity data (exclusive write), it is very suitable for data caching, but not all application types support this way of caching, here "resource data" refers to "shared" data that needs to be read and written at the same time, and the Read and Write volume is very large. For exampleInventoryThis type of data is often changed, and the real-time information of each application must be provided, and the inventory quantity may be changed at any time.Resource Data.

    The biggest problem with this type of cache data is that it is difficult to provideHigh Efficiency(High Availability) support, due to maintenanceHigh EfficiencyThe data must be accurate to maintain data consistency. Therefore, the transaction processing, data change notification, and invalidations must be performed, appfabric caching allows you to set Automatic duplication of such data to different cache hosts.High Efficiency.

Use Cases

  • Social SNS websites

Because user names and friend lists do not change frequently, this situation is suitableReference data type(Reference Data)Cache.

  • Enterprise lob (such as ERP, CRM ,...

For supplier data and price information, you can useReference data type(Reference Data)And other information such as order information, invoice information, and payment information can be used. Activity data type(Activity data)To cache.

 

Basic concepts of appfabric caching

The above is the basic concept of "distributed Cache architecture". Here is the basic concept of "development model, understanding these concepts makes it clear when you actually use appfabric caching (code name: velocity) to develop programs.

Logic layer architecture

The logical architecture is described as follows:

  • EachServer(MACHINE)You can execute severalCache instance(Cache instanceOrCache host ),It means that a machine can run several SQL Server instances.
  • EachCache instance(Cache host)Can contain multipleNamespace(Named cache), named CacheIt can be set to span multiple cache hosts or machines
  • EachNamespace(Named cache)Can contain multipleRegion(Regions)
  • EachCache area(Regions)Can contain multipleCache items(Cache items)
  • EachCache items(Cache items)IncludeSerializableCLRObject(Objects)

Cache concepts)

  • Master Node(Primary node)

AllRegion(Regions)The data will be placed on the primary node. Any data obtained from the cache client will be automatically routed to the primary node to read and write data.

  • Secondary Node(Secondary nodes)

IfNamespace(Named cache)When "backup" is configured for high availability, "secondary nodes" are used to store the "backup used"Region(Regions)"Remarks:RegionContains multipleCache items). If the "master node" is damaged, the requests received by the cache cluster are automatically routed to the "secondary node" for Data Reading.

 

 

Cache type(Cache types)

Appfabric supports two common cache types: partition cache and local cache.

  • Partition Cache(Partitioned cache)

When talking about "partition cache", it is easy to misunderstand its meaning. This concept is not like "disk partition". An entity hard disk is partitioned into several sectors, instead, all the "cache servers" are integrated into a memory cache storage area (Cache cluster). You can partition any size you want in this "cache cluster. ThereforePartitioned CacheIt is suitable for applications that require massive storage cache, which greatly improves scalability of applications. When the memory is insufficient, you only need to add servers. WhenNew Cache ServerJoin the wholeCache ClusterAppfabric caching automatically performs load balancing andCache itemsAutomatically moved to the new host. When cache items are evenly distributed across hosts, the overall cache cluster throughput (throughtput) is also increased ). Because multiple servers are integrated into a large memory, cached data is not stored repeatedly. For example, K2 and V2 refer to "key/value pair 2, when writing data to a cache project using the PUT command, data is written to cache 2.Cache entity(Cache host)So when the other host obtains (get) K2 and V2 data from cache 3, it will get data from cache2 through the Routing Mechanism in appfabric caching, all these complex routing jobs are completed by appfabric caching.

Partitioned CacheYou can also configure the "secondary cache node" so that the "primary cache data" can automatically copy the cache project to another hostHigh Efficiency(High Availability)As follows:

 

  • Local Cache(Local cache)

Appfabric caching also supports "local cache". The local cache can effectively save the CPU cost of "serialization/deserialization" and improve the performance when reading and writing cached data. As shown in, it is easy to see the scenario where local cache is used:

 

 

Expiration and recycling(Expiration and eviction)

  • Cache expiration(Expiration)

When a cache project is added to regions, you can specify the TTL (time to live) of the object)

  • Cache collection(Eviction)

Cache items can be set to a priority level. When the cache is insufficient, unused cache items will be deleted based on the LRU (least-recently-used) algorithm, enables cache projects with higher priority to enter the cache server.

Consistency Model(Consistency models)

  • Optimistic version update mechanism(Optimistic version-based updates)

Through this mechanism, you can enjoy high execution efficiency, because even if different clients execute at the same timeGet Cache(Get) orWrite Cache(Put) actions can be executed at the same time, and velocity will maintain a copy internallyCache itemsThe version information is returned to the client each time the get data is obtained. Therefore, you do not need to maintain locking. However, the version information must be determined by the client.

  • Pessimistic Locking Mechanism(Pessimistic locking)

When using getandlock provided by API to retrieve data, if other programs also need to use getandlock to retrieve data, it will fail. However, if the client uses get to retrieve data, it is still possible. In this case, the putandlock method can be used to write data back to velocity, and the lock status will be lifted. However, if the put method is used directly, the lock status will be canceled and the value of the object will be rewritten, therefore, you must be careful when using it. The unlock method can also be used to set the unlock.

 

Change Notification(Communications)

In a distributed architecture, because multiple clients read and write the same resource at the same time,Change NotificationThe change is very practical. When another client changesRegion(Regions)OrCache items(Cache items)You can use the event notification application.

Deployment Topology(Deployment topology)

Velocity is a service provided through Windows Service. It can be connected from the local computer or remote computer through TCP/IP and used directly through. Net client APIs.

There are two common velocity deployment modes:

  • Embedded

SetCache host(Cache host)Installed with the IIS host and combined with multiple hostsCache Cluster

  • Cache service

UseDedicated hostProvideCache host(Cache host)To provide a hostCache Layer(Caching tier)

ASP. NET Integration(ASP. NET integration)

Appfabric provides a set of sessionstoreprovider that allows you to easily move sessions to the appfabric caching platform and store them toPartition Cache(Partitioned cache)You can also set ha (high availability) and HS (high scalability.

Performance Testing(Performance Testing)

As shown in, as long as you addCache ServerAlmost displays "linear growth" throughput, which can effectively improve the scalability of applications.

Conclusion(Conclusion)

Appfabric caching allows you to easilyMemory of multiple serversIntegrates into a large memory cache, which can be read and written through a single API. When the memory is insufficient, it can be easily expanded as long as the server is increased, which not only effectively reduces management costs, it also easily achieves 3 h (high scalability, high availability, high performance) system architecture.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.