Windows PowerShell - Center

Download Report

Transcript Windows PowerShell - Center

セッション ID: T6-402
Windows Server AppFabric
を使用した
サービス ホスティングと
分散キャッシュの
実践ノウハウ
マイクロソフト株式会社
デベロッパー & プラットフォーム統括本部
エバンジェリスト
松崎 剛
セッションの目的とゴール
Session Objectives and Takeaways
目的
Windows Server AppFabric における
技術的背景やノウハウを習得することで、
今後の実務での活用に役立てる
本セッションのゴール
ホスティング サービス :
アーキテクチャと動きを理解し、さらに独自な
カスタマイズ可能性を習得する
キャッシュ サービス :
現状、どこまでが可能で、どこからが不可能か
理解する
3
アジェンダ
Windows Server AppFabric のさらなる理解!
ホスティング サービス編
アーキテクチャと動作概念
Windows PowerShell で学ぶ全体像
機能の拡張
キャッシュ サービス編
基本
(アーキテクチャー、Region/Tag/Version、セキュリティなど)
応用
(内部動作、一貫性、可用性、セッション管理など)
その他のトピック
4
ホスティング サービス編
いわゆる、"Dublin" です ...
ホスティング サービス アーキテクチャ
Tools
Windows PowerShell
Runtime services
Workflow management service
Event collection service
Runtime
databases
Persistence DB
Monitoring DB
.NET Framework
Monitoring
Persistence
Durable
Timer
Lock
Retry
WCF
Tracking
sqlInstanceStore
WCF message logging
IIS/Windows
6
WF
Tracking
System Center Operations Manager
IIS Manager 用アドイン
動作概念 (監視)
既定で、ETW Tracking Participant を提供
Event Collection Service がイベントを収集
(権限設定に注意! サービスが DB に書き込む)
IIS 管理マネージャーは、監視 DB の内容を収集
.NET Framework
Management
Tools
Tracking
Participant
WCF Host
(ServiceHost)
IIS
Windows
7
ETW
Event
Collection
Service
Monitoring DB
動作概念 (永続化)
SqlInstanceStore を通して永続化を実行
Workflow Management Service の役割
タイマーの実行 (ロード)
ストアされたコマンドの実行
インスタンスのロック状態の監視
注: ただし、IIS 上のインスタンスへのコマンドは、DB に登録
.NET Framework
Management
Tools
Persistence
Participant
InstanceStore
Workflow Application
(WorkflowServiceHost)
IIS
Windows
8
Workflow Workflow
Control Management
Service
Endpoint
Persistence
DB
負荷分散と可用性に対処
以前の SqlWorkflowPersistenceService は、
"状態の持続" を目的とした機能
複数ユーザー & 負荷分散構成による
同一インスタンス アクセスなどに未対応
障害発生時のインスタンス リカバリーも未対応
Id=456
Id=123
WMS
Id=789
Id=456
Id=123
9
WMS
Persistence
Id=789
WMS
Heartbeats
Windows PowerShell で学ぶ、
Application Server 管理の全体像
ホスティング サービスは、
"Application Server 全体の拡張" である
設定・管理内容のほとんどは web.config
(または applicationHost.config) に反映
アプリケーション全体/データベースの管理
項目
説明
Application
IIS のアプリケーション
applicationHost.config
ASAppService
WCF/WF サービス
applicationHost.config
ASAppServiceAutoStart
サービスの自動起動の構成
applicationHost.config
AppInstanceStore
使用可能なインスタンス ストア
MonitoringSqlDatabase
監視用のデータベース
PersistenceSqlDatabase 永続化用のデータベース
10
設定場所
ルートの web.config
SQL Server
SQL Server
Windows PowerShell で学ぶ、
Application Server 管理の全体像
サービスの管理 (1)
11
項目
設定される構成
IIS 上
の管理
AppMessageLogging
system.serviceModel\diagnostics\
messageLogging
○
AppMonitoring
microsoft.applicationserver\monitoring
○
AppPerformanceCounter
system.serviceModel\diagnostics
×
AppServiceBehaviorName
system.serviceModel\services\service
×
AppServiceCertificate
system.serviceModel\behaviors\
serviceBehaviors\behavior\serviceCredential
s\serviceCertificate
○
AppServiceEndpoint
system.serviceModel\services\service\
endpoint
×
AppServiceEndpointAuthe
ntication
system.serviceModel\bindings\
<バインディング>\binding\security
×
AppServiceEndpointTrans
portQuota
system.serviceModel\bindings\
<バインディング>\binding
×
Windows PowerShell で学ぶ、
Application Server 管理の全体像
サービスの管理 (2) 続き . . .
12
項目
設定される構成
IIS 上
の管理
AppServiceMetadata
system.serviceModel\behaviors\
serviceBehaviors\behavior\serviceMetadata
×
AppServiceThrottling
system.serviceModel\behaviors\
serviceBehaviors\behavior\serviceThrottling
○
AppSqlServicePersistence
system.serviceModel\behaviors\
serviceBehaviors\behavior\sqlWorkflowInsta
nceStore
○
InstanceExceptionPolicy
system.serviceModel\behaviors\
serviceBehaviors\behavior\workflowUnhandl
edException
○
InstanceManagement
system.serviceModel\behaviors\
serviceBehaviors\behavior\workflowInstanc
eManagement
×
InstanceUnloadPolicy
system.serviceModel\behaviors\
serviceBehaviors\behavior\workflowIdle
○
アプリケーション サーバー
拡張機能の全貌
Windows PowerShell でおこなう
アプリケーションの管理 & カスタマイズ
デモシナリオ
サービス 1
14
サービス 2
Event 1
Event 2
Event 3
Monitoring DB 1
Monitoring DB 2
機能の拡張 (監視)
Tracking Profile:
監視の収集項目を拡張可能
Tracking Participant:
監視そのものの "動作" を拡張可能
ETW Consumer:
収集ログを扱ったカスタム アプリケーション
Custom Tracking Profile
.NET Framework
Custom
Tracking
Participant
Management
Tools
WCF Host
(ServiceHost)
IIS
Windows
15
Custom
ETW Consumer
ETW
Event
Collection
Service
Monitoring DB
機能の拡張 (永続化)
Instance Store:
永続化用のストアの拡張が可能
Persistence Participant:
永続化対象 (ロード/アンロード対象) の
データの収集機能の拡張が可能
.NET Framework
Management
Tools
Persistence
Participant
InstanceStore
Workflow Application
(WorkflowServiceHost)
IIS
Windows
16
Workflow Workflow
Control Management
Service
Endpoint
Persistence
DB
カスタマイズ!
カスタマイズ!
カスタマイズ!
 カスタム トラッキング プロファイル
 カスタム TrackingParticipant
etc . . .
キャッシュ サービス編
いわゆる、"Velocity" です...
キャッシュ サービス アーキテクチャー
キャッシュ
クライアント
キャッシュ
サービス
Caching
Tier
Web Tier
メモリ データを共有 (DB は構成情報のみを保持)
シリアライズ可能な .NET オブジェクトが対象
Get/Put/Add/Remove
Unified Cache View
Database
19
領域 (Region) とタグ (Tag)
「グループ化」と「タグ付け」の概念
Region は排他的
Tag とアイテムは多対多
いずれも、ランタイム時に作成
Region
Tag
Item
(key-value)
PC
Note type
Business Use
Car Accessories
Furniture
20
Full HD
msbook
mspad
ms-V
ms-star
prims
maio
領域 (Region)
同じ Region のアイテムは、同じホストに
配置 (パーティション化の対象)
同一の Key のアイテムであっても、
Region が異なれば、異なるアイテムとして
扱う
Region 単位で、アイテムの Bulk Get と
Bulk Remove が可能
cache.CreateRegion("PC");
cache.Add("prod1", "notebook", "PC");
PCItem obj = (PCItem) cache.Get("prod1", "PC");
21
タグ (Tag)
Tag を使用した検索 (Bulk Get) を提供
GetObjectsByTag
GetObjectsByAllTags
GetObjectsByAnyTag (ただし、重複抽出される)
検索時に、必ず、Region の指定が必要
(ノード ツリーをベースとした高速なアクセス)
var cache = factory.GetCache("HogeHoge");
cache.CreateRegion("PC");
DataCacheTag tag1 = new DataCacheTag("note");
DataCacheTag tag2 = new DataCacheTag("business");
cache.Add("prod1",obj1,new List<DataCacheTag> {tag1},"PC");
cache.Add("prod2",obj2,new List<DataCacheTag> {tag2}, "PC");
cache.Add("prod3",obj3,new List<DataCacheTag>{tag1,tag2}, "PC");
IEnumerable<KeyValuePair<string, object>> result =
cache.GetObjectsByTag(tag1, "PC"); // prod1, prod3
22
アイテムのバージョン
キャッシュ クラスターには、常に最新のみを保持
(注意 : 旧アイテムの世代保持はしない !)
保持しているデータが、どの世代のバージョンか
確認可能
アプリケーション ロジックで、並行性 / 一貫性を
保持する際に使用可能
DataCacheItemVersion ver1 = cache.Add("Foo", obj1);
DataCacheItemVersion ver2 = cache.Put("Foo", obj2);
DataCacheItemVersion ver = default(DataCacheItemVersion);
MyObj res = (MyObj) cache.Get("Foo", out ver);
if (ver.CompareTo(ver1) == 0)
Console.WriteLine("res is Version1"); // not hit
else if(ver.CompareTo(ver2) == 0)
Console.WriteLine("res is Version2"); // hit !
23
セキュリティ
Security Mode と Protection Level
Security Mode
設定値
内容
None
いかなるクライアントもアクセス可能
Transport
(既定)
許可された Windows アカウント
(ユーザー、グループ、マシン) のみ接続可能
Protection Level
24
設定値
内容
None
(追加の指定なし)
Sign
データの外部からの不正操作を防止
※ Security Mode: Transport 時のみ有効
EncryptAndSign
(既定)
上記に加え、データを暗号化 (外部読み取り防止)
※ Security Mode: Transport 時のみ有効
セキュリティ
セキュリティ設定は、サービス側とクライアント側
の双方を設定
サービス側
Windows PowerShell コマンドレット
(Set-CacheClusterSecurity)
クライアント側
.config 設定、またはコード
(securityProperties)
権限付与は、All or Nothing! (Not Fine-Grained)
ユーザー追加で、Add/Put/Get すべてが可能
セキュリティは高くつく! (パフォーマンスに影響)
DMZ など外部のセキュリティ機構を信頼する場合、
キャッシュ セキュリティそのものをオフ化する
Windows PowerShell
Set-CacheClusterSecurity -SecurityMode None
-ProtectionLevel None
25
キャッシュアイテム ライフサイクル
キャッシュごとに、Expiration と Eviction を管理
Expiration
Eviction
時限方式の生存管理
メモリ使用量などに応じた生存管理
このため、ホストのメモリ容量により
スケーラビリティが異なる
Expiration
設定項目
内容
既定値
IsExpirable
False にすると、Eviction のみを評価
True
defaultTTL
既定の TTL (TimeToLive)
※ TTL は、アイテムごとに上書き (変更) 可
10 min
設定項目
内容
既定値
EvictionType
None: Eviction なし
LRU (least recently used): 使用頻度が高い
アイテムを優先するアルゴリズム
LRU
Eviction
26
キャッシュアイテム ライフサイクル
設定方法
Windows PowerShell コマンドレット
(New-Cache, Set-CacheConfig)
ファイルによる構成共有の場合は、ClusterConfig.xml
に記述可能
Windows PowerShell
New-Cache HogeHoge -TimeToLive 3
または Set-CacheConfig -CacheName HogeHoge -TimeToLive 3
# HogeHoge の既定値は、3 分で消滅 !
ClusterConfig.xml
<dataCache size="small">
<caches>
<cache type="partitioned" name="default">
<policy>
<eviction type="lru" />
<expiration defaultTTL="10" isExpirable="true" />
</policy>
</cache>
</caches>
</dataCache>
27
キャッシュ サービスの基本動作
キャッシュ サービスの
動きを見てみよう!
内部動作 (既定: Partitioned)
接続先のサーバー (キャッシュ サービス) が、
ルーティング情報を保持
クライアント側では、可用性を考慮し、接続先の
サーバーを複数指定可能
サーバー台数の増加に応じて、適宜 Region を移動
Cache Client
Routing Layer
Cache Client
Routing Layer
Routing Layer
Data 1
Region 1
Cache Service 1
29
Cache Service 2
Cache Service 3
内部動作 (ローカル キャッシュ)
"アイテムコピー" と "ルーティング情報" を保持
パフォーマンス重視の参照データに適した構成
以下の点に注意!
同じ DataCacheFactory (または DataCache) で有効
データ一貫性が犠牲となる
Cache Client
Cache
Cache
Cache Client
Data 1
Routing Layer
Data 1
Routing Layer
Data 1
Region 1
Cache Service 1
30
Cache Service 2
Cache Service 3
内部動作 (ローカル キャッシュ)
構成を使用して、キャッシュを設定
タイムアウトベースと、通知ベースの設定
<dataCacheClient>
<localCache isEnabled="true" sync="NotificationBased"
objectCount="100,000" ttlValue="300" />
<!--(optional) キャッシュ更新通知のポーリング間隔 -->
<clientNotification pollInterval="300" />
設定項目
内容
IsEnabled
True でローカル キャッシュを有効化
sync
TimeoutBased - 時限方式でキャッシュを無効化
NotificationsBased - 時限方式に加え、通知方式によるキャッ
シュ無効化。既定は 300 秒ごとに Polling
objectCount キャッシュ可能なデータの最大数。既定では 100,000
ttlValue
31
無効化の時間設定 (単位は秒)。既定は 300 秒
並行性とロック
楽観的アクセス以外に、悲観的ロックのための API
を提供 (GetAndLock/PutAndUnlock/Unlock)
ロックされたオブジェクトに対し、
Get 可能/GetAndLock 不可能
obj1 = cache.GetAndLock("Foo", TimeSpan.FromSeconds(10),
out handle, true);
任意の処理の実行 ...
cache.PutAndUnlock("Foo", obj2, handle);
注意点
キーが存在していないアイテムはロックできない
待機するには、例外処理を構築する必要がある
DataCacheException (ErrorCode=11) を返す
ロックの途中でも Put が可能 (ロックが解除される!)
アプリケーション側での統一的な管理が必要!
32
通知 (Notification)
キューとポーリングによる通知メカニズム
非同期処理
処理のトリガーは不可
PowerShell、または ClusterConfig.xml による
キャッシュ側の設定が必要
Set-CacheConfig -CacheName HogeHoge -NotificationsEnabled true
または New-Cache HogeHoge -NotificationsEnabled true
通知レベルを指定可能
キャッシュ/Region/アイテムの各レベル
上位の範囲では、下位の通知をすべて受け取る
ただし、
更新系処理のみ対象 (Get は対象外)
アイテムのライフサイクル上の廃棄
(Expiration or Eviction) は対象
33
高可用性オプション
HA のオプションにより、単一点障害を防止
New-Cache <name> -Secondaries 1
# 0 : オフ、1 : オン
Primary–Secoudary を含めた一貫性も保証
サーバー構成
OS : Windows Server 2008 / 2008 R2
Edition : Enterprise Edition / Datacenter Edition
推奨 : 3 台以上
Cache Service 1
Cache Service 2
Data 1
(Secondary)
Data 1
Data 1
(Primary)
(Secondary)
Data 2
Data 2
(Secondary)
(Primary)
(Secondary)
34
Cache Service 3
Data 2
(Primary)
ASP.NET Session との統合
ASP.NET セッション (Session) における
データ キャッシュ統合
セッション レプリケーション + インメモリの
双方のメリットを享受
高可用性オプションの指定が可能
<sessionState mode="Custom" customProvider="MyVelocity">
<providers>
<add name="MyVelocity"
type="Microsoft.ApplicationServer.Caching.DataCacheSessionStorePr
ovider, Microsoft.ApplicationServer.Caching.Client, Version=1.0.0.0, Cultu
re=neutral, PublicKeyToken=31bf3,856ad364e35"
cacheName="SessionTest"/>
</providers>
</sessionState>
35
ASP.NET Session との統合
基本的には、アプリごと、セッションごとに
異なる管理となる
sharedId 属性で、同一サイトの
別アプリケーションでセッション情報を
共有可能
内部的には <sharedId>+<セッション ID>
をキーとして使用
ただし、ローカル キャッシュは
使用できない!
36
キャッシュ サービスにおける
さまざまなオプション
• ローカル キャッシュ
• セッション
• 通知
データ分類とチューニング
データ分類に応じたパラメーター設定
参照データ : 参照中心のデータ
アクティビティ データ : 並行性を伴わない
更新データ
リソース データ : 厳密な並行性を伴う更新データ
求められるパフォーマンス (スループット)、
一貫性、可用性に応じたチューニング
データ分類
並行性
アクセス
頻度
データの例
(商品購入の場合)
関連性の高いテクノロジ
参照データ
商品カタログ etc
• Expiration/Eviction
• Local Cache
アクティビティ データ
ショッピング カート etc
• Region
• Session State
リソース データ
オークション アイテム etc
• Lock
38
ご参考: "Cache" everywhere!
Windows Server 2003 Distributed Cache
Client (ダウンロード センター)
Velocity を使ったカスタムの ASP.NET
出力キャッシュ実装
System.Web.Caching.OutputCacheProvider
クラスから派生 (ASP.NET 4 の新機能!)
OR マッパーの second-level キャッシュ
CodePlex: Tracing and Caching Provider
Wrappers for Entity Framework
Sourceforge: NHibernate.Caches.Velocity
39
"AppFabric"
for a consistent and symmetric future application model...
Today this degree of flexibility is not common, . . .
With AppFabric, we are committed to delivering a single and consistent
application model and supporting fabric which delivers the ability to
develop, deploy, and manage end to end applications across both worlds.
http://www.microsoft.com/servers/appfabric/
40
関連セッション
T6-312: Windows Communication Foundation 4 における新機能
のポイント~ REST サービスから ワークフローサービスまで~
T1-301: Windows Azure ストレージ詳説
T1-502: クラウド コンピューティングの最先端技術動向と
選択の戦略
41
リファレンス
松崎 剛 Blog – Windows Server AppFabric の入門
http://blogs.msdn.com/b/tsmatsuz/archive/2010/02/25/windowsserver-appfabric-application-server-extensions.aspx
Code Recipe: 10 行でズバリ!-.NET Framework 4 WF
http://msdn.microsoft.com/ja-jp/netframework/ee708289.aspx
MSDN マガジン: AppFabric キャッシュ-実際の使用法と統合
http://msdn.microsoft.com/ja-jp/magazine/ff714581.aspx
ダウンロード センター: Windows Server AppFabric Tutorials (英語)
http://www.microsoft.com/downloads/details.aspx?FamilyID=baa3322b
-c498-4c71-a995-396c4a8e3ff7&DisplayLang=en
チームブログ – The .NET Endpoint (英語)
http://blogs.msdn.com/b/endpoint
関連技術 : .NET Framework 4 – Memory-Mapped Files (英語)
http://msdn.microsoft.com/en-us/library/dd997372.aspx
42
ご清聴ありがとうございました。
T6-402
アンケートにご協力ください。
© 2010 Microsoft Corporation. All rights reserved. Microsoft, Windows and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries.
The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should
not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS,
IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.