Building Scalable .NET Web Applications

  • Published on
    18-Oct-2014

  • View
    13.397

  • Download
    1

Embed Size (px)

DESCRIPTION

 

Transcript

<p>Application Lifecycle Management with Visual Studio 2010</p> <p>Building Scalable .NET Web ApplicationsBuu Nguyen, MVP (ASP.NET)www.buunguyen.net/blogbuunguyen@kms-technology.comMicrosoft Confidential1AgendaScalabilityScaling Web Client TierScaling Web &amp; Application Server TiersScaling Database TierScalabilityScalabilityA system is scalable when it can accommodate more loads and larger data set by increasing hardware power</p> <p>Scalability implies performance but not the other way around</p> <p>Vertical Scaling vs. Horizontal Scaling</p> <p>http://www.gigaspaces.com/files/pics/online_gaming_scalability_diagram_website.jpg</p> <p>http://www.ourofficebox.co.uk/Images/scalability2%20750.png5Don't Underestimate Vertical ScalingStackOverflow.com1M page views per day500K questions and millions of posts817th largest siteHardware2 web servers (1 Xeon 4-core processor, 8GB RAM)1 database server (2 Xeon 4-core processors, 48GB RAM)SoftwareIIS 7.5 on Windows Server 2008 R2HAProxy (inside Linux VM)SQL Server 2008 EnterpriseASP.NET MVC and .NET 3.5</p> <p>Source: http://www.microsoft.com/casestudies/Case_Study_Detail.aspx?casestudyid=4000006676Microsoft Confidential6</p> <p>Scaling Web Client TierClient Resource ManagementMinify and Gzip JavaScript, CSSMS Ajax Minifier, YUI Compressor, Google Closure CompilerCombine JavaScript and CSSMS Script LoaderCSS on topJavaScript at bottom Add Expires headers for all resources</p> <p>8CombresCurrently 2.0, Apache licensehttp://combres.codeplex.com/Key FeaturesCombine, compress, minify, cache (server &amp; client) JavaScript and CSS resourcesAutomatic change detectionExtensible architectureUser Guidehttp://www.codeproject.com/KB/aspnet/combres2.aspx</p> <p>Microsoft Confidential9JavaScript &amp; Ajax OptimizationReverse-Ajax (Comet) instead of pollingUse dedicated Comet serverExamples: StreamHub, Meteorhttp://cometdaily.com/maturity.htmlYield to timer by chunking processingAvoid outer-scope lookupSplit initial payload (i.e. before onload)Employ non-blocking JS loading techniquesMS Ajax Library Script Loader, YUI Script Loader</p> <p>10Scaling Web and Application Server TiersLoad BalancingThe act of properly distribute workload across machines/resources in a clusterApproachesDNS A recordsPoor mans hand-coded redirectionSoftware, e.g. HAProxy, NLB, LVSHardware, e.g. F5ConsiderationsSession stateView state</p> <p>12Domain ShardingPartition resources across different hostsBy type, e.g. static/dynamic, JS/CSS etc.By functionality, e.g. forum moduleBenefitsBalance loadsParallel downloadsAvoid redundant cookiesIsolated optimization</p> <p>13Content Delivery Network (CDN)ServicesMicrosoft, Google, Akamai etc.Static resources onlyBenefitsAs domain shardingRedundancy and availabilitySmart DNS routingHigh chance of browser cache hit</p> <p>14Distributed CacheEnable persistent cache for a server clusterFast (in-memory) Distributed ignorant by clientsSolutionsAppFabric Cache (Velocity)Support POCO, XML, binaryASP.NET integrationExtensible cache providerOthers: memcached</p> <p>15ConcurrencyIts a waste of cores if you dont have enough threadsSolutionsParallel Task Library (PTL)PLINQF#</p> <p>16OthersCompensation over distributed transactionsAsynchronous over synchronous servicesRelated: asynchronous controller in MVC 2.017Side Notes on Entity FrameworkSingleton ObjectContext doesnt fit web appsNot thread-safeConsume RAMMight fit rich clientOne OC per request is the common strategy for web appsUse compiled query to reuse generated EF command tree</p> <p>18Scaling Database TierIndexesClustered vs. non-clustered indexesGuidelinesIndexing columns in WHERE and SELECTIndexing columns with highly unique valuesCluster-indexing primary keysAvoid over-indexing </p> <p>20ReplicationPublisher-subscribers configurationi.e. master-slave in MySQLWrite to subscribers wont propagate backCommon optionsTransactional (near real-time)Snapshot (time interval)Suitable for read-intensive applications</p> <p>21ReplicationPeer-2-peer configurationi.e. master-master in MySQLIssuesIdentity conflictsNo true copy at any point of timeHigh network latency</p> <p>22PartitioningVertical Partitioning (Clustering)</p> <p>Distribute tables into multiple DBs, each representing a cluster of related tables, e.g.Customer DB, product DB, forum DB etc.Application layer aggregates data</p> <p>Horizontal Partitioning (Sharding)</p> <p>Distribute table rows into logical groups, e.g. US customers, European customersApplication layer picks shards &amp; aggregates data</p> <p>23NoSQLPartitioning makes relational databases not so relational any moreComplexity in DB design &amp; application layerNoSQL, not-only-relational, is about DBs built with scalability in mind Sacrifice integrity &amp; ACID to a certain extentApache CassandraAuto load balancingIdentical nodesElastic capacityFlexible schemaOthers: MongoDB, Voldermort, Tokyo Cabinet24</p>