• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
ITCamp 2011 - Alessandro Pilotti - Optimizing ASPNet and PHP apps on IIS 7.5
 

ITCamp 2011 - Alessandro Pilotti - Optimizing ASPNet and PHP apps on IIS 7.5

on

  • 1,438 views

 

Statistics

Views

Total Views
1,438
Views on SlideShare
1,438
Embed Views
0

Actions

Likes
0
Downloads
21
Comments
0

0 Embeds 0

No embeds

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    ITCamp 2011 - Alessandro Pilotti - Optimizing ASPNet and PHP apps on IIS 7.5 ITCamp 2011 - Alessandro Pilotti - Optimizing ASPNet and PHP apps on IIS 7.5 Presentation Transcript

    • Optimizing ASP.Net and PHPWeb Applications on IIS 7.5 Alessandro Pilotti info@cloudbasesolutions.com MVP / IIS MCSD (VS 6.0 & .Net), MCAD, MCSE, MCDBA, MCT, RHCE, SCJP2 Premium conference on Microsoft’s Dev and ITPro technologies @itcampro / #itcampro
    • IT Camp 2011• Thanks for coming!• ITCamp is made possible by our sponsors: Premium conference on Microsoft’s Dev and ITPro technologies @itcampro / #itcampro
    • Session agenda• IIS 7.5 Architecture• WebPI• FastCGI• Wincache Extensions for PHP• Output Caching• Application Request Routing• AppFabric Caching• Session management in PHP & SQL Server Premium conference on Microsoft’s Dev and ITPro technologies @itcampro / #itcampro
    • Architecture - IIS 6 Web Request • MonolithicAuthentication • Extension viaNTLM Basic Anon ISAPI ony… CGIDetermine StaticHandler File ASP.NET ISAPI… PHPSend ResponseLog Compress Premium conference on Microsoft’s Dev and ITPro technologies @itcampro / #itcampro
    • Architecture IIS 7.5 Web Request • Features separated in NTLM Basic modulesAuthentication Anon – More than 40Authorization… • Modules fit in aResolveCache CGI… common pipeline Static File • Modules employDetermine Handler ISAPI common API…UpdateCache • Managed or Compress unmanagedSend Response Log Premium conference on Microsoft’s Dev and ITPro technologies @itcampro / #itcampro
    • Anatomy of a Request in IIS 7.x • HTTP .sys receives the request • WAS • applicationHost .config • WWW service • HTTP .sys config • W3WP • WP execution • Response Premium conference on Microsoft’s Dev and ITPro technologies @itcampro / #itcampro
    • Request – W3WP detailsPremium conference on Microsoft’s Dev and ITPro technologies @itcampro / #itcampro
    • WAS and W3SVCPremium conference on Microsoft’s Dev and ITPro technologies @itcampro / #itcampro
    • versioning• IIS 5.0 – Windows 2000• IIS 5.1 – Windows XP• IIS 6.0 – Windows Server 2003• IIS 7.0 – Windows Vista / Server 2008• IIS 7.5 – Window 7 / Server 2008 R2 Premium conference on Microsoft’s Dev and ITPro technologies @itcampro / #itcampro
    • Web Platform Installer 3• Single tool to easily deploy: – Frameworks – Extensions – Tools – Applications • E.g.: DNN, Joomla, etc• Always updated Premium conference on Microsoft’s Dev and ITPro technologies @itcampro / #itcampro
    • WEB PI 3Premium conference on Microsoft’s Dev and ITPro technologies @itcampro / #itcampro
    • Web PI 3Premium conference on Microsoft’s Dev and ITPro technologies @itcampro / #itcampro
    • Web PI 3Premium conference on Microsoft’s Dev and ITPro technologies @itcampro / #itcampro
    • Web Platform InstallerDEMO Premium conference on Microsoft’s Dev and ITPro technologies @itcampro / #itcampro
    • FastCGI 1.5• Very popular in the Apache environment, for PHP Perl, , Ruby, etc• CGI is slow: every request generates a process instance!• FastCGI employs the same process for many requests• Supported on IIS 7.x and IIS 6.0 (the latter via fcgiext.dll ISAPI)• Written in collaboration with Zend (PHP) but is generic• In IIS 7.x: Enable CGI among the IIS role services• Note: Install Hotfix KB980363 on IIS 7.0 to get version 1.5! Premium conference on Microsoft’s Dev and ITPro technologies @itcampro / #itcampro
    • FastCGI SetupPremium conference on Microsoft’s Dev and ITPro technologies @itcampro / #itcampro
    • FastCGI – version differencesFeature 5.1/6.0 7.0 7.5Monitoring file changes Yes Yes YesReal-Time max Inst. tuning Yes Yes YesSTDERR support Yes Yes YesSIGTERM support Yes Yes YesEnv. variable _FCGI_X_PIPE_ Yes Yes YesProc. Pool per application Yes Yes YesUTF-8 variable encoding Yes Yes NoIIS CPU Limit support No Yes Yes Premium conference on Microsoft’s Dev and ITPro technologies @itcampro / #itcampro
    • FastCGI - PHP• Install PHP 5.2 or 5.3 – During setup choose FastCGI• As an alternative, deploy via WebPI• WP3P.exe – Loads iisfcgi.dll – Executes php-cgi.exe• Config: PHP.INI – E.g.: fastcgi.impersonate = 1 Premium conference on Microsoft’s Dev and ITPro technologies @itcampro / #itcampro
    • PHP on IIS – other options• ISAPI – Previous choice – Low reliability due to reentrance problems – DLL loaded at W3SVC instance level • Security issues!!• CGI (not FastCGI!) – Awful performance Premium conference on Microsoft’s Dev and ITPro technologies @itcampro / #itcampro
    • PHP on IIS - Performance• PHP gets compiled at runtime – Reads source file and generates bytecode – Process repeated at each request• Not a problem for small loads• Huge bottleneck otherwise – Various solutions available – Now (PHP 5.x) no one available natively Premium conference on Microsoft’s Dev and ITPro technologies @itcampro / #itcampro
    • PHP Accelerators• Tools whose purpose is to improve the PHP execution time• Most popular available: – APC (default on PHP 6.0) – eAccelerator – Zend Server – Windows Cache Extension for PHP Premium conference on Microsoft’s Dev and ITPro technologies @itcampro / #itcampro
    • WinCache for PHP• Open source project developed by Microsoft• IIS Specific• Requires PHP 5.2 or 5.3 x86 – Non thread safe version• Provides features not available in APC and other accelerators Premium conference on Microsoft’s Dev and ITPro technologies @itcampro / #itcampro
    • WinCache for PHP• Setup – Web Platform Installer – Direct download – Source code• PHP configuration .ini – extension = php_wincache.dll – Verify setup with phpinfo() – maxInstances = 0 for best performance! Premium conference on Microsoft’s Dev and ITPro technologies @itcampro / #itcampro
    • WinCache for PHP• PHP Bytecode Cache – Subsequest calls to a script employ precompiled and cached bytecode• PHP scripts loaded in memory – Reduced I/O, mainly for UNC Paths!• Cache handled via Shared Memory• Absolute path caching – Optimizes the time required to resolve relative paths• Cache based session handler – By default PHP uses a file system based solution Premium conference on Microsoft’s Dev and ITPro technologies @itcampro / #itcampro
    • WinCache for PHP• User cache – wincache_ucache_set(key, value) – wincache_ucache_get(key) – Etc• User Cache session handler – session.save_handler = wincache Premium conference on Microsoft’s Dev and ITPro technologies @itcampro / #itcampro
    • FastCGI / PHP / WinCacheDEMO Premium conference on Microsoft’s Dev and ITPro technologies @itcampro / #itcampro
    • IIS 7.x Output Caching• Very efficient way to optimize an application• There 2 type of contents – Static – Dynamic • Based on a degree of dynamism and determinism – Premium conference on Microsoft’s Dev and ITPro technologies @itcampro / #itcampro
    • IIS 7.x Output Caching• IIS provides two caching policies – User mode (IIS 7.x worker process) – Kernel mode • Cache in HTTP.sys memory • Faster!• Parameter based (header, QueryString)• Not to be confused with ASP.Net output caching! Premium conference on Microsoft’s Dev and ITPro technologies @itcampro / #itcampro
    • Kernel Caching - limits• No user mode modules or features – E.g. Authentication• varyByQueryString parameter not supported• Management: – netsh http show cache – Netsh http delete cache … Premium conference on Microsoft’s Dev and ITPro technologies @itcampro / #itcampro
    • IIS 7.x Output Caching• Caching can be enabled for static and “semi-dynamic” content• Caching enabled for each site – Via UI – Via Command Line (appcmd) Premium conference on Microsoft’s Dev and ITPro technologies @itcampro / #itcampro
    • Caching Rules• IIS decides if “it is worth” to cache some content• Parameters – frequentHitTimePeriod • Default 10s – frequentHitThreshold • Default 2• ServerRuntime in applicationHost.config Premium conference on Microsoft’s Dev and ITPro technologies @itcampro / #itcampro
    • ServiceRuntime sample<system.webServer> <serverRuntime enabled="true" frequentHitThreshold="5" frequentHitTimePeriod="00:00:20" /></system.webServer> Premium conference on Microsoft’s Dev and ITPro technologies @itcampro / #itcampro
    • Output CachingDEMO Premium conference on Microsoft’s Dev and ITPro technologies @itcampro / #itcampro
    • Application Request Routing (ARR) 2.5• Based on the URL Rewrite module• Enhances Availability and scalability• Load balancing• Health monitoring• Client Affinity• Works at level 5 ISO/OSI – Can work with a NLB (level 3) solution• ARR 2 introduces a caching option Premium conference on Microsoft’s Dev and ITPro technologies @itcampro / #itcampro
    • Load balancingPremium conference on Microsoft’s Dev and ITPro technologies @itcampro / #itcampro
    • Creating a Web FarmPremium conference on Microsoft’s Dev and ITPro technologies @itcampro / #itcampro
    • Server farm configPremium conference on Microsoft’s Dev and ITPro technologies @itcampro / #itcampro
    • Application Request RoutingDEMO Premium conference on Microsoft’s Dev and ITPro technologies @itcampro / #itcampro
    • AppFabric• Extension with two separated main areas – WCF and WF service housing MSDN video (in Italian  ) http://www.microsoft.com/italy/beit/Generic.aspx? video=1a5e02e4-c881-4ef9-ac86-61dd7a370f70 – Distributed Cache • Solution to increase scalability and performance Premium conference on Microsoft’s Dev and ITPro technologies @itcampro / #itcampro
    • AppFabric Cache - Scalability• The problem: – Increasing load, means distributing it on more hosts – ARR is not a data oriented tool – The cache works at a data level• Other advantages: – Works also as a session provider – It can be integrated in EF as a 2nd level cache Premium conference on Microsoft’s Dev and ITPro technologies @itcampro / #itcampro
    • AppFabric Cache Architecture Premium conference on Microsoft’s Dev and ITPro technologies @itcampro / #itcampro
    • AppFabric SetupPremium conference on Microsoft’s Dev and ITPro technologies @itcampro / #itcampro
    • AppFabric Cache Cluster• Fault tolerant solution• Every host keeps a replicated copy of the data• Doesn’t require Windows Clustering• Configuration based on the “leadHost” concept – Host delegated to “master” the cluster configuration Premium conference on Microsoft’s Dev and ITPro technologies @itcampro / #itcampro
    • AppFabric Cache Cluster• Configuration can be kept on: – SQL Server • LeadHost not required – Shared storage + XML file • LeadHost required – Custom provider• LeadHost can be redundant• Note: SQL / storage can become a single point of failure! (valutare cluster etc) Premium conference on Microsoft’s Dev and ITPro technologies @itcampro / #itcampro
    • AppFabric Cache TCP/IP• Replication: 22236• Arbitration: 22235• Cluster: 22234• Cache: 22233 Premium conference on Microsoft’s Dev and ITPro technologies @itcampro / #itcampro
    • AppFabric Cache Client• Any .Net 3.5 o 4.0• Install the “Cache Client” feature only• In Visual Studio, register: – Microsoft.ApplicationServer.Caching.Client – Microsoft.ApplicationServer.Caching.Core• Assembly available in – %systemroot%System32AppFabric • Sostituire con SysWOW64 se x86 su x64 Premium conference on Microsoft’s Dev and ITPro technologies @itcampro / #itcampro
    • AppFabric Cache client session• Enabling AppCache as a session provider in web.config <sessionState mode="Custom" customProvider="AppFabricCacheSessionStoreProvider”> <providers> <add name="AppFabricCacheSessionStoreProvider” type="Microsoft.ApplicationServer.Caching.DataCacheSessionStoreProvider, Microsoft.ApplicationServer.Caching.Client, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35” cacheName="TestWPC” sharedId="DemoApp1"/> </providers> </sessionState> Premium conference on Microsoft’s Dev and ITPro technologies @itcampro / #itcampro
    • PowerShell• Start-CacheCluster• New-Cache• Grant-CacheClientAllowedAccount• Get-Cache• Get-CacheStatistics Premium conference on Microsoft’s Dev and ITPro technologies @itcampro / #itcampro
    • Concurrency models• Optimistic – Versioning – Version number checked during a Put operation• Pessimistic – Lock – Watchout for performance issues… – Note: Put doesn’t check for locks! Premium conference on Microsoft’s Dev and ITPro technologies @itcampro / #itcampro
    • AppFabric CacheDEMO Premium conference on Microsoft’s Dev and ITPro technologies @itcampro / #itcampro
    • PHP + MSSQL Sessions• Scaling out an application on a web farm requires proper session management• Tipically offloaded to a database or a state server• ASP .Net offers ready made solutions• PHP can be extended implementing a small number of documented callbacks Premium conference on Microsoft’s Dev and ITPro technologies @itcampro / #itcampro
    • PHP + MSSQL Sessions• SQL Server Drivers for PHP 1.1 – Installable also via WebPI (recommended)• In PHP.ini – extension=php_pdo_sqlsrv.dll – session.save_handler = user• PHP handler to implement: – session_set_save_handler Premium conference on Microsoft’s Dev and ITPro technologies @itcampro / #itcampro
    • PHP + MS SQL Server Session handlingDEMO Premium conference on Microsoft’s Dev and ITPro technologies @itcampro / #itcampro
    • Q&A Premium conference on Microsoft’s Dev and ITPro technologies @itcampro / #itcampro
    • Don’t forget!Get your free Azure pass! We want your feedback!• 30+15 days, no CC req’d • Win a WP7 smartphone – http://bit.ly/ITCAMP11 – Fill in your feedback forms – Promo code: ITCAMP11 – Raffle: end of the day Premium conference on Microsoft’s Dev and ITPro technologies @itcampro / #itcampro