61
for Developers Daniel Moth Developer and Platform Group Microsoft http ://www.danielmoth.com/Blo

For Developers Daniel Moth Developer and Platform Group Microsoft

Embed Size (px)

DESCRIPTION

1. Build More Flexible Web Apps

Citation preview

Page 1: For Developers Daniel Moth Developer and Platform Group Microsoft

for Developers

Daniel MothDeveloper and Platform GroupMicrosofthttp://www.danielmoth.com/Blog

Page 2: For Developers Daniel Moth Developer and Platform Group Microsoft

AGENDA

Top 7 Ways To “Light Up” Your Apps on Windows Server 2008Part 1 emphasis on

IIS7, PowerShellPart 2 emphasis on

WER, Restart and Recovery APIs, TxF

Page 3: For Developers Daniel Moth Developer and Platform Group Microsoft

1. Build More Flexible Web Apps

Page 4: For Developers Daniel Moth Developer and Platform Group Microsoft

2. Design Highly-Manageable Apps

Page 5: For Developers Daniel Moth Developer and Platform Group Microsoft

3. Develop Federation-Aware Apps

Page 6: For Developers Daniel Moth Developer and Platform Group Microsoft

4. Build Connected Systems

Page 7: For Developers Daniel Moth Developer and Platform Group Microsoft

The Top 7 Ways… Part 2

1. Build More Flexible Web Applications2. Design Highly-Manageable Applications3. Develop Federation-Aware Applications4. Build Connected Systems5. Build For Scalability6. Develop More Reliable Applications7. Virtualize

Page 8: For Developers Daniel Moth Developer and Platform Group Microsoft

5. Build For Scalability

Page 9: For Developers Daniel Moth Developer and Platform Group Microsoft

Native Threading Enhancementsin Windows Vista and Windows Server 2008

Thread Pools

One-Time Initialization

Slim Reader/Writer Lock

Condition Variables

Thread Ordering Service

Wait Chain Traversal

Page 10: For Developers Daniel Moth Developer and Platform Group Microsoft

Thread Pool in Vista and Server 2008

Re-architected Thread PoolSimpler, more reliable, higher performanceDoes not use a timer threadSingle queueDedicated persistent threadClean-up groupsSingle worker thread type (both I/O and non-I/O)Multiple pools per processMore flexible API

Page 11: For Developers Daniel Moth Developer and Platform Group Microsoft

Feature Original API Current APISynch RegisterWaitForSingleObject

UnregisterWaitEx

CloseThreadpoolWaitCreateThreadpoolWaitSetThreadpoolWaitWaitForThreadpoolWaitCallbacks

Work QueueUserWorkItem

CloseThreadpoolWorkCreateThreadpoolWorkSubmitThreadpoolWorkTrySubmitThreadpoolCallbackWaitForThreadpoolWorkCallbacks

TimerCreateTimerQueueCreateTimerQueueTimerChangeTimerQueueTimerDeleteTimerQueueTimerDeleteTimerQueueEx

CloseThreadpoolTimerCreateThreadpoolTimerIsThreadpoolTimerSetSetThreadpoolTimerWaitForThreadpoolTimerCallbacks

I/O BindIoCompletionCallback

CancelThreadpoolIoCloseThreadpoolIoCreateThreadpoolIoStartThreadpoolIoWaitForThreadpoolIoCallbacks

Clean-up group CloseThreadpoolCleanupGroupCloseThreadpoolCleanupGroupMembersCreateThreadpoolCleanupGroup

PoolCloseThreadpoolCreateThreadpoolSetThreadpoolThreadMaximumSetThreadpoolThreadMinimum

Callback environmentDestroyThreadpoolEnvironmentInitializeThreadpoolEnvironmentSetThreadpoolCallbackCleanupGroupSetThreadpoolCallbackLibrarySetThreadpoolCallbackPoolSetThreadpoolCallbackRunsLong

Callback CallbackMayRunLong

Callback clean upDisassociateCurrentThreadFromCallbackFreeLibraryWhenCallbackReturnsLeaveCriticalSectionWhenCallbackReturnsReleaseMutexWhenCallbackReturnsReleaseSemaphoreWhenCallbackReturnsSetEventWhenCallbackReturns

Page 12: For Developers Daniel Moth Developer and Platform Group Microsoft

One-Time Initialization

Interlocked functions ensure that only one thread performs the initializationOne-time initialization is better

Optimized for speedAppropriate barriers are created on processor architectures that require themSupport for both locked and parallel initializationNo internal locking so the code can operate asynchronously or synchronously

Page 13: For Developers Daniel Moth Developer and Platform Group Microsoft

One Time Init StepsBOOL WINAPI InitOnceBeginInitialize(

__inout LPINIT_ONCE lpInitOnce, __in DWORD dwFlags, __out PBOOL fPending, __out LPVOID* lpContext );BOOL WINAPI InitOnceExecuteOnce(

__inout PINIT_ONCE InitOnce, __in PINIT_ONCE_FN InitFn, __inout_opt PVOID Parameter, __out LPVOID* Context ); BOOL WINAPI InitOnceComplete(

__inout LPINIT_ONCE lpInitOnce, __in DWORD dwFlags, __in LPVOID lpContext );BOOL CALLBACK InitOnceCallback(

__inout PINIT_ONCE InitOnce, __inout_opt PVOID Parameter, __out_opt PVOID* Context );

Page 14: For Developers Daniel Moth Developer and Platform Group Microsoft

Slim Reader/Writer LockSRW locks – new synchronization primitive

enable threads to access shared resourcesoptimized for speed take very little memorybuilt on top of windows kernel keyed events

Two modesShared mode

– grants shared read-only access to multiple reader threads

Exclusive mode– grants read/write access to one writer thread at a time

Page 15: For Developers Daniel Moth Developer and Platform Group Microsoft

SRW Lock APIs

VOID WINAPI InitializeSRWLock( __out PSRWLOCK SRWLock );

VOID WINAPI AcquireSRWLockExclusive( __inout PSRWLOCK SRWLock );

VOID WINAPI ReleaseSRWLockExclusive( __inout PSRWLOCK SRWLock );

VOID WINAPI AcquireSRWLockShared( __inout PSRWLOCK SRWLock );

VOID WINAPI ReleaseSRWLockShared( __inout PSRWLOCK SRWLock );

Page 16: For Developers Daniel Moth Developer and Platform Group Microsoft

Condition Variables

Used to synchronize a group of threads based on the result of some conditional testEnable threads to atomically release a lock and enter the sleeping stateBenefits

Much clearer and less error-proneCan be more efficient

– Tries to avoid trips to kernel mode (unlike WaitForSingleObject)

Page 17: For Developers Daniel Moth Developer and Platform Group Microsoft

Condition Variable APIsVOID WINAPI InitializeConditionVariable(

__out PCONDITION_VARIABLE ConditionVariable );BOOL WINAPI SleepConditionVariableCS(

__inout PCONDITION_VARIABLE ConditionVariable, __inout PCRITICAL_SECTION CriticalSection, __in DWORD dwMilliseconds );

BOOL WINAPI SleepConditionVariableSRW( __inout PCONDITION_VARIABLE ConditionVariable, __inout PSRWLOCK SRWLock, __in DWORD dwMilliseconds, __in ULONG Flags );

VOID WINAPI WakeConditionVariable( __inout PCONDITION_VARIABLE ConditionVariable );

VOID WINAPI WakeAllConditionVariable( __inout PCONDITION_VARIABLE ConditionVariable );

Page 18: For Developers Daniel Moth Developer and Platform Group Microsoft

Thread Ordering Service (TOS)

TOS controls the execution of client threadsEnsures that they run once and in order

5 APIs – AvRtXxxxThreadOrderingGroupparent thread calls Create to set up the TOSclient threads call Join to join the TOSall of them call Wait, run their code and Wait...client threads call Leave when they are doneparent thread calls Delete to end it all

Page 19: For Developers Daniel Moth Developer and Platform Group Microsoft

TOS APIs - avrt.hBOOL WINAPI AvRtCreateThreadOrderingGroup( __out PHANDLE Context, __in PLARGE_INTEGER Period, __inout GUID* ThreadOrderingGuid, __in_opt PLARGE_INTEGER Timeout );

BOOL WINAPI AvRtJoinThreadOrderingGroup( __out PHANDLE Context, __in GUID* ThreadOrderingGuid, __in BOOL Before );

BOOL WINAPI AvRtWaitOnThreadOrderingGroup( __in HANDLE Context );

BOOL WINAPI AvRtLeaveThreadOrderingGroup( __in HANDLE Context );

BOOL WINAPI AvRtDeleteThreadOrderingGroup(

__in HANDLE Context );

Page 20: For Developers Daniel Moth Developer and Platform Group Microsoft

Wait Chain Traversal (WCT)

Enables debuggers to diagnose application hangs and deadlocks

“Wait chain is an alternating sequence of threads and synchronization objects; each thread waits for the object that follows it, which is owned by the subsequent thread in the chain”

WCT supports the followingALPC, COM, Critical sections, Mutexes, SendMessage

Page 21: For Developers Daniel Moth Developer and Platform Group Microsoft

WCT APIs in Wct.h

HWCT WINAPI OpenThreadWaitChainSession( __in DWORD Flags, __in_opt PWAITCHAINCALLBACK callback );

BOOL WINAPI GetThreadWaitChain( __in HWCT WctHandle, __in_opt DWORD_PTR Context, __in DWORD Flags, __in DWORD ThreadId, __inout LPDWORD NodeCount, __out PWAITCHAIN_NODE_INFO NodeInfoArray, __out LPBOOL IsCycle );

VOID WINAPI CloseThreadWaitChainSession( __in HWCT WctHandle );

VOID CALLBACK WaitChainCallback( HWCT WctHandle, DWORD_PTR Context, DWORD CallbackStatus, LPDWORD NodeCount, PWAITCHAIN_NODE_INFO NodeInfoArray, LPBOOL IsCycle );

typedef struct _WAITCHAIN_NODE_INFO { <SNIP>

Page 22: For Developers Daniel Moth Developer and Platform Group Microsoft

Native Threading Enhancementsin Windows Vista and Windows Server 2008

Thread Pools

One-Time Initialization

Slim Reader/Writer Lock

Condition Variables

Thread Ordering Service

Wait Chain Traversal

MSDN Magazine: Oct07, Jun07, Jul07

Page 23: For Developers Daniel Moth Developer and Platform Group Microsoft

6. Develop More Reliable Apps

Page 24: For Developers Daniel Moth Developer and Platform Group Microsoft

Windows Error Reporting & winqual

New User ExperienceIn addition to crashes, hangs are also detectedPrivacy evaluation, Queuing and transportProblem Reports and SolutionsResponse management

New Public APIsAdding additional file and memory data to a report (inc. minidump & heap information)Create reports for custom events

Page 25: For Developers Daniel Moth Developer and Platform Group Microsoft

WER, Restart, Recovery

Page 26: For Developers Daniel Moth Developer and Platform Group Microsoft
Page 27: For Developers Daniel Moth Developer and Platform Group Microsoft

Restart API

Register to be restarted after fatal problemsRegistration also used for Restart Manager

– Restarts process after patch installationAll applications should support restart

– Especially if support document recovery

How it worksRegister command-line that should be called every execution

– HRESULT RegisterApplicationRestart (IN PCWSTR pwzCommandline, DWORD dwFlags)

After fatal event is reported, app is restarted– Fatal events block user tasks– Automatically restarting saves users from having to re-open the

application

Page 28: For Developers Daniel Moth Developer and Platform Group Microsoft

Recovery APIs

Attempt to recover data after a fatal eventUsers should not lose any work to an app bug

How it works1. App registers a “recovery callback” every execution

HRESULT RegisterApplicationRecoveryCallback (IN RECOVERY_ROUTINE RecoveryRoutine, IN PVOID pvParameter)

2. Recovery routine called after data collection– Application’s code attempts to recover user work

– Flush to disk, repair on next run of application– Repair data in memory, save to disk

– Need to call RecoveryInProgress() every 5 seconds to heartbeat– Call RecoveryFinished() to signal recovery is completed

Page 29: For Developers Daniel Moth Developer and Platform Group Microsoft

Windows Installer (MSI)

•Fewer reboots when using the Windows Add/Remove Programs feature•Developers can reduce reboots for installations and updates by using the Windows Installer v4.0

Key Microsoft Office 2007 Applications

•Automatically restart after a reboot due to an installation or update•Recreate application state upon restart

Restart Manager OverviewWith the Restart Manager technology installers can

Automatically shutdown only the applications and services holding a file to be updatedWhen available, leverage specific application functionality to restore the user to the state they were in before the restartWhen a reboot cannot be avoided, automatically re-launch apps after reboot

Page 30: For Developers Daniel Moth Developer and Platform Group Microsoft

Restart Manager

Page 31: For Developers Daniel Moth Developer and Platform Group Microsoft

Restart Manager, Call to Action

Installer software call the Restart Manager APIs

Applications and Services Restart Manager "aware”

Page 32: For Developers Daniel Moth Developer and Platform Group Microsoft

Transactional NTFS

Windows Vista and Windows Server 2008

Does what it says on the tin

System.Transactions.dll + PInvoke

Page 33: For Developers Daniel Moth Developer and Platform Group Microsoft

Transactional PlatformKernel Transaction Manager (KTM)

Makes transactions available as kernel objectsProvides transaction management services to system components such as TxFCan communicate with DTC to enable distributed transactions

Transactional NTFS (TxF)Integrates transactions directly into the NTFS file system

Transactional Registry (TxR)Integrates transactions directly into the Registry

Page 34: For Developers Daniel Moth Developer and Platform Group Microsoft

Transactional NTFS (TxF)Ke

rnel KTM

CLFSNTFS Registry

KtmRm KtmW32DTC

Nativ e

Man

age

d System.Tx LTM

WS-*WCF

MSMQ

SQL

Page 35: For Developers Daniel Moth Developer and Platform Group Microsoft

TxF

Page 36: For Developers Daniel Moth Developer and Platform Group Microsoft

7. Virtualize

Page 37: For Developers Daniel Moth Developer and Platform Group Microsoft

Hosted Virtualization ProductsMicrosoft Virtual PC 2007

Over 3.5 million downloadsSupport for Windows Vista as a host and guest64-bit host support Improved performanceSupport for Intel VT and AMD-V

Microsoft Virtual Server 2005 R2 SP1Support for Intel VT and AMD-VSupport for SLES 10VSS integration for live backup of running virtual machinesVHD mounting tool for offline servicingImproved performanceImproved scalability: 512 VMs on x64 systems

Page 38: For Developers Daniel Moth Developer and Platform Group Microsoft

Server Virtualization

Application Virtualizatio

nDesktop

Virtualization

Presentation

Virtualization

Management

A comprehensive set of virtualization products, from the data center to the desktopAssets – both virtual and physical – are managed from a single platform

Microsoft Virtualization Products

Centralized Desktop

Hyper-V Server

Page 39: For Developers Daniel Moth Developer and Platform Group Microsoft

Virtualization BenefitsServer consolidation

Business Continuity Flexibility

Utilization

Page 40: For Developers Daniel Moth Developer and Platform Group Microsoft

Hyper-V

Flexible and dynamic virtualization solutionA role of Windows Server 2008 (Std, EE, DC)

Can be a full role with local UI or Server Core roleHypervisor based architectureManaged by Microsoft System CenterAlso provided as a standalone server

Microsoft Hyper-V Server ($28)

Codename "Viridian", Windows Server Virtualization

Page 41: For Developers Daniel Moth Developer and Platform Group Microsoft

Windows Server Core roleServer Core

Minimal Installation option in all x86/x64 editionsCommand line interface only, no GUI shellProvides essential server functionalityDeployed for a single role

– No need to deploy and service the whole OS

BenefitsLess code results in fewer patches and servicing burdenLow surface area targeted for server rolesMore secure and reliable with less management

Page 42: For Developers Daniel Moth Developer and Platform Group Microsoft

Virtualization and High AvailabilityTraditional Non-Virtualized Environment

Downtime is bad, but affects only one workload

Virtualized Environment

Value of the physical server goes upDowntime is far worse because multiple workloads are affected

Virtualization and High-Availability Go Hand in Hand

Page 43: For Developers Daniel Moth Developer and Platform Group Microsoft

Microsoft Hyper-V High Availability

Planned downtimeMore common than unplannedQuickly move virtualized workloads in order to service underlying hardware

Unplanned downtimeNot as common and more difficultAutomatic failover to other nodes

– hardware or power failure

Page 44: For Developers Daniel Moth Developer and Platform Group Microsoft

Quick Migration FundamentalsPlanned Downtime

Save stateSave entire virtual machine state

Move virtual machineMove storage connectivity from origin to destination host

Restore state and RunRestore virtual machine and run

VHDs

Network Connectivity

Shared Storage

Page 45: For Developers Daniel Moth Developer and Platform Group Microsoft

Quick Migration – Planned Downtime

• Active server requires servicing

• Move virtualized workloads to a standby server

• ~4 seconds downtime per virtual machine

Virtualization Servers

(3 + 1 Servers)

System CenterVirtual Machine Manager

Windows Server 2008Failover Cluster Manager

VHDs onSAN

DomainController

Ethe

rnet

Storage Connectivity

Page 46: For Developers Daniel Moth Developer and Platform Group Microsoft

Quick Migration – Unplanned Downtime

• Active server loses power

• Virtual machines automatically restart on the next cluster node

• If there is not enough memory, the failover automatically moves to the next node until done

Virtualization Servers

(3 + 1 Servers)

System CenterVirtual Machine Manager

Windows Server 2008Failover Cluster Manager VHDs on

SAN

DomainController

Ethe

rnet

Storage Connectivity

Page 47: For Developers Daniel Moth Developer and Platform Group Microsoft

Quick Migration – How Quick Is It?Disc /

VM Memory1 GbE iSCSI 2 Gb FC 4 Gb FC

512 MB ~8 seconds ~ 4 seconds ~2 seconds

1 GB ~16 seconds ~8 second ~ 4 seconds

2 GB ~32 seconds ~16 seconds ~8 seconds

4 GB ~64 seconds ~32 seconds ~16 seconds

8 GB ~2 minutes ~64 seconds ~32 seconds

Page 48: For Developers Daniel Moth Developer and Platform Group Microsoft

TerminologyHypervisor

A piece of software that provides the ability to run multiple operating systems on one piece of hardwareEnsures that the CPU and hardware answer the *correct* OSMicrokernelized or Monolithic

Hyper-VA role you can install in Windows that includes the Hypervisor as well as management software

PartitionAn “operating system” to the hypervisor

Virtual MachineA “child” partition

Page 49: For Developers Daniel Moth Developer and Platform Group Microsoft

Hyper-V Overview

Windows HypervisorPowerful virtualization built into the Windows platform

VirtualizationPlatform andManagement

Management tools

VM 2“Child”

VM 1“Parent”

VM 2“Child”

Page 50: For Developers Daniel Moth Developer and Platform Group Microsoft

Hyper-V Architecture

Parent Partition Child Partitions

Kernel Mode

User Mode

VirtualizationService

Providers(VSPs)

WindowsKernel

Server Core

IHVDrivers

VirtualizationServiceClients(VSCs)

WindowsKernel

EnlightenmentsVMBus

Windows hypervisor

Virtualization Stack

VM WorkerProcessesVM

Service

WMI ProviderApplications

“Designed for Windows” Server Hardware

Provided by:

Windows

ISV

OEM

Hyper-V

Page 51: For Developers Daniel Moth Developer and Platform Group Microsoft

Example VSP/VSC DesignParent Partition Child Partitions

Kernel Mode

User Mode

Windows hypervisor

ApplicationsProvided by:

Windows

ISV

OEM

Hyper-V

VMBus

Windows File System

Volume

Partition

DiskFast Path Filter (VSC)

iSCSIprtVirtual StorageMiniport (VSC)

Virtual StorageProvider (VSP)

StorPort

Hardware

StorPortMiniport

VM Worker Process

Disk

Page 52: For Developers Daniel Moth Developer and Platform Group Microsoft

Monolithic vs. MicrokernelizedMonolithic hypervisor

Simpler than a modern kernel, but still complexContains its own drivers model

Microkernelized hypervisorSimple partitioning functionalityIncrease reliability and minimize TCBNo third-party codeDrivers run within guests

VM 1(“Admin”) VM 3

Hardware

Hypervisor

VM 2(“Child”)

VM 3(“Child”)

Virtual-ization Stack

VM 1(“Parent”)

DriversDriversDrivers DriversDriversDrivers DriversDriversDriversHypervisor

VM 2

Hardware

DriversDriversDrivers

Microkernelized Hypervisor has an inherently secure architecture with minimal attack surface

VMware ESX Approach Hyper-V Approach

Page 53: For Developers Daniel Moth Developer and Platform Group Microsoft

Virtual Server 2005 vs. Hyper-VVirtual Server 2005 R2 SP1 Hyper-V

32-bit Virtual Machines Yes Yes

64-bit Virtual Machines No Yes

Multi Processor Virtual Machines No Yes, up to 4 core VMs

Virtual Machine Memory Support 3.6GB per VM 32GB per VM

Physical Memory Support 256 GB 1 TB

Managed by System Center Virtual Machine Manager Yes Yes

Support for Microsoft Clustering Services Yes Yes

Host side backup support (VSS) Yes Yes

Scriptable / Extensible COM WMI + HyperCall API

User Interface Web Interface MMC 3.0 Interface

Page 54: For Developers Daniel Moth Developer and Platform Group Microsoft

Hyper-V Features and AbilitiesPerformance

HypervisorSynthetic DriversServer Core

FlexibilityMulti-architectureMulti-OS VM’s

ManageabilityManaged through WMI (PowerShell)SCVMMWindows

Page 55: For Developers Daniel Moth Developer and Platform Group Microsoft

Interoperability & Standards VHD (Virtual Hard Disk)

VHD specification is freely available under Open Specification Promise (OSP)VHD TestDrive program for ISVs

Standards based management APIsDMTF defining industry standard model for VM managementHyper-V uses this model

Hypervisor hypercall APIPreliminary documentation available under OSPFinal version will be at RTM

Page 56: For Developers Daniel Moth Developer and Platform Group Microsoft

Interoperablity & 3rd Party OS SupportLinux

Working with XenSource– Developing adapter layer to map Xen hypercall API to

Hyper-V hypercall API– Developing disk and networking drivers (VSCs) to integrate

with the new I/O architecture

Working with Novell– Interoperability and joint support for Windows Server and

Novel SUSE Linux Enterprise Server 10

Support for Linux on Hyper-VSolaris

Working with Sun to support Solaris on Hyper-V

Page 57: For Developers Daniel Moth Developer and Platform Group Microsoft

Windows Server Enterprise/Datacenter Includes 4/Unlimited virtual instances

Windows Vista (Software Assurance Customer Benefit)Allows Vista Enterprise Centralized Desktop deployments

Licensing per Virtual ProcessorSQL Server, BizTalk Server, etc.

Instance Based LicensingWill enable new usage models

Demo Distribution of Virtual Images

Industry Leadership In Licensing

Page 58: For Developers Daniel Moth Developer and Platform Group Microsoft

Virtualization Investments

Ease consolidationonto virtual infrastructureBetter utilizemanagementresourcesFree up IT spend

Management

Supportheterogeneityacross thedatacenterOSP (Open Specification Promise) VHD and HyperCall

Interoperability

AcceleratedeploymentReduce the cost of supportingapplications Turn apps into dynamic, real-time services

Applications

Deliver cost-effective, flexible and simplified licensing

Licensing

Create agilityBetter utilizeserver resourcesPartner with AMD and Intel

Infrastructure

Page 59: For Developers Daniel Moth Developer and Platform Group Microsoft

Summary

Build More Flexible Web ApplicationsDesign Highly-Manageable ApplicationsDevelop Federation-Aware ApplicationsBuild Connected SystemsBuild For ScalabilityDevelop More Reliable ApplicationsVirtualize

Page 61: For Developers Daniel Moth Developer and Platform Group Microsoft

© 2007 Microsoft Ltd. All rights reserved. Microsoft, Windows, Windows Vista 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.