Windows Azure Learning Note (3)

PARTITION DATA

Partitioning support in Azure can be summarised as follows:

 Table entities are horizontally partitioned on partition key
 Blobs are partitioned based on their container
 Queues are partitioned on a per-queue basis

 Sql Azure supports no partitioning

CACHE

 Client side timed cache – content that expires after a certain amount of time, preventing client browsers from requesting a page, serving a local copy instead
 Entity Tags6 (ETags) - Allow you to specify a ‘version’ in a http header field; server can indicate the version has not changed, in which case no other data is exchanged, otherwise can return all the data for that request
 ASP.Net Page level Cache
 Distributed Cache7 - has multiple nodes that either all share the same content (shared everything) or have unique sections of the cache (shared nothing); shared everything distributed caches work well in Azure because of the throwaway nature of commodity hardware and ease of scale

DISTRIBUTE WORKLOADS EFFECTIVELY

The ‘Asynchronous Work Queue Pattern’ is one such solution. By providing a robust, redundant queuing mechanism that guarantees unique distribution of work items, the workers are ignorant of leases and locks and can focus on the job of processing work items. Such a queue will be reusable for many different work types, and the Windows Azure Storage Queue service is an ideal candidate.

There are other messaging architectures that allow us to decouple our components. AppFabric allows a ‘NetEventRelayBinding’ for Publish/Subscribe scenarios, for example.

MAXIMISE RESOURCES

When using worker roles, multi-threaded architectures are often forgotten. Since adding another instance means an additional hourly cost, first ensure you are getting the most out of your current instances. If your worker (or web role for that matter) has lots of IO work, it makes sense to use multiple threads.

Currently you can utilise content delivery services (CDN) to push blobs out to localised edges. This will help improve latency for your customers. Also consider what could qualify for blob storage; essentially anything static is a contender:



BUILDING A CONTENT-BASED ROUTER SERVICE ON WINDOWS AZURE

The Windows Azure load balancer only exposes a single external endpoint that clients interact with; therefore it is necessary to know the unique IP address of the instance that will be performing the work. IP addresses are discoverable via the Windows Azure API when marked as internal (configured through the web role’s properties).

it is important to understand how to perform inter-role communication without the use of queues.


AZURE DRIVE

Azure Drive is a feature of Windows Azure providing access to data contained in an NTFS-formatted virtual hard disk (VHD) persisted as a page blob in Azure Storage. A single Azure instance can mount a page blob for read/write access as an Azure Drive. However, multiple Azure instances can mount a snapshot of a page blob for read-only access as an Azure Drive. The Azure Storage blob lease facility is used to prevent more than one instance at a time mounting the page blob as an Azure Drive. It is not possible to mount an Azure Drive in an application not resident in the Azure cloud or development fabric.


QUERIES AND AZURE TABLES

CREATEQUERY<T>()

protected void SimpleQuery(CloudTableClient cloudTableClient) 
{ 
TableServiceContext tableServiceContext = cloudTableClient.GetDataServiceContext();
 tableServiceContext.ResolveType = (unused) => typeof(Song); IQueryable<Song> songs = (from entity in tableServiceContext.CreateQuery<Song>("Songs") select entity).Take(10); List<Song> songsList = songs.ToList<Song>(); 
 }

As with other LINQ implementations the query is not submitted to the Azure Table Service until the query results are enumerated.

DATASERVICEQUERY

DataServiceQuery is the WCF Data Services class representing a query to the Azure Table Service. DataServiceQuery provides the following methods to send queries to the Azure Table Service. public IAsyncResult BeginExecute(AsyncCallback callback, Object state); public IEnumerable<TElement> EndExecute(IAsyncResult asyncResult); public IEnumerable<TElement> Execute();
Execute() is a synchronous method which sends the query to the Azure Table Service and blocks until the query returns. BeginExecute() and EndExecute() are a matched pair of methods used to implement the AsyncCallback Delegate model for asynchronously accessing the Azure Table Service.


CLOUDTABLEQUERY

The CloudTableQuery<T> class supports continuation tokens.

Execute() handles continuation automatically and continues to submit queries to the Azure Table Service until all the results have been returned. Execute(ResultContinuation) starts the request with a previously acquired ResultContinuation object encapsulating a continuation token and continues the query until all results have been retrieved.

protected void UsingCloudTableQueryExecute(CloudTableClient cloudTableClient) 
{ TableServiceContext tableServiceContext = cloudTableClient.GetDataServiceContext(); 
tableServiceContext.ResolveType = (unused) => typeof(Song); CloudTableQuery<Song> cloudTableQuery = (from entity in tableServiceContext.CreateQuery<Song>("Songs") select entity).AsTableServiceQuery<Song>(); IEnumerable<Song> songs = cloudTableQuery.Execute();
 foreach (Song song in songs) { String singer = song.Singer; } }

The following is an example of BeginExecuteSegmented() and EndExecuteSegmented() paging through the result set of a query in pages of 10 entities at a time: protected void QuerySongsExecuteSegmentedAsync( CloudTableClient cloudTableClient) { 
TableServiceContext tableServiceContext = cloudTableClient.GetDataServiceContext(); tableServiceContext.ResolveType = (unused) => typeof(Song); CloudTableQuery<Song> cloudTableQuery = (from entity in tableServiceContext.CreateQuery<Song>("Songs").Take(10) select entity ).AsTableServiceQuery<Song>(); IAsyncResult iAsyncResult = cloudTableQuery.BeginExecuteSegmented( BeginExecuteSegmentedIsDone, cloudTableQuery); }

USING WORKER ROLES TO IMPLEMENT A DISTRIBUTED CACHE- memcached 

LOGGING, DIAGNOSTICS AND HEALTH MONITORING OF WINDOWS AZURE APPLICATIONS

Azure Diagnostic Manager


The Service Definition file specifies the roles contained in the service along with the following for each role:

  upgradeDomainCount - number of upgrade domains for the service 

 vmsize - the instance size from Small through ExtraLarge 

 ConfigurationSettings - defines the settings used to configure the service 

 LocalStorage- specifies the amount and name of disk space on the local VM

  InputEndpoints - defines the external endpoints for a role 

 InternalEndpoint - defines the internal endpoints for a role 

 Certificates - specifies the name and location of the X.509 certificate store


The Service Configuration file provides the configured values for: 

 osVersion - specifies the Azure guest OS version for the deployed service

  Instances - specifies the number of instances of a role 

 ConfigurationSettings - specifies the role-specific configuration parameters 

 Certificates - specifies X.509 certificates for the role


RoleEntryPoint is the base class providing the Azure fabric an entry point to a role. All worker roles must contain a class derived from RoleEntryPoint but web roles can use ASP.Net lifecycle management instead. The standard Visual Studio worker role template provides a starter implementation of the necessary derived class.

The Azure fabric initializes the role by invoking the overridden OnStart() method. Prior to this call the status of the role is Busy. Note that a web role can put initialization code in Application_Start instead of OnStart(). The overridden Run() is invoked following successful completion of OnStart() and provides the primary working thread for the role. An instance recycles automatically when Run() exits so care should be taken, through use of Thread.Sleep() for example, that the Run() method does not terminate. Azure invokes the overridden OnStop() during a normal suspension of the role. The Azure fabric stops the role automatically if OnStop() does not return within 30 seconds. Note that a web role can put shutdown code in Application_End instead of OnStop().


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值