server-side web trackbrought to you by
Getting out of Sync with IISand Riding a COMET Richard Banks		richard-banks.org  @rbanks54TalkingShopDownUnder.com
Goal: Improve your Server Side Performance
WebForms,MVC &Comet
Client side Things we already know(hopefully!)
Fewer requests == more performance!
View State Is EVIL!!! 
CDN’s, css sprites, minification, YSLOW, etc, etc
Server side?
Minimal DB calls,Cache usage, AJAX, and so forth
But what if you’ve done all that already?!
What if you have “Hanging” Requests?
Poor performance with very little load?
Probably BLOCKingREQUEST THREADS
Some IIS Internals
IIS 6.0: 12request threads per CPUAlso IIS 7.0 in Classic pipeline mode
20worker & 20 IO threads per CPU
No free threads?The request gets queuedPerfMon Counter:ASP.NET\Requests in Application Queue
Limit is 5000 requests. Over that? 503 errorsPerfMon Counter:ASP.NET\Requests Current
IIS 7.0 (Intg): 12 concurrent requests per CPUApplies to .NET 2.0
In .NET 4.0: 5000 per CPU!
MS says do same in ASP.NET 2.0. Add registry key or edit aspnet.configMaxConcurrentRequestsPerCPUHKLM\SOFTWARE\Microsoft\ASP.NET\2.0.50727
Note: App Pool Queue Length is 1000
Before messing with configs… Get Async!
Time For some Demofun!
ASP.NET Web Forms
Async=“true”in page directive.
REGISTERASYNCTASK and PageASYNCTASKhttp://msdn.microsoft.com/en-us/library/system.web.ui.pageasynctask.aspx
ASP.NET MVCAsyncControlers
Howz about USING that new ASYNC Keyword?!
Now for the new Hawtness!
COMET!Aka “Reverse AJAX”
Practical uses:Stock tickerSports scoresAuction biddingBus Service GPS updatesWarehouse movements & logisticsGoogle+Anything broadcasting events/msgs
Canonical Demo:Web Chat
Implement Via UpdatePanel?Ajax Request on Enter:No live update
Need to send full chat history each time
Uses Update Panel!AJAX && JSON(aka wOOtage!)Use a jssetTimeout() callOnly ask for messages after msgIdRegular polling to get messages
Long Polling or StREAMING(no, not web sockets)
Bayeux Protocolhttp://cometd.org/Dojo & Jquery Bindings
Lots of other Comet servers. I want TO USE IISIIS threading means no streaming support, only long polling.
CHAT Demo: AspComet(on Appharbor)http://chat.richard-banks.org
For better Comet go Threadless: Manos de Mono or Node.jsJust Remember Mordac will likely need bribing to deploy it
Faye is a Bayeaux server for Node.JShttp://faye.jcoglan.com/
ResourcesContention, poor performance, and deadlocks:  http://support.microsoft.com/kb/821268ASP.NET Thread Usage on IIS 6.0 and IIS 7.0: http://blogs.msdn.com/b/tmarq/archive/2007/07/21/asp-net-thread-usage-on-iis-7-0-and-6-0.aspxImproving ASP.NET Performance: http://msdn.microsoft.com/en-us/library/ff647787.aspxPageAsyncTask: http://msdn.microsoft.com/en-us/library/system.web.ui.pageasynctask.aspxMVC Async Controllers: http://msdn.microsoft.com/en-us/library/ee728598.aspxShould DB Calls be Async? http://blogs.msdn.com/b/rickandy/archive/2009/11/14/should-my-database-calls-be-asynchronous.aspxAspComet: http://github.com/nmosafi/aspcometBayeux and Cometd: http://svn.cometd.com/trunk/bayeux/bayeux.htmlManos De Mono: http://github.com/jacksonh/manosNode.JS: http://nodejs.org/FAYE: http://faye.jcoglan.com/
We would like to thank our sponsors and supporters for helping us bring you this event

DDD Sydney 2011 - Getting out of Sync with IIS and Riding a Comet

Editor's Notes

  • #19 We want the perf counter to be zero.
  • #27 Demo:Copy deployment to \\\\webserver\\DeploymentsSwitch to server and run the deployment – use the batch command with /Y optionRun TailspinSpyworks (port 8080!) – use VS web load testShow perf counters:ASP.NET\\Requests in Application QueueASP.NET\\Requests CurrentShow IIS session diagnostics (via IIS mgr) and request queue states
  • #28 Means page executes asynchronouslyCan run async tasks, but only until pre-render completesWithout Async=True errors get thrownDemo:Async pagesRun load test againNOTE – no real difference. If anything a little worse.Only apply where multiple activities being performed, and where activity is not CPU boundEach async == extra threadDon’t manually create threads!Web service calls use CLR threads as does QueueUserWorkItem – tune thread pool
  • #30 Show glimpse in action: http://getglimpse.com/
  • #31 Demo:RSS AggregatorSynchronous fetching == slow Async = better, but async on main threadParallels = best – spawns multiple threads, but leads to thread starvation in a web farmTurn offAsync in page directive and check the error
  • #40 IIS is still threaded so the issues from earlier still applyLong polling reduces the issue somewhat
  • #41 Show web chat workingShow long polling in chromedev toolshttp://webserver:8082/jquery.aspxStep through some of the server side code (from the processrequest method onwards) Show JSON content of messageWalkthrough of some of the codeCometHttpHandler. IHttpAsyncHandlerMessage comes in, converted from JSONPushed onto message busDone!Your code?Clients subscribeBack end pushes onto message busASPComet also supports callback messages, not just long polling